Fix post-monomorphization error note race in the parallel frontend#157282
Fix post-monomorphization error note race in the parallel frontend#157282xmakro wants to merge 2 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
|
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
67b98f4 to
8649755
Compare
| pub fn err_count_on_current_thread(&self) -> usize { | ||
| THREAD_ERR_COUNT.with(Cell::get) | ||
| } |
There was a problem hiding this comment.
This method is misleading since instead of modifying the self argument it actually modifies a thread local. Instead we could store a ThreadId in the err_guars, lint_err_guars and stashed_diagnostics fields so that err_count_on_current_thread could filter and count errors almost like the old err_count, but also counting only matching ThreadIds.
There was a problem hiding this comment.
TBH we could use any type for this CountErrorsId as long as we set it in compiler/rustc_monomorphize/src/errors.rs and it is implicitly "passed down" to through the callstack, in a thread local for example.
There was a problem hiding this comment.
Thanks, I added the ThreadId explicitly to the relevant vecs holding errors, do you prefer type ErrCountId = ThreadId?
There was a problem hiding this comment.
Please no type alias. This is fine.
041103b to
bc17536
Compare
bc17536 to
2e128c7
Compare
|
Thanks, addressed |
Fixes #154260. Part of #154314.
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 when using parallel frontend:This PR records the thread that emits each error alongside its
ErrorGuaranteedinerr_guars,lint_err_guars, and the stashed-diagnostics map, and adderr_count_on_current_thread, which counts only the errors whose recorded thread is the calling thread. The collector uses it for the snapshot and comparison, so the delta is not affected by errors emitted on other threads. In serial compilation it is equivalent to a delta oferr_count.