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: 7 additions & 0 deletions tslang/lib/TypeScript/MLIRGenImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16814,6 +16814,13 @@ class MLIRGenImpl
// imports a) stops instead of recursing until the stack overflows.
llvm::StringSet<> filesInProgress;

// Source imports whose own discovery pass has run once (mlirGenInclude). Their declarations
// are in the maps from then on, so an import generated into another module - each discovery
// module, then theModule - is generated without discovering it again. Discovered again each
// time, an import nested d deep was generated 2^d times: a chain of eight imports took 10 GB.
// Survives discovery, as filesInProgress does.
llvm::StringSet<> discoveredImports;

// The default library's files - lib.d.ts and every file it references - by file key. Its
// ambient data is defined in its DLL when the program links that (see
// isImportedFromSharedDefaultLib).
Expand Down
6 changes: 5 additions & 1 deletion tslang/lib/TypeScript/MLIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,10 @@ namespace mlirgen
MLIRValueGuard<mlir::SmallVector<std::unique_ptr<mlir::Diagnostic>> *> diagnosticsGuard(importDiagnostics);
importDiagnostics = &diagnostics;

generated = mlir::succeeded(mlirDiscoverAllDependencies(importSource, importIncludeFiles)) &&
// discovered once already (generated into an earlier module): its declarations are
// known, and discovering it again would generate every import inside it twice more
generated = (discoveredImports.contains(canonicalPath) ||
mlir::succeeded(mlirDiscoverAllDependencies(importSource, importIncludeFiles))) &&
mlir::succeeded(mlirCodeGenModule(importSource, importIncludeFiles, false, false));
}

Expand All @@ -1441,6 +1444,7 @@ namespace mlirgen
emittedFiles.insert(canonicalPath);
emittedFiles.insert(declSymbol);
emittedFiles.insert(genericDeclSymbol);
discoveredImports.insert(canonicalPath);

// the object the JIT has to load for it; after the ones it imports, which were
// generated inside it. A pass generated again (discovery, then the module) finds it
Expand Down
17 changes: 17 additions & 0 deletions tslang/test/tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5139,6 +5139,23 @@ endfunction()
set(reference_path_dir "${PROJECT_SOURCE_DIR}/test/tester/reference-path")
tslang_add_import_tests(reference-path-import-and-reference "${reference_path_dir}" import_and_reference module_left)
tslang_add_import_tests(reference-path-two-imports "${reference_path_dir}" two_imports module_left module_right)

