Skip to content

Fix post-monomorphization error note race in the parallel frontend#157282

Open
xmakro wants to merge 2 commits into
rust-lang:mainfrom
xmakro:fix/parallel-pme-note
Open

Fix post-monomorphization error note race in the parallel frontend#157282
xmakro wants to merge 2 commits into
rust-lang:mainfrom
xmakro:fix/parallel-pme-note

Conversation

@xmakro
Copy link
Copy Markdown
Contributor

@xmakro xmakro commented Jun 2, 2026

Fixes #154260. Part of #154314.

collect_items_rec decides whether to attach the note "the above error was encountered while instantiating fn ..." by snapshotting the error count before processing a mono item and comparing it afterwards. The mono item graph is walked in parallel (the par_for_each_in in collect_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:

note: the above error was encountered while instantiating `fn std::rt::lang_start::<()>`

This PR records the thread that emits each error alongside its ErrorGuaranteed in err_guars, lint_err_guars, and the stashed-diagnostics map, and add err_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 of err_count.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 2, 2026
@rust-log-analyzer

This comment has been minimized.

@xmakro xmakro marked this pull request as ready for review June 2, 2026 19:36
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 2, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 2, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jun 2, 2026

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 (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 18 candidates

@xmakro xmakro force-pushed the fix/parallel-pme-note branch from a57bd28 to 67b98f4 Compare June 2, 2026 19:40
@mejrs
Copy link
Copy Markdown
Contributor

mejrs commented Jun 2, 2026

r? @petrochenkov

@rustbot rustbot assigned petrochenkov and unassigned mejrs Jun 2, 2026
Comment thread tests/ui/abi/simd-abi-checks-avx.rs
@xmakro xmakro force-pushed the fix/parallel-pme-note branch from 67b98f4 to 8649755 Compare June 3, 2026 15:54
Comment on lines +739 to +741
pub fn err_count_on_current_thread(&self) -> usize {
THREAD_ERR_COUNT.with(Cell::get)
}
Copy link
Copy Markdown
Contributor

@zetanumbers zetanumbers Jun 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

@xmakro xmakro Jun 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I added the ThreadId explicitly to the relevant vecs holding errors, do you prefer type ErrCountId = ThreadId?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please no type alias. This is fine.

@xmakro xmakro force-pushed the fix/parallel-pme-note branch 2 times, most recently from 041103b to bc17536 Compare June 4, 2026 16:12
Comment thread compiler/rustc_errors/src/lib.rs Outdated
Comment thread compiler/rustc_errors/src/lib.rs Outdated
Comment thread compiler/rustc_errors/src/lib.rs Outdated
Comment thread compiler/rustc_monomorphize/src/collector.rs Outdated
@xmakro xmakro force-pushed the fix/parallel-pme-note branch from bc17536 to 2e128c7 Compare June 5, 2026 16:56
@xmakro
Copy link
Copy Markdown
Contributor Author

xmakro commented Jun 5, 2026

Thanks, addressed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parallel frontend tests failures due to different post-monomorphization errors

6 participants