-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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 schemeGive everyMutVisitor::visit_*
method a correspondingflat_map_*
method. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate.- we can make it so implementors can override either
visit_foo
orflat_map_foo
without there being problems. Thewalk_bar
functions 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_foo
will 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
To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.(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 everyMutVisitor::visit_*
method a correspondingVisitor
method and vice versa E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Create a macro that generates both visitors, including thewalk_
functions in one go, just like with the MIR visitors E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Previous work
- Make ast
MutVisitor
have the same method name and style asVisitor
#127524 - introduce common macro for
MutVisitor
andVisitor
to dedup code #141249 - remove
visit_clobber
and moveDummyAstNode
torustc_expand
#141430 - remove
visit_mt
fromast::mut_visit
#141632 - further dedup
WalkItemKind
formut_visit
andvisit
#141635 - avoid some usages of
&mut P<T>
in AST visitors #141636 - Add
visit_id
to 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_expr
etc methods #142371 - completely deduplicate
Visitor
andMutVisitor
#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.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
MutVisitor
have the same method name and style asVisitor
#127524Auto merge of rust-lang#127524 - oli-obk:feed_item_attrs2, r=<try>
Auto merge of rust-lang#127524 - oli-obk:feed_item_attrs2, r=<try>
Auto merge of rust-lang#127524 - oli-obk:feed_item_attrs2, r=petroche…
Auto merge of rust-lang#127524 - oli-obk:feed_item_attrs2, r=petroche…
Auto merge of #127524 - oli-obk:feed_item_attrs2, r=petrochenkov
Auto merge of #127524 - oli-obk:feed_item_attrs2, r=petrochenkov
GrigorenkoPV commentedon Jul 26, 2024
Visitor::visit_*
angle_bracketed_parameter_data
coroutine_kind
fn_decl
foreign_mod
id
macro_def
meta_item
meta_list_item
mt
parenthesized_parameter_data
qself
span
where_clause
MutVisitor::visit_*
arm
assoc_item
enum_def
expr_field
expr_post
field_def
fn_ret_ty
foreign_item
generic_param
item
mac_def
param
pat_field
stmt
variant
variant_discr
All of these should be added, correct?
oli-obk commentedon Jul 26, 2024
For the ones that only exist in Visitor but not in MutVisitor, it may be useful to see if anyone actually overrides these and potentially entirely remove them.
For the ones that only exist in MutVisitor but not Visitor, there are some that don't really make sense for Visitor, like the one for ids or the one for spans. There won't be any immutable visitors that just want to see all spans I think. So it seems ok to have such differences for leaf functions (where the Walker is a noop)
oli-obk commentedon Jul 26, 2024
Also sometimes MutVisitor has things like ItemKind visiting, but not Item...
Looks like my idea was a bit naive. We basically need to analyze every missing method and see if there isn't one almost like it and if it can reasonably be refactored or if the mut visitor is just too different because of the mutation
47 remaining items