Skip to content

completely deduplicate Visitor and MutVisitor #142706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

fee1-dead
Copy link
Member

@fee1-dead fee1-dead commented Jun 19, 2025

r? oli-obk

This closes #127615.

Discussion

  • Give every MutVisitor::visit_* method a corresponding flat_map_* method.

Not every AST node exists in a location where they can be mapped to multiple instances of themselves. Not every AST node exists in a location where they can be removed from existence (e.g. filter_map_expr). I don't think this is doable.

  • Give every MutVisitor::visit_* method a corresponding Visitor method and vice versa

The only three remaining method-level asymmetries after this PR are visit_stmt and visit_nested_use_tree (only on Visitor) and visit_span (only on MutVisitor).

visit_stmt doesn't seem applicable to MutVisitor because walk_flat_map_stmt_kind will ask flat_map_item / filter_map_expr to potentially turn a single Stmt to multiple based on what a visitor wants. So only using flat_map_stmt seems appropriate.

visit_nested_use_tree is used for rustc_resolve to track stuff. Not useful for MutVisitor for now.

visit_span is currently not used for MutVisitor already, it was just kept in case we want to revive #127241. cc @cjgillot maybe we could remove for now and re-insert later if we find a use-case? It does involve some extra effort to maintain.

  • Remaining FIXMEs

visit_lifetime has an extra param for Visitor that's not in MutVisitor. This is again something only used by rustc_resolve. I think we can keep that symmetry for now.

just using `walk_item` instead would be okay.
@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 Jun 19, 2025
@fee1-dead fee1-dead force-pushed the push-zsznlqyrzsqo branch from 68ac46d to e59533d Compare June 19, 2025 07:22
@fee1-dead fee1-dead marked this pull request as draft June 19, 2025 07:25
@fee1-dead fee1-dead marked this pull request as ready for review June 19, 2025 07:30
@fee1-dead fee1-dead force-pushed the push-zsznlqyrzsqo branch from e59533d to ed397ad Compare June 19, 2025 07:32
@fee1-dead
Copy link
Member Author

@bors2 try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Jun 19, 2025

⌛ Trying commit ed397ad with merge a1b90e8

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request Jun 19, 2025
completely deduplicate `Visitor` and `MutVisitor`

r? oli-obk

This closes #127615.

### Discussion

> * Give every `MutVisitor::visit_*` method a corresponding `flat_map_*` method.

Not every AST node exists in a location where they can be mapped to multiple instances of themselves. Not every AST node exists in a location where they can be removed from existence (e.g. `filter_map_expr`). I don't think this is doable.

> * Give every `MutVisitor::visit_*` method a corresponding `Visitor` method and vice versa

The only three remaining method-level asymmetries after this PR are `visit_stmt` and `visit_nested_use_tree` (only on `Visitor`) and `visit_span` (only on `MutVisitor`).

`visit_stmt` doesn't seem applicable to `MutVisitor` because `walk_flat_map_stmt_kind` will ask `flat_map_item` / `filter_map_expr` to potentially turn a single `Stmt` to multiple based on what a visitor wants. So only using `flat_map_stmt` seems appropriate.

`visit_nested_use_tree` is used for `rustc_resolve` to track stuff. Not useful for `MutVisitor` for now.

`visit_span` is currently not used for `MutVisitor` already, it was just kept in case we want to revive #127241. cc `@cjgillot` maybe we could remove for now and re-insert later if we find a use-case? It does involve some extra effort to maintain.

* Remaining FIXMEs

`visit_lifetime` has an extra param for `Visitor` that's not in `MutVisitor`. This is again something only used by `rustc_resolve`. I think we can keep that symmetry for now.
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 19, 2025
@rust-log-analyzer

This comment has been minimized.

@fee1-dead fee1-dead force-pushed the push-zsznlqyrzsqo branch from ed397ad to 3da58e6 Compare June 19, 2025 09:50
@rust-bors
Copy link

rust-bors bot commented Jun 19, 2025

☀️ Try build successful (CI)
Build commit: a1b90e8 (a1b90e8b552cbb8c94842e1b04cb49b07d4b9475, parent: 8a65ee08296b36342bf7c3cdc15312ccbc357227)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (a1b90e8): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking 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
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary 0.9%, secondary -3.0%)

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

mean range count
Regressions ❌
(primary)
0.9% [0.9%, 0.9%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.0% [-5.7%, -1.2%] 4
All ❌✅ (primary) 0.9% [0.9%, 0.9%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 692.997s -> 691.913s (-0.16%)
Artifact size: 372.00 MiB -> 372.02 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 20, 2025
@oli-obk
Copy link
Contributor

oli-obk commented Jun 20, 2025

Not every AST node exists in a location where they can be mapped to multiple instances of themselves. Not every AST node exists in a location where they can be removed from existence (e.g. filter_map_expr). I don't think this is doable.

yea that makes sense. The scheme you have now that generates the flat map functions and similar resolves that point sufficiently imo

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 20, 2025

📌 Commit 3da58e6 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors 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 Jun 20, 2025
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.

ast::mut_visit::MutVisitor and ast::visit::Visitor do not have corresponding methods for all their methods
6 participants