Skip to content

Add a QueryKeyId to identify a query instance#153492

Open
Zoxc wants to merge 1 commit intorust-lang:mainfrom
Zoxc:querykeyid
Open

Add a QueryKeyId to identify a query instance#153492
Zoxc wants to merge 1 commit intorust-lang:mainfrom
Zoxc:querykeyid

Conversation

@Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Mar 6, 2026

This adds back a QueryKeyId enum which represents a query kind and the associated key. This is used to replace QueryStackDeferred and QueryStackFrameExtra and the associated lifting operation for cycle errors

This approach has a couple of benefits:

  • We only run description queries when printing the query stack trace in the panic handler
  • The unsafe code for QueryStackDeferred is removed
  • Cycle handles have access to query keys, which may be handy

Some further work could be replacing QueryStackFrame with QueryKeyId as the extra information can be derived from it.

@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 6, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 6, 2026

r? @mati865

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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, query-system
  • compiler, query-system expanded to 69 candidates
  • Random selection from 16 candidates

@Zoxc
Copy link
Contributor Author

Zoxc commented Mar 6, 2026

cc @nnethercote @Zalathar

@Zalathar
Copy link
Member

Zalathar commented Mar 6, 2026

If we can get rid of a lot of the QueryStackFrame complexity by just storing the query key in an enum, that seems great.

The name QueryKeyId seems strange to me, though. It’s not the ID of a query key; it’s the key itself, “tagged” with the query that it belongs to.

@Zoxc
Copy link
Contributor Author

Zoxc commented Mar 6, 2026

The name QueryKeyId seems strange to me, though. It’s not the ID of a query key; it’s the key itself, “tagged” with the query that it belongs to.

Yeah, QueryId was taken, maybe QueryInstance is better?

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 6, 2026

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

@nnethercote nnethercote assigned nnethercote and unassigned mati865 Mar 6, 2026
@nnethercote
Copy link
Contributor

This looks great! I hate the deferred/extra split, this seems like a really clean way to eliminate it.

@Zoxc: can you expand the first paragraph of the PR description to explain (a) the current situation, and (b) how this PR changes that situation? I've skimmed the changes and they look good, but I will need to look again more closely on Monday to get my head fully around how the new QueryKeyId is used and how it lets so much of the existing complexity be removed. Extra description will help with that.

cc @zetanumbers

@Zalathar
Copy link
Member

Zalathar commented Mar 6, 2026

Yeah, QueryId was taken, maybe QueryInstance is better?

I was thinking of something like TaggedQueryKey, because the value being stored is a query key, tagged with its corresponding query.

I think it's easier to say “this is a key that also indicates what query it came from” than to try to come up with an intuitive name for query+key.

Or we could go for something like QueryAndKey or QueryWithKey.

@nnethercote
Copy link
Contributor

TaggedQueryKey sounds good to me -- that's exactly what it is!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants