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 orders the entry points instead of taking the first one. The primary key is the incoming-edge span: the cycle stack records, for each query, the span where its predecessor in the cycle requested it. For the recursive-definition cycles these errors come from, the entry point with the latest incoming-edge span is the query the single-threaded path anchors at, so this keeps the parallel output matching the committed .stderr. Span ties prefer an entry point that has an outside waiter, so the "cycle used when" note is still produced, then fall back to the query's stable description.

This is a heuristic rather than a guaranteed total order: if two entry points share both a span and a description the choice is still arbitrary, and there is no stable per-job key to order them by since QueryJobId is assigned in racy execution order. For the cycles these tests exercise the edge spans are distinct, so the anchor is deterministic in practice, which is what the parallel test suite needs.

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

@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
@xmakro xmakro force-pushed the fix/parallel-query-cycle branch from e642a03 to f4a84eb Compare June 3, 2026 05:05
@petrochenkov petrochenkov self-assigned this Jun 3, 2026
@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 3, 2026
@xmakro xmakro force-pushed the fix/parallel-query-cycle branch from f4a84eb to e3e3e67 Compare June 3, 2026 15:54
@petrochenkov
Copy link
Copy Markdown
Contributor

r? @Zoxc could you check if this generally makes sense?

Sorting based on spans is still not deterministic because all the spans can potentially be the same (including dummy), but it may be more deterministic than just some arbitrarily selected order, which may be enough for our parallel test suite in practice.

(The change is most likely LLM-generated so feel free to close if you don't want to look.)

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jun 3, 2026

Failed to set assignee to Zoxc: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@petrochenkov
Copy link
Copy Markdown
Contributor

(Ok, leaving assigned to me, but marking as blocked on @Zoxc looking.)
@rustbot blocked

@rustbot rustbot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 3, 2026
xmakro added 2 commits June 3, 2026 11:00
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.

Order the entry points instead of taking the first one. The primary key
is the incoming-edge span: the cycle stack records, for each query, the
span where its predecessor in the cycle requested it. For the
recursive-definition cycles these errors come from, the entry point with
the latest incoming-edge span is the query the single-threaded path
anchors at, so this keeps the parallel output matching the committed
.stderr. Span ties prefer an entry point that has an outside waiter, so
the "cycle used when ..." note is still produced, then fall back to the
query's stable description.

This is a heuristic rather than a guaranteed total order: if two entry
points share both a span and a description the choice is still arbitrary,
and there is no stable per-job key to order them by since QueryJobId is
assigned in racy execution order. For the cycles these tests exercise the
edge spans are distinct, so the anchor is deterministic in practice,
which is what the parallel test suite needs.

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 replace the directive
with a blank line rather than deleting it. The following source lines stay
in place, so the expected stderr is unchanged.
@xmakro xmakro force-pushed the fix/parallel-query-cycle branch from e3e3e67 to 6d4945e Compare June 3, 2026 18:00
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-blocked Status: Blocked on something else such as an RFC or other implementation work. 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.

3 participants