Skip to content

-mm=own: fix a data race in the inference pass (compiler crashed about once in 500 runs) - #867

Merged
ASDAlexander77 merged 1 commit into
mainfrom
fix-own-inference-module-walk-race
Nov 15, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
fix-own-inference-module-walk-race

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

With -mm=own 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 (test-own-no-counting-own_field_chain_let). The compiler from before #862 does the same, so it is not from the compile-time work; it was found while testing #866.

Cause

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. 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.

A crash dump showed two worker threads in releaseCellReads, both in that walk.

Fix

accessorFiller looks at the module's own operations only. Globals are there, and no function's pass changes that list.

The other passes that run per function were checked for the same pattern: every other module.walk is in a module pass.

Testing

  • tslang --emit=llvm --no-default-lib -mm=own tslang/test/tester/own/own_field_chain_let.ts, repeated: before the fix 2 of 1,000, 1 of 725 and 1 of 300 runs failed; with it, 0 of 4,000.
  • Release suite on Windows x64: 7,445 tests, 5 failures, all test-borrow-facts-*, which fail on my machine only (the build cache's CMAKE_AR names an MSVC toolset that is no longer installed).
  • LLVM IR of the 190 tests of test/tester/own that compile with --no-default-lib -mm=own: unchanged.

Not covered

🤖 Generated with Claude Code

…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 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit c124994 into main Nov 15, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the fix-own-inference-module-walk-race branch November 15, 2026 20:02
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