Move and expand the big rustc_query_impl macro into a physical query_impl.rs#153760
Move and expand the big rustc_query_impl macro into a physical query_impl.rs#153760rust-bors[bot] merged 2 commits intorust-lang:mainfrom
rustc_query_impl macro into a physical query_impl.rs#153760Conversation
|
cc @Zoxc @zetanumbers on this structural change to The idea of splitting off the big macro has some overlap with the ideas in #151977, but I think the key insight of this PR is that there's a lot of benefit from defining and expanding the macro in the same module. |
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.
There was a problem hiding this comment.
It is good to define and call define_queries in the same file.
Are you planning to do the same for define_callbacks? I like when it and define_queries are as similar as possible. That would require moving define_callbacks into compiler/rustc_middle/src/queries.rs.
| @@ -0,0 +1,263 @@ | |||
| use rustc_middle::query::plumbing::QueryVTable; | |||
There was a problem hiding this comment.
Aside: feels weird that QueryVTable isn't obtainable via rustc_middle::query::plumbing.
There was a problem hiding this comment.
You mean it not being re-exported from rustc_middle::query? Yeah, we should fix that at some point.
| mode: QueryMode, | ||
| ) -> Option<Erased<queries::$name::Value<'tcx>>> { | ||
| #[cfg(debug_assertions)] | ||
| let _guard = tracing::span!(tracing::Level::TRACE, stringify!($name), ?key).entered(); |
There was a problem hiding this comment.
Aside: I wonder if this is necessary. The non-incr function doesn't have it.
|
|
||
| pub(crate) mod execute_query_incr { | ||
| use super::*; | ||
| use rustc_middle::queries::$name::{Key, Value}; |
There was a problem hiding this comment.
You import Key and Value multiple times, but don't import Cache. Can the repeated imports be avoided by importing once at the top of mod $name, next to where you import Erased?
There was a problem hiding this comment.
To me, the important thing about these local imports is that they're local, being physically quite close to the code that relies on them.
We could import more things into mod $name, but I think that would make it harder to mentally resolve imports, which is a big concern in macro-generated code.
If anything, I'm tempted to duplicate the import of erase/Erased into more local imports, closer to the places that use them.
There was a problem hiding this comment.
Actually, I realised that I can hoist the imports of erase/Erased out to the top of the module, so they're no longer in macros at all.
| description_fn: $crate::queries::_description_fns::$name, | ||
| execute_query_fn: if incremental { | ||
| query_impl::$name::execute_query_incr::__rust_end_short_backtrace | ||
| crate::query_impl::$name::execute_query_incr::__rust_end_short_backtrace |
There was a problem hiding this comment.
crate::query_impl::$name can be shortened to just $name, I think? Here and a few cases below.
There was a problem hiding this comment.
I think it happens to work because of the use super::*; import, but generally I'd prefer not to see $name outside of a fully-qualified path (or stringify!).
In the context of a macro, it's so much easier to know how $name is being used if you can see the fully-qualified path directly in the source code.
In the case of I'm pretty confident that we don't want to move the big plumbing macro into the same source file as the list of query declarations; that would be far worse than any inconsistency between rustc_middle and rustc_query_impl. The expansion of the big rustc_middle macro also really wants to have access to the plain imports in Currently I can think of two plausible resolutions:
|
0393d81 to
40d3a55
Compare
There was a problem hiding this comment.
r=me but I will wait until #153707 merges before approving this because the two PRs will conflict.
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.
|
Invalid command: Invalid delegation type |
Moving the macro and its expansion into the same physical file resolves a lot of tension in the current module arrangement. Code in the macro is now free to use plain imports in the same file, and there is no longer any question of whether `mod query_impl` should be declared inside the macro, or surrounding a separate expansion site.
|
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. |
|
I rebased, but I'm going to spend some extra time checking that I didn't accidentally break anything subtle. |
|
I used @bors r=nnethercote |
This comment was marked as resolved.
This comment was marked as resolved.
|
@bors r=nnethercote |
Move and expand the big `rustc_query_impl` macro into a physical `query_impl.rs` While looking through rust-lang#153588, I came up with a related but different change that I think resolves a lot of tension in the current module arrangement. The core idea is that if we both define and expand the big macro in the same physical module `rustc_query_impl::query_impl`, then we no longer need to worry about where `mod query_impl` should be declared, or where its imports should go, because those questions now have simple and obvious answers. The second commit follows up with some more changes inspired by rust-lang#153588. Those particular follow-ups are not essential to the main idea of this PR. r? nnethercote
Rollup of 7 pull requests Successful merges: - #152621 (LinkedGraph: support adding nodes and edges in arbitrary order) - #153376 (Replace `visit_waiters` with `abstracted_waiters_of`) - #153760 (Move and expand the big `rustc_query_impl` macro into a physical `query_impl.rs`) - #153818 (Reimplement const closures) - #153774 (Fix std doctest build for SGX target.) - #153786 (Remove `value_from_cycle_error` specializations) - #153819 (delete some duplicated tests)
Rollup of 7 pull requests Successful merges: - #152621 (LinkedGraph: support adding nodes and edges in arbitrary order) - #153376 (Replace `visit_waiters` with `abstracted_waiters_of`) - #153760 (Move and expand the big `rustc_query_impl` macro into a physical `query_impl.rs`) - #153818 (Reimplement const closures) - #153774 (Fix std doctest build for SGX target.) - #153786 (Remove `value_from_cycle_error` specializations) - #153819 (delete some duplicated tests)
While looking through #153588, I came up with a related but different change that I think resolves a lot of tension in the current module arrangement.
The core idea is that if we both define and expand the big macro in the same physical module
rustc_query_impl::query_impl, then we no longer need to worry about wheremod query_implshould be declared, or where its imports should go, because those questions now have simple and obvious answers.The second commit follows up with some more changes inspired by #153588. Those particular follow-ups are not essential to the main idea of this PR.
r? nnethercote