Introduce for_each_query_vtable! to move more code out of query macros#153685
Introduce for_each_query_vtable! to move more code out of query macros#153685rust-bors[bot] merged 2 commits intorust-lang:mainfrom
for_each_query_vtable! to move more code out of query macros#153685Conversation
|
|
I don't expect any perf difference, but I'm curious to see if there's a measurable difference in bootstrap time. (Though I think that even an extra 1-2 seconds would still be worth the cost, if it came to that.) @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.
Introduce `for_each_query_vtable!` to move more code out of query macros
dcad3d3 to
82f9877
Compare
|
I have an item on my todo list to rename all these functions. Currently we have an inconsistent mess:
I'm considering these:
They are long, but each one is only used a small number of times, and I think they score high for consistency and clarity. Shorter alternatives all seemed worse. What do you think? |
|
(The function renaming would be a follow-up to this PR, of course.) |
7d69ab2 to
50d4b2d
Compare
This comment has been minimized.
This comment has been minimized.
Seems pretty reasonable. Also note that if we're moving in the direction of referring to query return values as “values” instead of ”results”, then that should probably be |
I considered a few different variations of how to indicate the filter condition, and having one macro with multiple arms and |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (45cd205): comparison URL. Overall result: ❌ regressions - 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 (primary -0.2%, secondary -1.9%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 1.5%)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: 479.93s -> 483.213s (0.68%) |
|
Hmm, +3.3s for bootstrap, I wonder if that's real. |
|
Based on some local measurements, I think the bootstrap-time regression is real, though the full 3.3 seconds is probably exaggerated. I have an alternate version that expands into N calls to a single named inner function, instead of N calls to N duplicated closures. I'll push that as a separate commit, to see what you think of the different tradeoffs. |
|
Let’s see what perf has to say about the function-call version. @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.
Introduce `for_each_query_vtable!` to move more code out of query macros
|
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. |
a7528b0 to
d066ff7
Compare
|
@bors r+ |
d066ff7 to
9de761b
Compare
|
This pull request was unapproved. |
|
I'll just revert back to the approved version and reapprove. |
9de761b to
d066ff7
Compare
|
To keep things simple, I reverted back to the previously-approved revision. (No perf changes, and the bootstrap timing change is tiny.) @bors r=nnethercote rollup=maybe |
…cote Introduce `for_each_query_vtable!` to move more code out of query macros After rust-lang#153114 moved a few for-each-query functions into the big `rustc_query_impl::plumbing` macro, I have found that those functions became much harder to navigate and modify, because they no longer have access to ordinary IDE features in rust-analyzer. Even *finding* the functions is considerably harder, because a plain go-to-definition no longer works smoothly. This PR therefore tries to move as much of that code back out of the macro as possible, with the aid of a smaller `for_each_query_vtable!` helper macro. A typical use of that macro looks like this: ```rust for_each_query_vtable!(ALL, tcx, |query| { query_key_hash_verify(query, tcx); }); ``` The result is an outer function consisting almost entirely of plain Rust code, with all of the usual IDE affordances expected of normal Rust code. Because it uses plain Rust syntax, it can also be formatted automatically by rustfmt. Adding another layer of macro-defined macros is not something I propose lightly, but in this case I think the improvement is well worth it: - The outer functions can once again be defined as “normal” Rust functions, right next to their corresponding inner functions, making navigation and modification much easier. - The closure expression is ordinary Rust code that simply gets repeated ~300 times in the expansion, once for each query, in order to account for the variety of key/value/cache types used by different queries. Even within the closure expression, IDE features still *mostly* work, which is an improvement over the status quo. - For future maintainers looking at the call site, the macro's effect should hopefully be pretty obvious and intuitive, reducing the need to even look at the helper macro. And the helper macro itself is largely straightforward, with its biggest complication being that it necessarily uses the `$name` metavar from the outer macro. There should be no change to compiler behaviour. r? nnethercote (or compiler)
…cote Introduce `for_each_query_vtable!` to move more code out of query macros After rust-lang#153114 moved a few for-each-query functions into the big `rustc_query_impl::plumbing` macro, I have found that those functions became much harder to navigate and modify, because they no longer have access to ordinary IDE features in rust-analyzer. Even *finding* the functions is considerably harder, because a plain go-to-definition no longer works smoothly. This PR therefore tries to move as much of that code back out of the macro as possible, with the aid of a smaller `for_each_query_vtable!` helper macro. A typical use of that macro looks like this: ```rust for_each_query_vtable!(ALL, tcx, |query| { query_key_hash_verify(query, tcx); }); ``` The result is an outer function consisting almost entirely of plain Rust code, with all of the usual IDE affordances expected of normal Rust code. Because it uses plain Rust syntax, it can also be formatted automatically by rustfmt. Adding another layer of macro-defined macros is not something I propose lightly, but in this case I think the improvement is well worth it: - The outer functions can once again be defined as “normal” Rust functions, right next to their corresponding inner functions, making navigation and modification much easier. - The closure expression is ordinary Rust code that simply gets repeated ~300 times in the expansion, once for each query, in order to account for the variety of key/value/cache types used by different queries. Even within the closure expression, IDE features still *mostly* work, which is an improvement over the status quo. - For future maintainers looking at the call site, the macro's effect should hopefully be pretty obvious and intuitive, reducing the need to even look at the helper macro. And the helper macro itself is largely straightforward, with its biggest complication being that it necessarily uses the `$name` metavar from the outer macro. There should be no change to compiler behaviour. r? nnethercote (or compiler)
…uwer Rollup of 9 pull requests Successful merges: - #153571 (Avoid ICE when an EII declaration conflicts with a constructor) - #153581 (Simplify `type_of_opaque`.) - #153611 (interpret: go back to regular string interpolation for error messages) - #153635 (Unify same-span labels in move error diagnostics) - #153660 (mir-opt: Drop invalid debuginfos after SingleUseConsts.) - #153685 (Introduce `for_each_query_vtable!` to move more code out of query macros) - #153671 (Make Enzyme has dependent on LLVM hash) - #153710 (remove `.ftl` checks from tidy) - #153720 (doc/rustc: clarify how to contact arm-maintainers)
…uwer Rollup of 9 pull requests Successful merges: - #153571 (Avoid ICE when an EII declaration conflicts with a constructor) - #153581 (Simplify `type_of_opaque`.) - #153611 (interpret: go back to regular string interpolation for error messages) - #153635 (Unify same-span labels in move error diagnostics) - #153660 (mir-opt: Drop invalid debuginfos after SingleUseConsts.) - #153685 (Introduce `for_each_query_vtable!` to move more code out of query macros) - #153671 (Make Enzyme has dependent on LLVM hash) - #153710 (remove `.ftl` checks from tidy) - #153720 (doc/rustc: clarify how to contact arm-maintainers)
…uwer Rollup of 9 pull requests Successful merges: - #153571 (Avoid ICE when an EII declaration conflicts with a constructor) - #153581 (Simplify `type_of_opaque`.) - #153611 (interpret: go back to regular string interpolation for error messages) - #153635 (Unify same-span labels in move error diagnostics) - #153660 (mir-opt: Drop invalid debuginfos after SingleUseConsts.) - #153685 (Introduce `for_each_query_vtable!` to move more code out of query macros) - #153671 (Make Enzyme has dependent on LLVM hash) - #153710 (remove `.ftl` checks from tidy) - #153720 (doc/rustc: clarify how to contact arm-maintainers)
…uwer Rollup of 12 pull requests Successful merges: - #152569 (Stop using rustc_layout_scalar_valid_range_* in rustc) - #153421 (Fix ICE in fn_delegation when child segment resolves to a trait) - #153571 (Avoid ICE when an EII declaration conflicts with a constructor) - #153581 (Simplify `type_of_opaque`.) - #153611 (interpret: go back to regular string interpolation for error messages) - #153635 (Unify same-span labels in move error diagnostics) - #153660 (mir-opt: Drop invalid debuginfos after SingleUseConsts.) - #153685 (Introduce `for_each_query_vtable!` to move more code out of query macros) - #153722 (miri-test-libstd: use --tests and update some comments) - #153671 (Make Enzyme has dependent on LLVM hash) - #153710 (remove `.ftl` checks from tidy) - #153720 (doc/rustc: clarify how to contact arm-maintainers)
View all comments
After #153114 moved a few for-each-query functions into the big
rustc_query_impl::plumbingmacro, I have found that those functions became much harder to navigate and modify, because they no longer have access to ordinary IDE features in rust-analyzer. Even finding the functions is considerably harder, because a plain go-to-definition no longer works smoothly.This PR therefore tries to move as much of that code back out of the macro as possible, with the aid of a smaller
for_each_query_vtable!helper macro. A typical use of that macro looks like this:The result is an outer function consisting almost entirely of plain Rust code, with all of the usual IDE affordances expected of normal Rust code. Because it uses plain Rust syntax, it can also be formatted automatically by rustfmt.
Adding another layer of macro-defined macros is not something I propose lightly, but in this case I think the improvement is well worth it:
$namemetavar from the outer macro.There should be no change to compiler behaviour.
r? nnethercote (or compiler)