Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoiding calling queries when collecting active queries #138672

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Mar 18, 2025

This PR changes active query collection to no longer call queries. Instead the fields needing queries have their computation delayed to when an cycle error is emitted or when printing the query backtrace in a panic.

This is done by splitting the fields in QueryStackFrame needing queries into a new QueryStackFrameExtra type. When collecting queries QueryStackFrame will contain a closure that can create QueryStackFrameExtra, which does make use of queries. Calling lift on a QueryStackFrame or CycleError will convert it to a variant containing QueryStackFrameExtra using those closures.

This also only calls queries needed to collect information on a cycle errors, instead of information on all active queries.

Calling queries when collecting active queries is a bit odd. Calling queries should not be done in the deadlock handler at all.

This avoids the out of memory scenario in #124901.

@rustbot
Copy link
Collaborator

rustbot commented Mar 18, 2025

r? @fmease

rustbot has assigned @fmease.
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

@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 Mar 18, 2025
@rust-log-analyzer

This comment has been minimized.

@Zoxc Zoxc force-pushed the deferred-queries-in-deadlock-handler branch from 367760a to fc76480 Compare March 18, 2025 17:19
@bors
Copy link
Contributor

bors commented Mar 19, 2025

☔ The latest upstream changes (presumably #122156) made this pull request unmergeable. Please resolve the merge conflicts.

@fmease
Copy link
Member

fmease commented Mar 19, 2025

r? oli-obk or fee1-dead?

@rustbot rustbot assigned oli-obk and unassigned fmease Mar 19, 2025
@Zoxc Zoxc force-pushed the deferred-queries-in-deadlock-handler branch from a88999f to b482491 Compare March 22, 2025 19:56
@rust-log-analyzer

This comment has been minimized.

@Zoxc Zoxc force-pushed the deferred-queries-in-deadlock-handler branch from b482491 to 1c4bb4f Compare March 22, 2025 23:01
@bors
Copy link
Contributor

bors commented Mar 24, 2025

☔ The latest upstream changes (presumably #115747) made this pull request unmergeable. Please resolve the merge conflicts.

@Zoxc Zoxc force-pushed the deferred-queries-in-deadlock-handler branch from 1c4bb4f to 9f25677 Compare March 24, 2025 19:29
@bors
Copy link
Contributor

bors commented Mar 26, 2025

☔ The latest upstream changes (presumably #138933) made this pull request unmergeable. Please resolve the merge conflicts.

@Zoxc Zoxc force-pushed the deferred-queries-in-deadlock-handler branch from 9f25677 to f3448e6 Compare March 26, 2025 01:04
@bors
Copy link
Contributor

bors commented Mar 26, 2025

☔ The latest upstream changes (presumably #138956) made this pull request unmergeable. Please resolve the merge conflicts.

@Zoxc Zoxc force-pushed the deferred-queries-in-deadlock-handler branch from f3448e6 to 23c63a9 Compare March 26, 2025 08:25
@rust-log-analyzer

This comment has been minimized.

@Zoxc Zoxc force-pushed the deferred-queries-in-deadlock-handler branch from 23c63a9 to 6319bb3 Compare March 26, 2025 08:36
@oli-obk
Copy link
Contributor

oli-obk commented Mar 26, 2025

Thanks!

@bors r+

@bors
Copy link
Contributor

bors commented Mar 26, 2025

📌 Commit 6ca2af6 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors 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 Mar 26, 2025
/// but can later be changed to `QueryStackFrameExtra` containing concrete information
/// by calling `lift`. This is done so that collecting query does not need to invoke
/// queries, instead `lift` will call queries in a more appropriate location.
pub info: I,
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the distinction between the lazy and evaluated frame extra need to be encoded into type system?
It causes the new generic parameter to spread over all of the query system.

Can it be an enum (or a dyn trait like LazyAttrTokenStream) instead of a generic?
If this is only used in query cycles, then it probably won't affect the query system performance on a good path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To make it an enum, we'd need to add 'tcx to the query system crate, so it could refer to QueryStackDeferred. That may spread further than the I parameter I used.

TaKO8Ki added a commit to TaKO8Ki/rust that referenced this pull request Mar 26, 2025
…handler, r=oli-obk

Avoiding calling queries when collecting active queries

This PR changes active query collection to no longer call queries. Instead the fields needing queries have their computation delayed to when an cycle error is emitted or when printing the query backtrace in a panic.

This is done by splitting the fields in `QueryStackFrame` needing queries into a new `QueryStackFrameExtra` type. When collecting queries `QueryStackFrame` will contain a closure that can create `QueryStackFrameExtra`, which does make use of queries. Calling `lift` on a `QueryStackFrame` or `CycleError` will convert it to a variant containing `QueryStackFrameExtra` using those closures.

This also only calls queries needed to collect information on a cycle errors, instead of information on all active queries.

Calling queries when collecting active queries is a bit odd. Calling queries should not be done in the deadlock handler at all.

This avoids the out of memory scenario in rust-lang#124901.
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 26, 2025
Rollup of 9 pull requests

Successful merges:

 - rust-lang#130883 (Add environment variable query)
 - rust-lang#138672 (Avoiding calling queries when collecting active queries)
 - rust-lang#138702 (Allow spawning threads after TLS destruction)
 - rust-lang#138935 (Update wg-prio triagebot config)
 - rust-lang#138946 (Un-bury chapters from the chapter list in rustc book)
 - rust-lang#138964 (Implement lint against using Interner and InferCtxtLike in random compiler crates)
 - rust-lang#138977 (Don't deaggregate InvocationParent just to reaggregate it again)
 - rust-lang#138980 (Collect items referenced from var_debug_info)
 - rust-lang#138985 (Use the correct binder scope for elided lifetimes in assoc consts)

r? `@ghost`
`@rustbot` modify labels: rollup
Zalathar added a commit to Zalathar/rust that referenced this pull request Mar 27, 2025
…handler, r=oli-obk

Avoiding calling queries when collecting active queries

This PR changes active query collection to no longer call queries. Instead the fields needing queries have their computation delayed to when an cycle error is emitted or when printing the query backtrace in a panic.

This is done by splitting the fields in `QueryStackFrame` needing queries into a new `QueryStackFrameExtra` type. When collecting queries `QueryStackFrame` will contain a closure that can create `QueryStackFrameExtra`, which does make use of queries. Calling `lift` on a `QueryStackFrame` or `CycleError` will convert it to a variant containing `QueryStackFrameExtra` using those closures.

This also only calls queries needed to collect information on a cycle errors, instead of information on all active queries.

Calling queries when collecting active queries is a bit odd. Calling queries should not be done in the deadlock handler at all.

This avoids the out of memory scenario in rust-lang#124901.
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 27, 2025
Rollup of 10 pull requests

Successful merges:

 - rust-lang#130883 (Add environment variable query)
 - rust-lang#138624 (Add mipsel maintainer)
 - rust-lang#138672 (Avoiding calling queries when collecting active queries)
 - rust-lang#138935 (Update wg-prio triagebot config)
 - rust-lang#138946 (Un-bury chapters from the chapter list in rustc book)
 - rust-lang#138964 (Implement lint against using Interner and InferCtxtLike in random compiler crates)
 - rust-lang#138977 (Don't deaggregate InvocationParent just to reaggregate it again)
 - rust-lang#138980 (Collect items referenced from var_debug_info)
 - rust-lang#138985 (Use the correct binder scope for elided lifetimes in assoc consts)
 - rust-lang#138987 (Always emit `native-static-libs` note, even if it is empty)

r? `@ghost`
`@rustbot` modify labels: rollup
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.

7 participants