Skip to content

--export=all exports the module's variables, not a function's locals - #394

Merged
ASDAlexander77 merged 1 commit into
mainfrom
export-all-accessor-locals
Sep 28, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
export-all-accessor-locals

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

With --export=all (or any --export filter matching a local's name), a library's __decls declared every local variable of every function, method and accessor as a @dllimport global, in a .f_<function> namespace:

namespace .f_Node.get_total {
@dllimport
let t : s32;
}
namespace .f_f {
@dllimport
let w : s32;
}

No library defines those symbols. I found this in #391's investigation.

Cause: in mlirGen(VariableDeclarationList), the filters (getExportModifier) were applied to every variable statement, function bodies included. export can't be written inside a function, so only a filter could mark a local, and it did.

Fix: the filters apply only where there's no function (!genContext.funcOp), which means the module and its namespaces. Line 965 of the same function already uses that test to mean "module level". A module-level variable is still exported under --export=all, and a namespace's export const still is.

Test: test-compile-export-all-no-locals compiles export-all/locals.ts (a getter, a method and a function with locals, plus a module-level let) with --export=all --emit=mlir. It must show let moduleLevel and no namespace .f_. It fails without the fix.

Results: the suite passes locally, 3012/3012. DefaultLib builds with --export=none, so it's unaffected.

🤖 Generated with Claude Code

@ASDAlexander77
ASDAlexander77 force-pushed the export-all-accessor-locals branch from 667a445 to 3339035 Compare September 28, 2026 15:06
An --export filter such as `all` matched every variable statement,
function bodies included, so a library's __decls declared each local of
each function, method and accessor as a `@dllimport` global in a
`.f_<function>` namespace - symbols no library defines. `export` cannot
be written inside a function; the filters now apply only where there is
no function (the module and its namespaces).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 force-pushed the export-all-accessor-locals branch from 3339035 to 853784a Compare September 28, 2026 16:37
@ASDAlexander77
ASDAlexander77 merged commit 64f246f into main Sep 28, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the export-all-accessor-locals branch September 28, 2026 16:57
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