Enhanced Visitor Pattern with Lifecycle Hooks and Composition #9984
magic-akari
started this conversation in
RFC
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
This RFC proposes a redesigned Visitor pattern with composable
enter
/exit
hooks.Key changes include:
enter_node
/exit_node
/enter_mut_node
/exit_mut_node
in a single traitMotivation
Design Details
enter
andexit
methods for visiting elements. This will help us compose Visitors by exposing methods in child Visitors and invoking them through parent Visitors to achieve composition.enter
/exit
and mutableenter
/exit
. Immutable hooks should be used for information collection, while mutable hooks handle AST modifications.enter
/exit` handlers, we should generally avoid skipping child nodes. Performance-driven skips can be deprecated, but correctness-critical skips require explicit handling.Lifecycle Hooks
Visitor Composition Example
Appendix: State Management Example
Before:
After (TBD):
Beta Was this translation helpful? Give feedback.
All reactions