Make rustc_with_all_queries! pass query modifiers as named values#153326
Make rustc_with_all_queries! pass query modifiers as named values#153326Zalathar wants to merge 1 commit intorust-lang:mainfrom
rustc_with_all_queries! pass query modifiers as named values#153326Conversation
|
The named-modifier style is based on a suggestion from @Zoxc. |
|
I don't anticipate perf effects, but for something like this it's good to check. @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Make `rustc_with_all_queries!` pass query modifiers as named values
|
At first I wasn't sure whether the named-values approach was worthwhile, but it was the ability to start using |
Who got it from Claude Opus! |
| $is_anon, | ||
| $is_cache_on_disk, | ||
| $is_eval_always, |
There was a problem hiding this comment.
If we change these to use named constants defined by one of the other callback macros, we can remove the modifier-parsing block from dep_kind_vtables.
I currently haven't made that change because I'm not sure whether it's worthwhile.
There was a problem hiding this comment.
Sorry, I don't understand. Can you expand?
There was a problem hiding this comment.
If we make the big macro in rustc_query_impl::plumbing define constants like:
pub(crate) const ANON: bool = $anon;
Then instead of writing $anon here, we would write $crate::query_impl::$name::ANON.
The benefit of doing so would be that the macro in dep_kind_vtables would no longer need to parse the modifier list at all, reducing the number of places that need to be kept in sync with the modifier list syntax.
But that benefit disappears if this code ends up needing to parse the modifier list for other reasons anyway.
|
One of the downsides of |
There was a problem hiding this comment.
I like the approach on the modifier passing. Verbose in places, but simple and explicit. Eliminating all those if_* macros is really nice. A few comments below.
I honestly don't like the first commit. More qualifiers, more use items, more pub(crate) visibilities, and now the query code is spread across two files which makes navigability worse. All just to move ~100 lines out of a ~500 line module. We clearly have different senses of taste on this. (Genuine question: if you introduced the module but as a mod modifiers { ... } within query.rs, does that satisfy you? I'm trying to understand the motivation.) I won't block the PR on this but I will ask you to think twice about whether it's worthwhile.
| pub type ProvidedValue<'tcx> = | ||
| <Value<'tcx> as $crate::query::arena_cached::ArenaCached<'tcx>>::Provided; | ||
| /// Type returned from query providers and loaded from disk-cache. | ||
| #[cfg(not($is_arena_cache))] |
There was a problem hiding this comment.
The duplication of the doc comments and the cfg attribute name is unfortunate, but I don't see how to avoid it.
There was a problem hiding this comment.
I guess the attribute name repetition could be avoided with the cfg_if crate, but it's probably not worth it.
ba86d8a to
bb45c0c
Compare
|
Addressed all of the feedback so far: (diff). |
bb45c0c to
0b96d85
Compare
|
Now I'm second-guessing the return type alias change. (Sorry!) A little bit of duplication might be worth it to avoid the unnecessary args. What do you think? |
|
BTW, the use of tidy-alphabetical to order the modifiers is great. |
I’m not sure which one I ultimately prefer, but right now I’m leaning towards the type alias because it’s closer to the status quo. This PR lays the foundation for some interesting follow-ups, so it’s fine to leave some potential improvements for future work in other PRs. |
0b96d85 to
083b5db
Compare
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (a360f53): comparison URL. Overall result: ❌✅ regressions and improvements - no action neededBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (secondary -2.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -6.7%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 480.002s -> 478.954s (-0.22%) |
| block: Block, | ||
| } | ||
|
|
||
| /// See `rustc_middle::query::modifiers` for documentation of each query modifier. |
There was a problem hiding this comment.
I had been thinking about this very change myself, thanks for doing it.
There was a problem hiding this comment.
Though there is still the comments at the top of compiler/rustc_middle/src/queries.rs.
| [#modifiers_stream] | ||
| fn #name(#key_ty) #return_ty, | ||
| fn #name(#key_ty) #return_ty | ||
| { #modifiers_stream } |
There was a problem hiding this comment.
Was there any particular motivation behind moving the modifiers after the fn signature?
There was a problem hiding this comment.
- It's closer to the actual syntax used in
rustc_middle::queries(and processed by the proc-macro), which is hopefully a bit more intuitive for people who don't know all the horrible details of how these macros work - It puts the signature near the top, which feels a bit more natural when looking at pattern at the pattern at the top of the callback macros
|
@bors r+ |
|
@bors rollup |
…rcote
Make `rustc_with_all_queries!` pass query modifiers as named values
This PR is a bold overhaul of how the proc-macro in `rustc_macros::query` passes query modifiers to the callback macros in `rustc_middle` and `rustc_query_impl`.
The existing approach passes modifiers as a list that looks like `[(arena_cache), (no_hash)]`. That style requires a family of helper macros (`if_arena_cache!`, `if_no_hash!`) to check for modifiers when consuming the query list.
This PR changes the proc-macro to instead pass modifiers like this:
```text
{
anon: false,
arena_cache: true,
cache_on_disk: false,
...
}
```
This style allows each of the callback macros to deconstruct the modifier list in a relatively straightforward way, by binding the true/false literals to variables like `$arena_cache:literal`.
One of the big advantages of this style is that we can write things like `#[cfg($arena_cache)]` and `#[cfg(not($arena_cache))]` to select blocks of code, eliminating the need for the `if_arena_cache!` family of helper macros.
In follow-up PRs, we can also try to take advantage of the new modifier style to pass richer information for some modifiers, such as `desc` or `cache_on_disk_if`. That could potentially make it more reasonable to get rid of the `_description_fns` and `_cache_on_disk_if_fns` modules, as proposed in rust-lang#153065.
r? nnethercote
Maybe using |
In this context, it’s often the case that one of the arms wouldn’t type-check, which is why we need to be able to eliminate it entirely before that happens. But I do agree that avoiding conditional compilation is preferable when reasonably possible. |
…rcote
Make `rustc_with_all_queries!` pass query modifiers as named values
This PR is a bold overhaul of how the proc-macro in `rustc_macros::query` passes query modifiers to the callback macros in `rustc_middle` and `rustc_query_impl`.
The existing approach passes modifiers as a list that looks like `[(arena_cache), (no_hash)]`. That style requires a family of helper macros (`if_arena_cache!`, `if_no_hash!`) to check for modifiers when consuming the query list.
This PR changes the proc-macro to instead pass modifiers like this:
```text
{
anon: false,
arena_cache: true,
cache_on_disk: false,
...
}
```
This style allows each of the callback macros to deconstruct the modifier list in a relatively straightforward way, by binding the true/false literals to variables like `$arena_cache:literal`.
One of the big advantages of this style is that we can write things like `#[cfg($arena_cache)]` and `#[cfg(not($arena_cache))]` to select blocks of code, eliminating the need for the `if_arena_cache!` family of helper macros.
In follow-up PRs, we can also try to take advantage of the new modifier style to pass richer information for some modifiers, such as `desc` or `cache_on_disk_if`. That could potentially make it more reasonable to get rid of the `_description_fns` and `_cache_on_disk_if_fns` modules, as proposed in rust-lang#153065.
r? nnethercote
…rcote
Make `rustc_with_all_queries!` pass query modifiers as named values
This PR is a bold overhaul of how the proc-macro in `rustc_macros::query` passes query modifiers to the callback macros in `rustc_middle` and `rustc_query_impl`.
The existing approach passes modifiers as a list that looks like `[(arena_cache), (no_hash)]`. That style requires a family of helper macros (`if_arena_cache!`, `if_no_hash!`) to check for modifiers when consuming the query list.
This PR changes the proc-macro to instead pass modifiers like this:
```text
{
anon: false,
arena_cache: true,
cache_on_disk: false,
...
}
```
This style allows each of the callback macros to deconstruct the modifier list in a relatively straightforward way, by binding the true/false literals to variables like `$arena_cache:literal`.
One of the big advantages of this style is that we can write things like `#[cfg($arena_cache)]` and `#[cfg(not($arena_cache))]` to select blocks of code, eliminating the need for the `if_arena_cache!` family of helper macros.
In follow-up PRs, we can also try to take advantage of the new modifier style to pass richer information for some modifiers, such as `desc` or `cache_on_disk_if`. That could potentially make it more reasonable to get rid of the `_description_fns` and `_cache_on_disk_if_fns` modules, as proposed in rust-lang#153065.
r? nnethercote
…uwer Rollup of 6 pull requests Successful merges: - #153336 (stdarch subtree update) - #152943 (Parse `impl` restrictions) - #153184 (Replace CodegenResults with CompiledModules) - #153285 (Update call-llvm-intrinsics test for Rust 1.94.0 IR) - #153319 (Comments and docs: add missing periods to "ie.") - #153326 (Make `rustc_with_all_queries!` pass query modifiers as named values)
This PR is a bold overhaul of how the proc-macro in
rustc_macros::querypasses query modifiers to the callback macros inrustc_middleandrustc_query_impl.The existing approach passes modifiers as a list that looks like
[(arena_cache), (no_hash)]. That style requires a family of helper macros (if_arena_cache!,if_no_hash!) to check for modifiers when consuming the query list.This PR changes the proc-macro to instead pass modifiers like this:
This style allows each of the callback macros to deconstruct the modifier list in a relatively straightforward way, by binding the true/false literals to variables like
$arena_cache:literal.One of the big advantages of this style is that we can write things like
#[cfg($arena_cache)]and#[cfg(not($arena_cache))]to select blocks of code, eliminating the need for theif_arena_cache!family of helper macros.In follow-up PRs, we can also try to take advantage of the new modifier style to pass richer information for some modifiers, such as
descorcache_on_disk_if. That could potentially make it more reasonable to get rid of the_description_fnsand_cache_on_disk_if_fnsmodules, as proposed in #153065.r? nnethercote