Clean up AST visitor some more - #162315
Conversation
`visit_test_binder_constraints` is the only `visit_foo` method in `impl_visitable_calling_walkable!` without a corresponding `walk_foo` method in `define_named_walk!`. I confirmed with the original author (khyperia) that this is an unintentional oversight.
There is currently a big list of `visit_*` methods in one macro call and another list of `walk_*` method in another macro call. The previous commit showed these can unintentionally get out of sync. This commit introduces a higher-order macro that puts all the information in a single place. This will make it impossible for the `visit_*` and `walk_*` methods to get out of sync (as we saw in the previous commit). It will also facilitate another cleanup in the next commit.
Currently various `Visitable` impls are defined within functions even though `Visitable` is defined at the top level, which is weird and requires `allow(non_local_definitions)`. This commit uses `for_each_ast_visit_hook` to move them out. It also renames a couple of the existing macros to give them simpler names.
Use `$ty` and `$extra` and `$extra_ty` consistently in macros, rather than `$Ty` and `$ExtraTy` and `$ParamTy`. Also fix some spacing.
They fit the pattern. Also remove `#[inline]` from `impl_visitable_list` for consistency. The visitor is generic so the methods are monomorphized into the calling crate and probably inlined anyway.
The AST visitor code uses `($($extra_ty)?)` which expands to `()` in some cases and `(T)` in others, which requires `allow(unused_parens)` to avoid warnings. This commit splits the two `impl_visitable!` macros into two rules: one for the "no-extra" case and one for the "with-extra" case. There's a small amount of duplication between the two rules but there are multiple advantages. - The `allow(unused_parens)` is removed. - `impl_visitable!` callers can omit the extra param if it's `()`. - When the extra argument might or might not be present, a more standard `$(, $extra: $extra_ty)?` is now used. - No weird `let ($($extra)?) = extra;` destructuring. The `Visitable` derive also gets a tweak to avoid unnecessary parens around extra args.
These macros aren't needed outside the crate.
We can just hardwire `'a` and `Visitor`/`MutVisitor`. This simplifies the inputs for these macros from "leading thing + repeating elements" to just "repeating elements".
A lot of these lists are already almost in alphabetical order.
|
LLM disclosure: most of these clean-ups were suggested by an LLM. I made all the code and text changes myself. |
|
Shouldn't affect perf, but just in case: @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.
…=<try> Clean up AST visitor some more
|
💥 Test timed out after |
Not sure what happened. Let's try again: @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.
…=<try> Clean up AST visitor some more
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (d804d79): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never rustc-perf 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 2.2%, secondary 6.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -2.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 476.718s -> 480.953s (0.89%) |
|
Slight regressions on html5ever. I'll investigate on Monday. |
|
☔ The latest upstream changes (presumably #162310) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
A sequel to #162226. Details in individual commits.
r? @fee1-dead