Skip to content

Make parallel query-cycle reporting deterministic#157343

Draft
xmakro wants to merge 2 commits into
rust-lang:mainfrom
xmakro:fix/parallel-query-cycle
Draft

Make parallel query-cycle reporting deterministic#157343
xmakro wants to merge 2 commits into
rust-lang:mainfrom
xmakro:fix/parallel-query-cycle

Conversation

@xmakro
Copy link
Copy Markdown

@xmakro xmakro commented Jun 3, 2026

The parallel front-end reports query cycles through the deadlock handler, which collects the active query jobs in a nondeterministic order. process_cycle then anchored the reported cycle at entry_points[0] (or the first entry point that has a waiter), so the query the cycle text was anchored at changed from run to run, and several UI tests had unstable output under -Zthreads.

This makes the entry-point selection deterministic. Single-threaded cycle reporting anchors at the query that was entered first, that is the one defined earliest in the source. The cycle stack records, for each query, the span of its incoming edge: where its predecessor in the cycle requested it. The query the cycle wraps back around to has the latest such span, so the entry point with the maximum incoming-edge span is chosen to match the single-threaded anchor. Ties prefer an entry point that has an outside waiter so the "cycle used when" note is still produced.

process_cycle only runs under the parallel front-end, so single-threaded output is unchanged.

With the anchor stable, six UI tests that were marked ignore-parallel-frontend for this reason are re-enabled. Removing the directive line shifts the following source lines up by one, so their expected stderr is re-blessed accordingly.

The remaining ignored cycle tests are left as-is: they fail for other reasons (the "cycle used when" note attribution, or selection among multiple simultaneous cycles) that this change does not address.

Validated single-threaded and under --parallel-frontend-threads=16 at high iteration counts (400 to 600 iterations per test with --force-rerun).

xmakro added 2 commits June 2, 2026 17:15
When the parallel front-end detects a query cycle, the deadlock handler
collects the active query jobs in a nondeterministic order. process_cycle
then picked entry_points[0] (or the first entry point that has a waiter),
so the query the cycle was anchored at changed from run to run and the
reported cycle text was unstable.

Single-threaded cycle reporting anchors at the query that was entered
first, that is the one defined earliest in the source. The cycle stack
records, for each query, the span of its incoming edge: where its
predecessor in the cycle requested it. The query the cycle wraps back
around to has the latest such span, so pick the entry point with the
maximum incoming-edge span to match the single-threaded anchor. Ties
prefer an entry point that has an outside waiter so the "cycle used when"
note is still produced.

This only changes process_cycle, which runs exclusively under the
parallel front-end, so single-threaded output is unchanged.
These tests were marked ignore-parallel-frontend because the reported
cycle anchor was nondeterministic. Now that process_cycle picks the
entry point deterministically their output is stable, so drop the
directive. Removing the directive line shifts the following source
lines up by one, so the expected stderr is re-blessed to match.
@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) 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 3, 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-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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants