Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions tslang/lib/TypeScript/MLIRGenVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,11 +954,14 @@ namespace mlirgen
// we need it for support "undefined type" in 'let' without initialization
item->parent = variableDeclarationListAST;

// --export filters by name, and one statement can declare several names
// --export filters by name, and one statement can declare several names. Only a
// variable of the module or a namespace can be exported: a filter such as `all` matched
// every function's locals too, and declared them to importers as `@dllimport` globals
// in a `.f_<function>` namespace, which no library defines.
auto itemVarClass = varClass;
if (variableDeclarationListAST->parent && !exportByDecorator)
{
itemVarClass.isExport = getExportModifier(
itemVarClass.isExport = !genContext.funcOp && getExportModifier(
variableDeclarationListAST->parent, MLIRHelper::getName(item->name, stringAllocator));
}

Expand Down
8 changes: 8 additions & 0 deletions tslang/test/tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2555,6 +2555,14 @@ if (WIN32)
FAIL_REGULAR_EXPRESSION "Stack dump|unlinked")
endif()

# --export=all exports the module's variables, not the locals of its functions.
add_test(NAME test-compile-export-all-no-locals
COMMAND $<TARGET_FILE:tslang> --emit=mlir --no-default-lib --export=all
"${PROJECT_SOURCE_DIR}/test/tester/export-all/locals.ts")
set_tests_properties(test-compile-export-all-no-locals
PROPERTIES PASS_REGULAR_EXPRESSION "let moduleLevel"
FAIL_REGULAR_EXPRESSION "namespace [.]f_|Stack dump|error:")

# The shared-component tier under the other two models. A shared library records the model
# it was built under, so both halves of a pair are built with the same flag - which is what
# these run. The file pairs are the default model's, verbatim.
Expand Down
27 changes: 27 additions & 0 deletions tslang/test/tester/export-all/locals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// --export=all exports the module's variables, not a function's: those were declared to
// importers as `@dllimport` globals in a `.f_<function>` namespace, which no library defines.
export class Node {
items: number[] = [];

get total(): number {
let t = 0;
for (const c of this.items) {
t += c;
}

return t;
}

sum(): number {
let u = 0;
for (let i = 0; i < this.items.length; i++) u += this.items[i];
return u;
}
}

export function f() {
let w = 1;
return w;
}

let moduleLevel = 5;
Loading