Clear lowering-pass side tables between functions (intermittent 00try_finally_return failure) - #317
Merged
Merged
Conversation
…e in lowering passes
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.
Problem
00try_finally_return.tsfailed now and then on Windows CI, only in AOT compile variants, and passed on re-run (first attempts of the #310 and #312 runs):It never failed locally.
Cause
The affine lowering keeps side tables in
TSContextthat decide where ops branch:unwind,cleanup,jumps,parentTryOp,landingBlockOf,leavesCatch,catchOpData. They are keyed byOperation*and holdBlock*values. They were never cleared, andTSContextis a member of the pass object, which lowers every function on its thread in turn.Once
func1is lowered its ops are freed, but its entries stay. An op created while loweringfunc2can reuse the address of one of those ops and inherit its entry, so it branches into one offunc1's blocks, which is the verifier error above.Reproduced single-threaded (
--mlir-disable-threading) with the old behaviour: compiling all 509 test files produced exactly one stale lookup, on two different builds, always the same site:That
ts.Returnis the oneTryOpLoweringcreates at the end offunc2's return-pathfinallycopy (hence thetry's location). It inherited thecleanupentry offunc1'sreturn, which pointed atfunc1'sfinallycopy.Why only CI: MLIR gives each worker thread its own pass clone. On a 16-thread machine the functions of a small file rarely share a clone; CI runners have few cores. Even single-threaded the hit depends on heap layout: the same binary hit on 2 of 100 compiles of this file.
Fix
TSContexttable is now anOpSideTable<V>.TSContext::beginRun()clears all of them, and the three affine lowering passes call it before building their patterns, i.e. once per function (or once per module).lookup/containsthat still finds an entry from an earlier run prints the table, op and location and stops withreport_fatal_error, in every build: in release this used to be a silent miscompile at best.lookup/containsinstead ofoperator[], which inserted an empty entry on every read. Writes still use[].TSLANG_REPORT_STALE_LOWERING_CONTEXTprints how many entries each run drops from the one before.Tests
00try_finally_returnno longer failing on CI.🤖 Generated with Claude Code