# An import discovered again in every module it was generated into was generated 2^depth times:
# twenty imports deep took about 1000 s, so the TIMEOUT is what fails it if that comes back.
set(import_chain_modules "")
foreach(import_chain_index RANGE 1 20)
if (import_chain_index LESS 10)
set(import_chain_index "0${import_chain_index}")
endif()
list(APPEND import_chain_modules "${PROJECT_SOURCE_DIR}/test/tester/import-chain/chain_${import_chain_index}.ts")
endforeach()
# Not -shared: a module that imports another is declared twice in the one library, chain or not.
# The JIT compiles each import into its cache by itself.
tslang_add_test(NAME test-compile-import-chain-deep
COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/import-chain/deep_chain.ts" ${import_chain_modules})
tslang_add_test(NAME test-jit-import-chain-deep
COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/import-chain/deep_chain.ts")
set_tests_properties(test-compile-import-chain-deep test-jit-import-chain-deep PROPERTIES TIMEOUT 120)
tslang_add_import_tests(reference-path-import-diamond "${reference_path_dir}" import_diamond plain_module via_module)
tslang_add_import_tests(reference-path-import-cycle "${reference_path_dir}" import_cycle cycle_module_a cycle_module_b)
# Through a -shared library of these two modules the importer read Node twice ("redefinition of
Expand Down
3 changes: 3 additions & 0 deletions tslang/test/tester/import-chain/chain_01.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Link 1 of the chain deep_chain.ts imports; see there.

export function chain1() { return 1; }
4 changes: 4 additions & 0 deletions tslang/test/tester/import-chain/chain_02.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Link 2 of the chain deep_chain.ts imports; see there.
import './chain_01'

export function chain2() { return chain1() + 2; }
5 changes: 5 additions & 0 deletions tslang/test/tester/import-chain/chain_03.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Link 3 of the chain deep_chain.ts imports; see there.
import './chain_02'
import './chain_01'

export function chain3() { return chain2() + 3; }
5 changes: 5 additions & 0 deletions tslang/test/tester/import-chain/chain_04.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Link 4 of the chain deep_chain.ts imports; see there.
import './chain_03'
import './chain_01'

export function chain4() { return chain3() + 4; }
5 changes: 5 additions & 0 deletions tslang/test/tester/import-chain/chain_05.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Link 5 of the chain deep_chain.ts imports; see there.
import './chain_04'
import './chain_01'

export function chain5() { return chain4() + 5; }
5 changes: 5 additions & 0 deletions tslang/test/tester/import-chain/chain_06.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Link 6 of the chain deep_chain.ts imports; see there.
import './chain_05'
import './chain_01'

export function chain6() { return chain5() + 6; }
5 changes: 5 additions & 0 deletions tslang/test/tester/import-chain/chain_07.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Link 7 of the chain deep_chain.ts imports; see there.
import './chain_06'
import './chain_01'

export function chain7() { return chain6() + 7; }
5 changes: 5 additions & 0 deletions tslang/test/tester/import-chain/chain_08.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Link 8 of the chain deep_chain.ts imports; see there.
import './chain_07'
import './chain_01'

export function chain8() { return chain7() + 8; }
5 changes: 5 additions & 0 deletions tslang/test/tester/import-chain/chain_09.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Link 9 of the chain deep_chain.ts imports; see there.
import './chain_08'
import './chain_01'

export function chain9() { return chain8() + 9; }
5 changes: 5 additions & 0 deletions tslang/test/tester/import-chain/chain_10.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Link 10 of the chain deep_chain.ts imports; see there.
import './chain_09'
import './chain_01'

export function chain10() { return chain9() + 10; }
5 changes: 5 additions & 0 deletions tslang/test/tester/import-chain/chain_11.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Link 11 of the chain deep_chain.ts imports; see there.
import './chain_10'
import './chain_01'

export function chain11() { return chain10() + 11; }
5 changes: 5 additions & 0 deletions tslang/test/tester/import-chain/chain_12.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Link 12 of the chain deep_chain.ts imports; see there.
import './chain_11'
import './chain_01'

export function chain12() { return chain11() + 12; }
5 changes: 5 additions & 0 deletions tslang/test/tester/import-chain/chain_13.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Link 13 of the chain deep_chain.ts imports; see there.
import './chain_12'
import './chain_01'

export function chain13() { return chain12() + 13; }
5 changes: 5 additions & 0 deletions tslang/test/tester/import-chain/chain_14.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Link 14 of the chain deep_chain.ts imports; see there.
import './chain_13'
import './chain_01'

export function chain14() { return chain13() + 14; }
5 changes: 5 additions & 0 deletions tslang/test/tester/import-chain/chain_15.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Link 15 of the chain deep_chain.ts imports; see there.
import './chain_14'
import './chain_01'

export function chain15() { return chain14() + 15; }
5 changes: 5 additions & 0 deletions tslang/test/tester/import-chain/chain_16.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Link 16 of the chain deep_chain.ts imports; see there.
import './chain_15'
import './chain_01'

export function chain16() { return chain15() + 16; }
5 changes: 5 additions & 0 deletions tslang/test/tester/import-chain/chain_17.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Link 17 of the chain deep_chain.ts imports; see there.
import './chain_16'
import './chain_01'

export function chain17() { return chain16() + 17; }
5 changes: 5 additions & 0 deletions tslang/test/tester/import-chain/chain_18.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Link 18 of the chain deep_chain.ts imports; see there.
import './chain_17'
import './chain_01'

export function chain18() { return chain17() + 18; }
5 changes: 5 additions & 0 deletions tslang/test/tester/import-chain/chain_19.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Link 19 of the chain deep_chain.ts imports; see there.
import './chain_18'
import './chain_01'

export function chain19() { return chain18() + 19; }
5 changes: 5 additions & 0 deletions tslang/test/tester/import-chain/chain_20.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Link 20 of the chain deep_chain.ts imports; see there.
import './chain_19'
import './chain_01'

export function chain20() { return chain19() + 20; }
8 changes: 8 additions & 0 deletions tslang/test/tester/import-chain/deep_chain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// A chain of 20 imports, each module importing the one below it and chain_01 as well. Each
// import was discovered again in every module it was generated into, so a module nested d
// deep was generated 2^d times: this one took minutes and gigabytes, and the TIMEOUT fails it.
import './chain_20'

assert(chain20() == 210);

print("done.");
Loading