Skip to content

Clean up AST visitor some more - #162315

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

Clean up AST visitor some more#162315
nnethercote wants to merge 11 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.

@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
@rustbot

rustbot commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

`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.
As requested by the reviewer.
@nnethercote
nnethercote force-pushed the clean-up-AST-visitor-some-more branch from ad3c224 to 44aee39 Compare September 13, 2026 23:41
@rustbot

rustbot commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

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.

@nnethercote

Copy link
Copy Markdown
Contributor Author

I addressed the nit.

@bors r=fee1-dead

@rust-bors

rust-bors Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 44aee39 has been approved by fee1-dead

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 13, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 14, 2026
…=fee1-dead

Clean up AST visitor some more



A sequel to #162226. Details in individual commits.

r? @fee1-dead
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job dist-x86_64-msvc failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@rust-bors rust-bors Bot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 14, 2026
@rust-bors

rust-bors Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

💔 Test for dd3ef79 failed: CI. Failed job:

@jieyouxu

jieyouxu commented Sep 14, 2026

Copy link
Copy Markdown
Member

The hosted runner lost communication with the server. Anything in your workflow that terminates the runner process, starves it for CPU/Memory, or blocks its network access can cause this error.

@jieyouxu

Copy link
Copy Markdown
Member

@bors retry

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 14, 2026
@rust-bors

rust-bors Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

⌛ Testing commit 44aee39 with merge ed77b7b...

Workflow: https://github.com/rust-lang/rust/actions/runs/34817933731

rust-bors Bot pushed a commit that referenced this pull request Sep 14, 2026
…=fee1-dead

Clean up AST visitor some more



A sequel to #162226. Details in individual commits.

r? @fee1-dead
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

6 participants