Repository navigation
An exported variable beside top-level code is exported (#448) - #501
Merged
Merged
Conversation
With -shared, the importer of `export const k = 5;` from a module that
also had a top-level statement could not resolve k ("can't resolve
name: k"), under every memory model. A root with top-level code
generates its own variable statements in its entry function
(generateGlobalEntryCode), where they stay module globals, but the
export check took any enclosing function to mean a local
(`isExport = !genContext.funcOp && ...`): k was never added to the
library's __decls, which then had none.
The context generateGlobalEntryCode gives the root's statements now
carries the entry function (rootStatementsFuncOp), and a variable
declared directly in it is at module level for the export check. A
function nested in them has a funcOp of its own, so --export=all still
leaves function locals alone.
The importer also warned "'let' does not have initializer" at the
import, with or without top-level code: the library declares k as
`@dllimport let k : s32;`, defined in the library. A declaration with
@dllimport no longer gets the warning, as a `declare` one does not.
import-source/import_export_const.ts and export_const_module.ts:
compiled, -shared (which failed), JIT with -shared, JIT; the -shared
runs fail on the warning as well.
Closes #448
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
-shared, the importer ofexport const k = 5;from a module that also had a top-level statement couldn't resolvek("can't resolve name: k"), under every memory model.A root with top-level code generates its own variable statements inside its entry function (
generateGlobalEntryCode), where they stay module globals. But the export check treated any enclosing function as making a variable local (isExport = !genContext.funcOp && ...). Soknever reached the library's__decls, and the library ended up with no__declsat all.The context
generateGlobalEntryCodegives the root's statements now records the entry function (rootStatementsFuncOp). A variable declared directly in that function counts as module level for the export check. A function nested inside those statements has afuncOpof its own, so--export=allstill leaves function locals alone.The importer also warned
'let' does not have initializerat the import, with or without top-level code. The library declareskto its importers as@dllimport let k : s32;, and the variable is defined in the library. A declaration with@dllimportno longer gets the warning, just as adeclaredeclaration doesn't.New tests
import-source/import_export_const.ts+export_const_module.tsrun compiled,-shared(the failing case onmain), JIT with-shared, and JIT. Both-sharedruns also fail if the warning appears.tests.ps1 -Model, release + debug, compile + JITweakref_basicskipped (gc only); all "All tests passed"Closes #448
🤖 Generated with Claude Code