Skip to content

Clean up AST visitor some more - #162315

Open
nnethercote wants to merge 10 commits into
rust-lang:mainfrom
nnethercote:clean-up-AST-visitor-some-more
Open

Clean up AST visitor some more#162315
nnethercote wants to merge 10 commits into
rust-lang:mainfrom
nnethercote:clean-up-AST-visitor-some-more

Conversation

@nnethercote

@nnethercote nnethercote commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

View all comments

A sequel to #162226. Details in individual commits.

r? @fee1-dead

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 4, 2026
@nnethercote

Copy link
Copy Markdown
Contributor Author

LLM disclosure: most of these clean-ups were suggested by an LLM. I made all the code and text changes myself.

@nnethercote

Copy link
Copy Markdown
Contributor Author

Shouldn't affect perf, but just in case:

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 4, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 4, 2026
@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 5, 2026
@rust-bors

rust-bors Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

💥 Test timed out after 21600s

@nnethercote

Copy link
Copy Markdown
Contributor Author

💥 Test timed out after 21600s

Not sure what happened. Let's try again:

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 5, 2026
@rust-bors

rust-bors Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: d804d79 (d804d7975d767ccd03c93b9f34541ae4bc41c8ee)
Base parent: 0ed41eb (0ed41eb4142dda2df61eb1145a312c1a9d62eb56)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

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 @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never rustc-perf
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.2% [0.2%, 0.3%] 7
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.1%] 2
All ❌✅ (primary) 0.2% [0.2%, 0.3%] 7

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.

mean range count
Regressions ❌
(primary)
7.7% [7.7%, 7.7%] 1
Regressions ❌
(secondary)
6.8% [6.8%, 6.8%] 1
Improvements ✅
(primary)
-3.3% [-3.3%, -3.3%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.2% [-3.3%, 7.7%] 2

Cycles

Results (secondary -2.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.0% [-2.0%, -2.0%] 1
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 476.718s -> 480.953s (0.89%)
Artifact size: 403.29 MiB -> 403.40 MiB (0.03%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Sep 5, 2026
@nnethercote
nnethercote marked this pull request as draft September 5, 2026 13:16
@nnethercote

Copy link
Copy Markdown
Contributor Author

Slight regressions on html5ever. I'll investigate on Monday.

@rust-bors

This comment has been minimized.

`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.
@nnethercote
nnethercote force-pushed the clean-up-AST-visitor-some-more branch from f9e5acf to ad3c224 Compare September 6, 2026 23:34
@nnethercote

Copy link
Copy Markdown
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 6, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 6, 2026
@rust-bors

rust-bors Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: e8a15ce (e8a15ced131dd3a6ecc5fe12dbe908486488c1f2)
Base parent: 5a2be9f (5a2be9f5f075d31e3ca5526b5b029881ce441253)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (e8a15ce): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This perf run didn't have relevant results for this metric.

Max RSS (memory usage)

Results (primary 4.9%, secondary 4.9%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
4.9% [2.7%, 7.1%] 2
Regressions ❌
(secondary)
4.9% [4.9%, 5.0%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 4.9% [2.7%, 7.1%] 2

Cycles

Results (secondary 0.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
4.7% [4.7%, 4.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.6% [-3.6%, -3.6%] 1
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 476.006s -> 480.221s (0.89%)
Artifact size: 403.41 MiB -> 403.49 MiB (0.02%)

@rustbot rustbot removed perf-regression Performance regression. S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Sep 7, 2026
@nnethercote
nnethercote marked this pull request as ready for review September 7, 2026 04:00
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 7, 2026
@nnethercote

Copy link
Copy Markdown
Contributor Author

Regressions fixed with a bit of #[inline]. Ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants