feat: add mutable visitor trait for traversal of AST#139
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #139 +/- ##
==========================================
- Coverage 98.93% 98.53% -0.41%
==========================================
Files 15 15
Lines 6560 6876 +316
==========================================
+ Hits 6490 6775 +285
- Misses 70 101 +31 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Tried to open the report, but it returns a "400 Bad Request" error when I click on a |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 156c7d09c4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 101c540040
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Partially addresses #137
This PR implements the mutable version of the AST visitor (
ExprVisitorMutandwalk_expr_mut) to allow in-place mutations of the AST.To support mutating extension nodes, I added
children_mut()to theExtensionExprtrait. Because the extension holds the inner expression in anArc<dyn ExtensionExpr>,walk_expr_mutattempts to unwrap it usingArc::get_mut. Currently, ifArc::get_mutfails (meaning there are multiple references to the sharedArc), the walker falls back to treating the extension as a leaf node and skips traversing its children.I'm not entirely sure if this fallback behavior is the most reasonable approach. I would love to hear your thoughts on whether we should keep it this way, or perhaps delegate the decision to the visitor itself (e.g., by adding an optional
visit_shared_extensionmethod to theExprVisitorMuttrait so implementers can choose whether to skip, halt, or throw a custom error).As discussed in the issue, I implemented this manually without using macros for now. I realized it would be more complicated than expected to use a macro to deduplicate the code, since
Expr::Extensionmust be handled differently depending on whether it is immutable or mutable.