Skip to content

Add more robust handling of nested query cycles#154389

Open
Zoxc wants to merge 2 commits intorust-lang:mainfrom
Zoxc:nested-cycles
Open

Add more robust handling of nested query cycles#154389
Zoxc wants to merge 2 commits intorust-lang:mainfrom
Zoxc:nested-cycles

Conversation

@Zoxc
Copy link
Copy Markdown
Contributor

@Zoxc Zoxc commented Mar 25, 2026

This adds more robust handling of query cycle that occur while we are already printing a query cycle error. Such nested query cycle are compiler bugs and this adds special handling so that both the nested query cycle and the outer query cycle are printed. Doubly nested query cycle errors are ignored to prevent infinite recursion.

This is based on #153999

@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 Mar 25, 2026
@Zoxc
Copy link
Copy Markdown
Contributor Author

Zoxc commented Mar 25, 2026

The nested query cycles are currently printed as errors as I don't think we have the mechanism to resume after emitting a bug.

This means we have 2 tests that are failing which were previously "undetected".

@petrochenkov petrochenkov self-assigned this Apr 7, 2026
@petrochenkov petrochenkov removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 7, 2026
@petrochenkov petrochenkov marked this pull request as ready for review April 7, 2026 11:09
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 7, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

This is now a blocker for the delegation work (like #154368) where you get compiler hangs instead of query cycle errors quite often due to this issue.
I'm going to review and merge this sooner rather than later to address the hangs, even if the implementation is not perfect, and @Zalathar and @nnethercote can cleanup it later if necessary.

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.

We shouldn't be testing for ICEs, but fixing them instead.

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.

Testing for ICE

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.

Testing for ICE

@Zoxc
Copy link
Copy Markdown
Contributor Author

Zoxc commented Apr 7, 2026

This is currently racy as we can resume multiple query cycles at once, so the global counter doesn't work. I have a branch which changes that, but I was waiting for #154146 to land first.

Comment on lines +122 to +127
0 => false,
1 => true,
_ => {
// Don't print further nested errors to avoid cases of infinite recursion
tcx.dcx().delayed_bug("doubly nested cycle error").raise_fatal()
}
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.

We call handle_cycle function in wait_for_query after breaking and resuming from one or multiple query cycles. As such this might race with other handle_cycle calls which wouldn't be a "nested" query cycles.

@petrochenkov
Copy link
Copy Markdown
Contributor

Blocked on #153999 and #154146.
@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 Apr 7, 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-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.

4 participants