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

@xmakro xmakro commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

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

rustbot commented Jun 2, 2026

Copy link
Copy Markdown
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 (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

mejrs commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

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 thread compiler/rustc_errors/src/lib.rs
@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

xmakro commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, addressed

@zetanumbers

Copy link
Copy Markdown
Contributor

LGTM

@petrochenkov

Copy link
Copy Markdown
Contributor

This is not really correct, an OS thread id is used for the filtering here, but the work that is done between the two calls to err_count_on_current_thread can potentially be run on multiple different OS threads.
But the currently existing logic is not correct either, so if this change improves the situation in practice, the let's do it. The change is not complex and doesn't add too much technical debt.
@bors r+

@rust-bors

rust-bors Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 2e128c7 has been approved by petrochenkov

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 5. This pull request will be tested once the tree is reopened.

@rust-bors rust-bors Bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jun 10, 2026
@rust-bors rust-bors Bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 10, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 10, 2026
…trochenkov

Fix post-monomorphization error note race in the parallel frontend

Fixes rust-lang#154260. Part of rust-lang#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`.
rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - #157280 (traits: Allow escaping self types in ExistentialTraitRef::with_self_ty)
 - #157282 (Fix post-monomorphization error note race in the parallel frontend)
 - #157352 (Make the retained dep graph deterministic under the parallel frontend)
 - #157601 (Emit error for unused target expression in glob and list delegations)
 - #157626 (Autogenerate unstable compiler flag stubs for unstable-book)
 - #157647 (Start using comptime for reflection intrinsics and their wrapper functions)
 - #157013 (Ensure inferred let pattern types are well-formed)
 - #157288 (platform support: add SNaN erratum to MIPS targets)
 - #157355 (Add `or_try_*` variants for `HashMap` and `BTreeMap` Entry APIs)
 - #157577 (Fix parser error recovery treating 'dyn' as a strict keyword in Rust …)
 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
 - #157691 (Move symbol hiding code to a new file)
 - #157700 (Rename `errors.rs` file to `diagnostics.rs` (5/N))
 - #157703 (Fix doc link to Instant sub in saturating caveat)

Failed merges:

 - #157699 (Arg splat experiment - hir FnDecl impl)
rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - #157280 (traits: Allow escaping self types in ExistentialTraitRef::with_self_ty)
 - #157282 (Fix post-monomorphization error note race in the parallel frontend)
 - #157352 (Make the retained dep graph deterministic under the parallel frontend)
 - #157601 (Emit error for unused target expression in glob and list delegations)
 - #157626 (Autogenerate unstable compiler flag stubs for unstable-book)
 - #157647 (Start using comptime for reflection intrinsics and their wrapper functions)
 - #157013 (Ensure inferred let pattern types are well-formed)
 - #157288 (platform support: add SNaN erratum to MIPS targets)
 - #157355 (Add `or_try_*` variants for `HashMap` and `BTreeMap` Entry APIs)
 - #157577 (Fix parser error recovery treating 'dyn' as a strict keyword in Rust …)
 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
 - #157691 (Move symbol hiding code to a new file)
 - #157700 (Rename `errors.rs` file to `diagnostics.rs` (5/N))
 - #157703 (Fix doc link to Instant sub in saturating caveat)

Failed merges:

 - #157699 (Arg splat experiment - hir FnDecl impl)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 10, 2026
…trochenkov

Fix post-monomorphization error note race in the parallel frontend

Fixes rust-lang#154260. Part of rust-lang#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`.
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 10, 2026
…trochenkov

Fix post-monomorphization error note race in the parallel frontend

Fixes rust-lang#154260. Part of rust-lang#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`.
rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
Rollup of 23 pull requests

Successful merges:

 - #157280 (traits: Allow escaping self types in ExistentialTraitRef::with_self_ty)
 - #157282 (Fix post-monomorphization error note race in the parallel frontend)
 - #157352 (Make the retained dep graph deterministic under the parallel frontend)
 - #157601 (Emit error for unused target expression in glob and list delegations)
 - #157611 (Update `browser-ui-test` version to `0.24.0`)
 - #157620 (Add a strategy FnMut to inject behavior into the flush cycle)
 - #157645 (Windows TLS - Only register the `atexit` hook when `cleanup` can be unloaded)
 - #157647 (Start using comptime for reflection intrinsics and their wrapper functions)
 - #157719 (resolve: Partially revert "Remove a special case for dummy imports")
 - #156497 (fix-155516: Don't suggest wrong unwrap expect)
 - #156583 (Support defaults for static EIIs)
 - #157013 (Ensure inferred let pattern types are well-formed)
 - #157230 (borrowck: avoid ICE describing fields on generic params)
 - #157288 (platform support: add SNaN erratum to MIPS targets)
 - #157350 (compiletest: ignore SVG `y` offset in by-lines comparison)
 - #157355 (Add `or_try_*` variants for `HashMap` and `BTreeMap` Entry APIs)
 - #157384 (Add `#[rustc_dump_generics]` attribute)
 - #157577 (Fix parser error recovery treating 'dyn' as a strict keyword in Rust 2015 when used in `dyn + dyn`)
 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
 - #157691 (Move symbol hiding code to a new file)
 - #157697 (Add more tests that exercise the well-formedness checking of lazy type aliases)
 - #157700 (Rename `errors.rs` file to `diagnostics.rs` (5/N))
 - #157703 (Fix doc link to Instant sub in saturating caveat)

Failed merges:

 - #157699 (Arg splat experiment - hir FnDecl impl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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