Fix post-monomorphization error note race in the parallel frontend#157282
Open
xmakro wants to merge 3 commits into
Open
Fix post-monomorphization error note race in the parallel frontend#157282xmakro wants to merge 3 commits into
xmakro wants to merge 3 commits into
Conversation
`collect_items_rec` snapshots the error count before processing a mono item and compares it afterwards to decide whether to attach the "the above error was encountered while instantiating ..." note. The mono item graph is walked in parallel, so the global error count can be bumped by an error emitted while collecting a different item on another thread between the two reads, which makes an unrelated item (often lang_start) get blamed. Add `DiagCtxt::err_count_on_current_thread`, backed by a thread-local counter bumped next to the shared error count, and use it for the snapshot and comparison. It is not affected by errors emitted on other threads. In serial compilation it is equivalent to a delta of `err_count`.
These were marked ignore-parallel-frontend because the spurious instantiation note made their output nondeterministic under -Zthreads. With that fixed they pass reliably, so remove the directive and bless the line numbers that shift from removing it.
This comment has been minimized.
This comment has been minimized.
Collaborator
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @mejrs (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
Why was this reviewer chosen?The reviewer was selected based on:
|
a57bd28 to
67b98f4
Compare
Contributor
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.
Fixes #154260.
collect_items_recdecides whether to attach the note "the above error was encountered while instantiatingfn ..." by snapshotting the error count before processing a mono item and comparing it afterwards. The mono item graph is walked in parallel (thepar_for_each_inincollect_crate_mono_items), so the global error count can be bumped by an error emitted while collecting a different item on another thread between the two reads. That makes an unrelated item get blamed, which showed up as a spurious note such asappearing nondeterministically in test output under
--parallel-frontend-threads.This adds
DiagCtxt::err_count_on_current_thread, backed by a thread-local counter that is bumped next to the shared error count, and uses it for the before/after delta in the collector. It is not affected by errors emitted on other threads. In serial compilation it is equivalent to a delta oferr_count.An alternative that removes the global count entirely, bubbling an
ErrorGuaranteedup from each post-monomorphization error source, was explored in #157318. It turns out to be infeasible. Some errors are emitted and then absorbed during collection, so no token ever reaches the collector. Intests/ui/infinite/infinite-instantiation-struct-tail-ice-114484.rsthe recursion-limit error is emitted inside CTFE while normalizing a calleeFnSig, and thePointee::Metadataprojection recovers the error tail to unit metadata before returning, soeval_constantonly ever sees a successfulOk. That recovery cannot be removed: it is what avoids the original #114484 ICE, and propagating the error type instead makes the instantiation collector run away without terminating. The only signal that survives the recovery is the error count, so making that count correct under the parallel frontend by making it per thread is the reliable fix.The second commit removes the
//@ ignore-parallel-frontend post-monomorphization errorsdirective from the tests listed in the issue and re-blesses the line numbers that shift from dropping the directive line. They were run with--parallel-frontend-threads=16 --iteration-count=40 --force-rerunwith no failures.