From 7d077d30f0ec48603b77183be1d0e367478bf7fb Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Sun, 15 Nov 2026 19:29:15 +0000 Subject: [PATCH] -mm=own: the inference pass no longer walks other functions' bodies (compiler crashed about once in 500 runs) OwnershipInferencePass runs on the functions of a module at once, on several threads. For a field read through an interface whose value leaves its function (`function dirOf(r: R) { return r.dir; }`) releaseCellReads asks accessorFiller whether a class fills the field with a getter, and accessorFiller looked for the accessor cell's global with module.walk - which goes into the body of every function of the module, among them the ones the other threads were putting releases in and erasing reads from at that moment. It read an operation list as it was relinked, and the compiler ended with an access violation: about once in 300 to 700 compiles of test/tester/own/own_field_chain_let.ts, and once in a run of the suite. It now looks at the module's own operations only: that is where globals are, and no function's pass changes that list. Found from a crash dump: two worker threads in releaseCellReads, both in the module walk. The compiler from before the fix failed 2 of 1,000 and 1 of 725 compiles of that test; with the fix, 0 of 4,000. Release suite on Windows x64; LLVM IR of the 190 tests of test/tester/own that compile without the default library is unchanged. Co-Authored-By: Claude Fable 5.2 --- .../lib/TypeScript/OwnershipInferencePass.cpp | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tslang/lib/TypeScript/OwnershipInferencePass.cpp b/tslang/lib/TypeScript/OwnershipInferencePass.cpp index a3edc5be9..c5ff09db6 100644 --- a/tslang/lib/TypeScript/OwnershipInferencePass.cpp +++ b/tslang/lib/TypeScript/OwnershipInferencePass.cpp @@ -230,7 +230,19 @@ namespace own_inference auto suffix = (llvm::Twine(".") + field + ".accessor").str(); auto module = getFunction()->getParentOfType(); llvm::StringRef found; - module.walk([&](mlir_ts::GlobalOp globalOp) { + // Only the module's own operations, which no function's pass changes: this pass runs on the + // module's functions at once, on several threads, and module.walk went into the bodies of + // the functions the other threads were putting releases in and erasing reads from. It read a + // list as it was relinked, and the compiler ended with an access violation about once in + // 500 runs (test/tester/own/own_field_chain_let.ts). + for (auto &moduleOp : *module.getBody()) + { + auto globalOp = mlir::dyn_cast(&moduleOp); + if (!globalOp) + { + continue; + } + auto name = globalOp.getSymName(); auto vtbl = name.find("..vtbl."); if (vtbl != llvm::StringRef::npos && name.ends_with(suffix) && vtbl + 6 + suffix.size() == name.size()) @@ -238,11 +250,9 @@ namespace own_inference // the class: up to the interface's name auto head = name.take_front(vtbl); found = head.take_front(head.rfind('.') == llvm::StringRef::npos ? head.size() : head.rfind('.')); - return mlir::WalkResult::interrupt(); + break; } - - return mlir::WalkResult::advance(); - }); + } return found; }