Add a TaggedQueryKey to identify a query instance#153492
Add a TaggedQueryKey to identify a query instance#153492Zoxc wants to merge 1 commit intorust-lang:mainfrom
TaggedQueryKey to identify a query instance#153492Conversation
|
r? @mati865 rustbot has assigned @mati865. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
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 |
Yeah, |
This comment has been minimized.
This comment has been minimized.
|
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 cc @zetanumbers |
I was thinking of something like 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 |
|
|
|
Just a little more work required to get this into shape. @rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
QueryKeyId to identify a query instanceTaggedQueryKey to identify a query instance
This comment has been minimized.
This comment has been minimized.
| } | ||
| match self { | ||
| $( | ||
| TaggedQueryKey::$name(key) => inner(key, tcx), |
There was a problem hiding this comment.
Why have inner? Why not just call key.key_as_def_id()... here?
There was a problem hiding this comment.
It reduces code generation as inner can be reused for shared key types.
There was a problem hiding this comment.
Can you add a comment explaining this?
| pub info: I, | ||
|
|
||
| pub struct QueryStackFrame<'tcx> { | ||
| pub id: TaggedQueryKey<'tcx>, |
There was a problem hiding this comment.
This field needs renaming. Maybe tagged_key?
There was a problem hiding this comment.
It is used as an identifier though?
There was a problem hiding this comment.
In the compiler, an “id” is usually an opaque or mostly-opaque integer that indexes into some other table, so I don’t understand the motivation behind calling this value an id.
| query: &'tcx QueryVTable<'tcx, C>, | ||
| tcx: TyCtxt<'tcx>, | ||
| require_complete: bool, | ||
| make_id: fn(C::Key) -> TaggedQueryKey<'tcx>, |
There was a problem hiding this comment.
This parameter needs renaming. Maybe mk_tagged_key?
| vtable: &'tcx QueryVTable<'tcx, C>, | ||
| key: C::Key, | ||
| ) -> QueryStackFrame<QueryStackDeferred<'tcx>> | ||
| make_id: fn(C::Key) -> TaggedQueryKey<'tcx>, |
|
#153685 conflicts a bit as |
|
Would it work to add the enum constructor as a function in QueryVTable? |
|
I think so, but I'd probably prefer reverting the use of |
Given that the variant constructor is already being passed around as a |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
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. |
View all comments
This adds back a
TaggedQueryKeyenum which represents a query kind and the associated key. This is used to replaceQueryStackDeferredandQueryStackFrameExtraand the associated lifting operation for cycle errorsThis approach has a couple of benefits:
QueryStackDeferredis removedSome further work could be replacing
QueryStackFramewithTaggedQueryKeyas the extra information can be derived from it.