Skip to content

Add more robust handling of nested query cycles#154389

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Zoxc:nested-cycles
Apr 13, 2026
Merged

Add more robust handling of nested query cycles#154389
rust-bors[bot] merged 1 commit 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.

@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.

"internal compiler error" is just a part of the message, I'm not sure if it's actually a compiler bug, and whether it's possible to eliminate it in all cases, if query cycles in general are not avoidable.

Comment thread tests/ui/query-system/query-cycle-printing-issue-151358.stderr
@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 thread compiler/rustc_query_impl/src/execution.rs
@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
@rust-bors

This comment has been minimized.

@Zoxc
Copy link
Copy Markdown
Contributor Author

Zoxc commented Apr 7, 2026

Blocked on #154973

@aerooneqq aerooneqq mentioned this pull request Apr 10, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

#154973 has landed.
@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-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Apr 12, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 12, 2026

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

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 12, 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.

@petrochenkov
Copy link
Copy Markdown
Contributor

(Please, mark with the label if/when this is ready.)

@Zoxc
Copy link
Copy Markdown
Contributor Author

Zoxc commented Apr 13, 2026

I'd say this is good enough to help out with the OOM cases now.

@rustbot ready

@rustbot rustbot 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 Apr 13, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 13, 2026

📌 Commit 6442b48 has been approved by petrochenkov

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 13, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 13, 2026
Add more robust handling of nested query cycles

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.
rust-bors bot pushed a commit that referenced this pull request Apr 13, 2026
…uwer

Rollup of 19 pull requests

Successful merges:

 - #155162 (relnotes for 1.95)
 - #140763 (Change codegen of LLVM intrinsics to be name-based, and add llvm linkage support for `bf16(xN)` and `i1xN`)
 - #153604 (Fix thread::available_parallelism on WASI targets with threads)
 - #154193 (Implement EII for statics)
 - #154389 (Add more robust handling of nested query cycles)
 - #154435 (resolve: Some import resolution cleanups)
 - #155236 (Normalize individual predicate of `InstantiatedPredicates` inside `predicates_for_generics`)
 - #155243 (cg_ssa: transmute between scalable vectors)
 - #153941 (tests/debuginfo/basic-stepping.rs: Explain why all lines are not steppable)
 - #154587 (Add --verbose-run-make-subprocess-output flag to suppress verbose run-make output for passing tests)
 - #154624 (Make `DerefPure` dyn-incompatible)
 - #154929 (Add `const Default` impls for `LazyCell` and `LazyLock`)
 - #154944 (Small refactor of `arena_cache` query values)
 - #155055 (UI automation)
 - #155062 (Move tests from `tests/ui/issues/` to appropriate directories)
 - #155131 (Stabilize feature `uint_bit_width`)
 - #155147 (Stabilize feature `int_lowest_highest_one`)
 - #155174 (Improve emission of `UnknownDiagnosticAttribute` lint)
 - #155194 (Fix manpage version replacement and use verbose version)
@rust-bors rust-bors bot merged commit e39dfc5 into rust-lang:main Apr 13, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 13, 2026
rust-timer added a commit that referenced this pull request Apr 13, 2026
Rollup merge of #154389 - Zoxc:nested-cycles, r=petrochenkov

Add more robust handling of nested query cycles

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.
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Apr 13, 2026
…uwer

Rollup of 19 pull requests

Successful merges:

 - rust-lang/rust#155162 (relnotes for 1.95)
 - rust-lang/rust#140763 (Change codegen of LLVM intrinsics to be name-based, and add llvm linkage support for `bf16(xN)` and `i1xN`)
 - rust-lang/rust#153604 (Fix thread::available_parallelism on WASI targets with threads)
 - rust-lang/rust#154193 (Implement EII for statics)
 - rust-lang/rust#154389 (Add more robust handling of nested query cycles)
 - rust-lang/rust#154435 (resolve: Some import resolution cleanups)
 - rust-lang/rust#155236 (Normalize individual predicate of `InstantiatedPredicates` inside `predicates_for_generics`)
 - rust-lang/rust#155243 (cg_ssa: transmute between scalable vectors)
 - rust-lang/rust#153941 (tests/debuginfo/basic-stepping.rs: Explain why all lines are not steppable)
 - rust-lang/rust#154587 (Add --verbose-run-make-subprocess-output flag to suppress verbose run-make output for passing tests)
 - rust-lang/rust#154624 (Make `DerefPure` dyn-incompatible)
 - rust-lang/rust#154929 (Add `const Default` impls for `LazyCell` and `LazyLock`)
 - rust-lang/rust#154944 (Small refactor of `arena_cache` query values)
 - rust-lang/rust#155055 (UI automation)
 - rust-lang/rust#155062 (Move tests from `tests/ui/issues/` to appropriate directories)
 - rust-lang/rust#155131 (Stabilize feature `uint_bit_width`)
 - rust-lang/rust#155147 (Stabilize feature `int_lowest_highest_one`)
 - rust-lang/rust#155174 (Improve emission of `UnknownDiagnosticAttribute` lint)
 - rust-lang/rust#155194 (Fix manpage version replacement and use verbose version)
@Zoxc Zoxc deleted the nested-cycles branch April 14, 2026 00:53
}

#[derive(Diagnostic)]
#[diag("internal compiler error: query cycle when printing cycle detected")]
Copy link
Copy Markdown
Member

@matthiaskrgr matthiaskrgr Apr 14, 2026

Choose a reason for hiding this comment

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

this is very confusing as there is neither a stacktrace nor a an according exit code, why not just make this a bug!() ?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because we need to continue execution to print the outermost query cycle. I'm not sure if it's overkill to add a new diagnostic mode for that.

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.

Overkill, IMO, I'd rather just remove "internal compiler error" from the message #154389 (comment).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They're always internal compiler errors though, so that wouldn't be great.

github-actions bot pushed a commit to rust-lang/rust-analyzer that referenced this pull request Apr 16, 2026
…uwer

Rollup of 19 pull requests

Successful merges:

 - rust-lang/rust#155162 (relnotes for 1.95)
 - rust-lang/rust#140763 (Change codegen of LLVM intrinsics to be name-based, and add llvm linkage support for `bf16(xN)` and `i1xN`)
 - rust-lang/rust#153604 (Fix thread::available_parallelism on WASI targets with threads)
 - rust-lang/rust#154193 (Implement EII for statics)
 - rust-lang/rust#154389 (Add more robust handling of nested query cycles)
 - rust-lang/rust#154435 (resolve: Some import resolution cleanups)
 - rust-lang/rust#155236 (Normalize individual predicate of `InstantiatedPredicates` inside `predicates_for_generics`)
 - rust-lang/rust#155243 (cg_ssa: transmute between scalable vectors)
 - rust-lang/rust#153941 (tests/debuginfo/basic-stepping.rs: Explain why all lines are not steppable)
 - rust-lang/rust#154587 (Add --verbose-run-make-subprocess-output flag to suppress verbose run-make output for passing tests)
 - rust-lang/rust#154624 (Make `DerefPure` dyn-incompatible)
 - rust-lang/rust#154929 (Add `const Default` impls for `LazyCell` and `LazyLock`)
 - rust-lang/rust#154944 (Small refactor of `arena_cache` query values)
 - rust-lang/rust#155055 (UI automation)
 - rust-lang/rust#155062 (Move tests from `tests/ui/issues/` to appropriate directories)
 - rust-lang/rust#155131 (Stabilize feature `uint_bit_width`)
 - rust-lang/rust#155147 (Stabilize feature `int_lowest_highest_one`)
 - rust-lang/rust#155174 (Improve emission of `UnknownDiagnosticAttribute` lint)
 - rust-lang/rust#155194 (Fix manpage version replacement and use verbose version)
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Apr 16, 2026
…uwer

Rollup of 19 pull requests

Successful merges:

 - rust-lang/rust#155162 (relnotes for 1.95)
 - rust-lang/rust#140763 (Change codegen of LLVM intrinsics to be name-based, and add llvm linkage support for `bf16(xN)` and `i1xN`)
 - rust-lang/rust#153604 (Fix thread::available_parallelism on WASI targets with threads)
 - rust-lang/rust#154193 (Implement EII for statics)
 - rust-lang/rust#154389 (Add more robust handling of nested query cycles)
 - rust-lang/rust#154435 (resolve: Some import resolution cleanups)
 - rust-lang/rust#155236 (Normalize individual predicate of `InstantiatedPredicates` inside `predicates_for_generics`)
 - rust-lang/rust#155243 (cg_ssa: transmute between scalable vectors)
 - rust-lang/rust#153941 (tests/debuginfo/basic-stepping.rs: Explain why all lines are not steppable)
 - rust-lang/rust#154587 (Add --verbose-run-make-subprocess-output flag to suppress verbose run-make output for passing tests)
 - rust-lang/rust#154624 (Make `DerefPure` dyn-incompatible)
 - rust-lang/rust#154929 (Add `const Default` impls for `LazyCell` and `LazyLock`)
 - rust-lang/rust#154944 (Small refactor of `arena_cache` query values)
 - rust-lang/rust#155055 (UI automation)
 - rust-lang/rust#155062 (Move tests from `tests/ui/issues/` to appropriate directories)
 - rust-lang/rust#155131 (Stabilize feature `uint_bit_width`)
 - rust-lang/rust#155147 (Stabilize feature `int_lowest_highest_one`)
 - rust-lang/rust#155174 (Improve emission of `UnknownDiagnosticAttribute` lint)
 - rust-lang/rust#155194 (Fix manpage version replacement and use verbose version)
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-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.

5 participants