Skip to content

ast::mut_visit::MutVisitor and ast::visit::Visitor do not have corresponding methods for all their methods #127615

Open
@oli-obk

Description

@oli-obk

In contrast to the MIR mut and immut visitors

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_* vs walk_* naming scheme
  • Give every MutVisitor::visit_* method a corresponding flat_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 or flat_map_foo without there being problems. The walk_bar functions must invoke flat_map_foo, so that they can pick up on more/fewer items being produced. So walk_flat_map_foo (which only ever maps to a single output element) needs to invoke visit_foo, not walk_foo. Otherwise overriding visit_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
  • (Optional): move all the walk_ functions to defaulted methods on the trait (not sure this should be done, discuss on zulip first!) discussed, should not be done
  • Give every MutVisitor::visit_* method a corresponding Visitor 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 the walk_ functions in one go, just like with the MIR visitors E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.

Previous work

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-astArea: ASTA-technical-debtArea: Internal cleanup workC-cleanupCategory: PRs that clean code up or issues documenting cleanup.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions