Skip to content

Conversation

@zetanumbers
Copy link
Contributor

@zetanumbers zetanumbers commented Dec 19, 2025

Fixes #150018
Fixes #142778
Fixes #141540

This PR allows parallel front-end's green-red node coloring processes in the query dep graph to race. Recall that whenever one thread tries to mark query node green and then fails to reconstruct a subquery's key to force it, parent query is tried to be forced or executed too. The subquery could be marked green by the thread during execution the parent query because key is now present. Other thread during this process is able to mark green parent query itself. And so after some time the first thread finishes the execution and finds in its place a green node. This is bad for no_hash queries since those are conservatively presumed to be red but actually queries must be deterministic anyway and so no_hash nodes should be colored green if its deps are green too after its execution finishes. As such we can consider green color to be "stronger" that the red color and thus former would replace the latter.

TODO: update rustc-dev-guide query docs and rustc comments on no_hash modifier

I have left some refactor-ish changes I did during my dirty debugging. Let me know if you would want those to be redone or removed.

Steps to reproduce

Quote from #150018, more details there:

Do a clean build x build library --stage 1 at 52fda2e, then git checkout to ba45f0b and without cleaning try rebuilding it the same way again. And don't forget to set RUSTFLAGS_BOOTSTRAP to -Zthreads=n where n > 1.

@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) 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. labels Dec 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 19, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@petrochenkov
Copy link
Contributor

cc @Zoxc @cjgillot @nnethercote

@zetanumbers
Copy link
Contributor Author

zetanumbers commented Dec 19, 2025

My first idea was to add a special "locked" color, but I wasn't sure what was even happening in there because coloring races currently are considered to be normal anyway.

@matthiaskrgr
Copy link
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Dec 19, 2025
@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 19, 2025
@zetanumbers
Copy link
Contributor Author

zetanumbers commented Dec 19, 2025

I ran rustc incremental builds as described in reproduction steps section for several hours with -Zthreads, debug=true and -Zincremental_verify_ich and it's looking good.

@rust-bors
Copy link
Contributor

rust-bors bot commented Dec 19, 2025

☀️ Try build successful (CI)
Build commit: bb5a19e (bb5a19e1ef3ed803b9a2acd98a3b223334df5063, parent: 0f0d850e9146f53b16fb1c6a56ed2f821962ff94)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (bb5a19e): comparison URL.

Overall result: ❌ regressions - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
2.3% [0.3%, 6.6%] 117
Regressions ❌
(secondary)
1.7% [0.2%, 4.9%] 75
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.3% [0.3%, 6.6%] 117

Max RSS (memory usage)

Results (primary -3.5%, secondary -1.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.5% [-3.5%, -3.5%] 1
Improvements ✅
(secondary)
-1.5% [-2.2%, -0.8%] 2
All ❌✅ (primary) -3.5% [-3.5%, -3.5%] 1

Cycles

Results (primary 3.0%, secondary 3.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
3.0% [2.9%, 3.1%] 2
Regressions ❌
(secondary)
3.4% [2.3%, 4.9%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.0% [2.9%, 3.1%] 2

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 479.055s -> 481.828s (0.58%)
Artifact size: 390.50 MiB -> 390.50 MiB (0.00%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Dec 19, 2025
@petrochenkov
Copy link
Contributor

As usual, it would be nice to split the work into a few parts (especially given the perf regressions):

  • Preparatory changes and refactorings (passing the frame and feed around, the named iterator change, the COMPRESSED_RED_BIT change, and few others)
  • The assert hardening changes
  • The substantial changes modifying the logic in try_mark and alloc_and_color_node

But it may be better to wait for a high level design review from Zoxc or cjgillot before doing that.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 19, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@cjgillot
Copy link
Contributor

Recall that whenever one thread tries to mark query node green and then fails to reconstruct a subquery's key to force it, parent query is tried to be forced or executed too. The subquery could be marked green by the thread during execution the parent query because key is now present.

Could you elaborate how this can happen? Key reconstructibility is not supposed to change.

I agree with @petrochenkov's suggestion to split pure reactors from the actual change. Parallelism and atomic are hard enough to make review as easy as possible.

3 similar comments
@cjgillot

This comment was marked as duplicate.

@cjgillot

This comment was marked as duplicate.

@cjgillot

This comment was marked as duplicate.

@zetanumbers
Copy link
Contributor Author

Recall that whenever one thread tries to mark query node green and then fails to reconstruct a subquery's key to force it, parent query is tried to be forced or executed too. The subquery could be marked green by the thread during execution the parent query because key is now present.

Could you elaborate how this can happen? Key reconstructibility is not supposed to change.

When some thread fails to mark some node green, it won't immediately mark that node red. It will try force the deepest possible node it can (aka one with the reconstructible key). While you are forcing a parent of that node you will execute that problematic child query you were unable to mark green (due to red dependencies) or force directly (due to unreconstructible key). That problematic query node could be marked as green if its computed result didn't change. But meanwhile another thread may try mark that parent node green as well too and so could now succeed, even tho the first thread is executing that query and will try mark it red if that query has no_hash modifier:

// This is a red node, effectively: it existed in the previous compilation
// session, its query was re-executed, but it doesn't compute a result hash
// (i.e. it represents a `no_hash` query), so we have no way of determining
// whether or not the result was the same as before.

But I suggest that's not really true. If no_hash query's dependencies are all green, it has to be green too.

And yes, no_hash queries cannot be force directly either, so it is actually done indirectly through another query.

@rustbot
Copy link
Collaborator

rustbot commented Jan 13, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@zetanumbers zetanumbers changed the title Allow green-red query coloring race Try mark no_hash queries as green after execution Jan 13, 2026
@petrochenkov
Copy link
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Jan 13, 2026
Try mark `no_hash` queries as green after execution
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 13, 2026
@zetanumbers
Copy link
Contributor Author

zetanumbers commented Jan 13, 2026

Seems like no node coloring race is required after all.

@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 Jan 13, 2026
@zetanumbers zetanumbers reopened this Jan 13, 2026
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 13, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 13, 2026

☀️ Try build successful (CI)
Build commit: 4b1294d (4b1294da0c6bc573b4608a908d2089ed17eeb095, parent: b2a322beb29110e22a1782e2ce5ed2a0719b81ed)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (4b1294d): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 473.958s -> 475.113s (0.24%)
Artifact size: 383.19 MiB -> 383.20 MiB (0.00%)

@rustbot rustbot removed S-waiting-on-perf Status: Waiting on a perf run to be completed. perf-regression Performance regression. labels Jan 13, 2026
@zetanumbers
Copy link
Contributor Author

@rustbot ready

@cjgillot cjgillot self-assigned this Jan 13, 2026
// This is a red node: it existed in the previous compilation, its query
// was re-executed, but it has a different result from before.
#[cfg(debug_assertions)]
if !feed && !cx.is_eval_always(key.kind) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if !feed && !cx.is_eval_always(key.kind) {
if cfg!(debug_assertions) && !feed && !cx.is_eval_always(key.kind) {

Nit: so the code is at least type checked in all build modes.

@petrochenkov
Copy link
Contributor

(Leaving this to @cjgillot to review.)

@petrochenkov petrochenkov removed their assignment Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) 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

6 participants