Repository navigation
-mm=own: fix a data race in the inference pass (compiler crashed about once in 500 runs) - #867
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
-mm=ownthe compiler ended with an access violation about once in 300 to 700 compiles oftest/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
OwnershipInferencePassruns 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; }),releaseCellReadsasksaccessorFillerwhether a class fills the field with a getter.accessorFillerlooked for the accessor cell's global withmodule.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
accessorFillerlooks 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.walkis 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.test-borrow-facts-*, which fail on my machine only (the build cache'sCMAKE_ARnames an MSVC toolset that is no longer installed).test/tester/ownthat compile with--no-default-lib -mm=own: unchanged.Not covered
mainplus the change. The change is one function, which Compile time: interfaces and one very large function (2,000 interfaces: 7.3 s -> 5.0 s; 16,000 ifs: 21.7 s -> 11.2 s) #866 does not touch.docs/compile-time-work.mdin Compile time: interfaces and one very large function (2,000 interfaces: 7.3 s -> 5.0 s; 16,000 ifs: 21.7 s -> 11.2 s) #866 lists this crash as open.🤖 Generated with Claude Code