Skip to content

Commit 7b3c175

Browse files
committed
Auto merge of #143897 - cjgillot:derive-walk, r=petrochenkov
Implement AST visitors using a derive macro. AST visitors are large and error-prone beasts. This PR attempts to write them using a derive macro. The design uses three traits: `Visitor`, `Visitable`, `Walkable`. - `Visitor` is the trait implemented by downstream crates, it lists `visit_stuff` methods, which call `Walkable::walk_ref` by default; - `Walkable` is derived using the macro, the generated `walk_ref` method calls `Visitable::visit` on each component; - `Visitable` is implemented by `common_visitor_and_walkers` macro, to call the proper `Visitor::visit_stuff` method if it exists, to call `Walkable::walk_ref` if there is none. I agree this is quite a lot of spaghetti macros. I'm open to suggestions on how to reduce the amount of boilerplate code. If this PR is accepted, I believe the same design can be used for the HIR visitor.
2 parents 27cbf0e + 41172f9 commit 7b3c175

File tree

0 file changed

+0
-0
lines changed

    0 file changed

    +0
    -0
    lines changed

    0 commit comments

    Comments
     (0)