Skip to content

compiler: account for nested imports in the importer's export offset - #487

Merged
jow- merged 1 commit into
masterfrom
fix/nested-import-export-offset
Oct 11, 2026
Merged

jow- merged 1 commit into
masterfrom
fix/nested-import-export-offset

Conversation

@jow-

@jow- jow- commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

compiler: account for nested imports in the importer's export offset

When a module is linked in at compile time, the importing source's export
offset was advanced by the linked module's own export count only. Modules
that the linked module itself imported also allocate slots in the shared
export table before the importer's own exports, but were not counted.

For the root of a runtime import() this yielded a too small offset once
the import graph was more than one level deep, so uc_require_imports()
paired exported names with the values of unrelated, nested modules (e.g. an
exported function resolving to a function of a transitively imported
module).

Advance the importer's offset by the number of export slots actually
allocated while compiling the import, which covers the linked module and
all modules it pulled in transitively.

Add a regression test with a three level import chain.

Signed-off-by: Jo-Philipp Wich jo@mein.io

When a module is linked in at compile time, the importing source's export
offset was advanced by the linked module's own export count only. Modules
that the linked module itself imported also allocate slots in the shared
export table before the importer's own exports, but were not counted.

For the root of a runtime `import()` this yielded a too small offset once
the import graph was more than one level deep, so `uc_require_imports()`
paired exported names with the values of unrelated, nested modules (e.g. an
exported function resolving to a function of a transitively imported
module).

Advance the importer's offset by the number of export slots actually
allocated while compiling the import, which covers the linked module and
all modules it pulled in transitively.

Add a regression test with a three level import chain.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
@jow-
jow- merged commit 2b32f92 into master Oct 11, 2026
3 checks passed
@jow-
jow- deleted the fix/nested-import-export-offset branch October 11, 2026 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant