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: 6 additions & 1 deletion tslang/lib/TypeScript/MLIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,8 +1086,13 @@ namespace mlirgen
filesInProgress.insert(canonicalPath);
auto inProgress = llvm::make_scope_exit([&]() { filesInProgress.erase(canonicalPath); });

// An import that points to a .ts file: compiled, it is a declaration - the module is
// compiled into an object of its own, and the objects are linked into one program. Under
// the JIT there is no other object, so it is included with its bodies, as a referenced
// file is. (An import that points to a library is mlirGenImportSharedLib.) A .d.ts is
// read as declarations either way.
MLIRValueGuard<bool> vg(declarationMode);
declarationMode = true;
declarationMode = !compileOptions.isJit;

// What the imported module exports is its own to export: it is compiled separately, with
// its declarations in its own __decls. Added to this module's too, a library holding both
Expand Down
7 changes: 7 additions & 0 deletions tslang/test/tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2598,6 +2598,13 @@ add_test(NAME test-compile-reference-path-import-cycle-quiet
"${reference_path_dir}/cycle_class_node.ts" -o "${CMAKE_CURRENT_BINARY_DIR}/cycle_class_node.obj")
set_tests_properties(test-compile-reference-path-import-cycle-quiet PROPERTIES FAIL_REGULAR_EXPRESSION "error:")

# Under the JIT an import pointing to a .ts file includes it with its bodies: a program run on its
# own found no `S..new` for the imported class, which was only declared. Compiled, the import is a
# declaration and the module's own object is linked beside it.
set(import_source_dir "${PROJECT_SOURCE_DIR}/test/tester/import-source")
tslang_add_test(NAME test-jit-import-source-new-imported-class COMMAND test-runner -jit "${import_source_dir}/new_imported_class.ts")
tslang_add_import_tests(import-source-new-imported-class "${import_source_dir}" new_imported_class imported_class_module)

# `import { a as b }` and `import * as M` - each used to be "can't resolve name".
set(import_bindings_dir "${PROJECT_SOURCE_DIR}/test/tester/import-bindings")
tslang_add_import_tests(import-bindings-renamed "${import_bindings_dir}" import_renamed names_module)
Expand Down
6 changes: 6 additions & 0 deletions tslang/test/tester/import-source/imported_class_module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class S
{
toString() {
return "Hi";
}
}
9 changes: 9 additions & 0 deletions tslang/test/tester/import-source/new_imported_class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Under the JIT an import pointing to a .ts file includes it with its bodies: run on its own, the
// program used to fail with "Symbols not found: [ S..new ]" - the imported class was only declared.
import './imported_class_module'

const s = new S();
assert(s.toString() == "Hi");
print("Hello World", s);

print("done.");
3 changes: 2 additions & 1 deletion tslang/test/tester/test-runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,8 @@ void createSharedMultiBatchFile(std::string tempOutputFileNameNoExt, std::vector
if (jitRun)
{
// one extra "../" because we run from the per-test working directory
batFile << "$TSLANGEXEPATH/tslang --emit=jit " << tslang_opt << " --shared-libs=../../../lib/libTypeScriptRuntime.so --shared-libs=./lib" << shared_filenameNoExt << ".so " << *files.begin() << " 1> ../$FILENAME.txt 2> ../$FILENAME.err"
// the library is not passed with --shared-libs: `import './<stem>'` loads it at run time
batFile << "$TSLANGEXEPATH/tslang --emit=jit " << tslang_opt << " --shared-libs=../../../lib/libTypeScriptRuntime.so " << *files.begin() << " 1> ../$FILENAME.txt 2> ../$FILENAME.err"
<< std::endl;
}
else
Expand Down
Loading