-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Labels
A-ASTArea: ASTArea: ASTA-technical-debtArea: Internal cleanup workArea: Internal cleanup workC-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
In contrast to the MIR mut and immut visitors
rust/compiler/rustc_middle/src/mir/visit.rs
Lines 1235 to 1236 in c92a8e4
| make_mir_visitor!(Visitor,); | |
| make_mir_visitor!(MutVisitor, mut); |
which are generated from a single macro, and are thus exactly the same except for mutation, the ast visitors are each handwritten. Their method naming scheme doesn't even match up, so changing from a Visitor to a MutVisitor requires extensive changes.
Work items
- Adjust names so everything has the
visit_*vswalk_*naming scheme - Give every
MutVisitor::visit_*method a correspondingflat_map_*method. E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate. - we can make it so implementors can override either
visit_fooorflat_map_foowithout there being problems. Thewalk_barfunctions must invokeflat_map_foo, so that they can pick up on more/fewer items being produced. Sowalk_flat_map_foo(which only ever maps to a single output element) needs to invokevisit_foo, notwalk_foo. Otherwise overridingvisit_foowill do nothing. - This should be using macros similar to what [WIP] Try optimizing noop AST mut visiting #127371 did, so you don't repeat yourself
- we can make it so implementors can override either
-
(Optional): move all thediscussed, should not be donewalk_functions to defaulted methods on the trait (not sure this should be done, discuss on zulip first!) - Give every
MutVisitor::visit_*method a correspondingVisitormethod and vice versa E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. - Create a macro that generates both visitors, including the
walk_functions in one go, just like with the MIR visitors E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.
Previous work
- Make ast
MutVisitorhave the same method name and style asVisitor#127524 - introduce common macro for
MutVisitorandVisitorto dedup code #141249 - remove
visit_clobberand moveDummyAstNodetorustc_expand#141430 - remove
visit_mtfromast::mut_visit#141632 - further dedup
WalkItemKindformut_visitandvisit#141635 - avoid some usages of
&mut P<T>in AST visitors #141636 - Add
visit_idto astVisitor#141843 - duduplicate more AST visitor methods #142086
- deduplicate the rest of AST walker functions #142240
- early linting: avoid redundant calls to
check_id#142398 - avoid
&mut P<T>invisit_expretc methods #142371 - completely deduplicate
VisitorandMutVisitor#142706
Metadata
Metadata
Assignees
Labels
A-ASTArea: ASTArea: ASTA-technical-debtArea: Internal cleanup workArea: Internal cleanup workC-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.