Skip to content

feat: add mutable visitor trait for traversal of AST#139

Merged
sunng87 merged 4 commits into
GreptimeTeam:mainfrom
scintillavoy:add-mutable-visitor
Apr 16, 2026
Merged

feat: add mutable visitor trait for traversal of AST#139
sunng87 merged 4 commits into
GreptimeTeam:mainfrom
scintillavoy:add-mutable-visitor

Conversation

@scintillavoy
Copy link
Copy Markdown
Contributor

Partially addresses #137

This PR implements the mutable version of the AST visitor (ExprVisitorMut and walk_expr_mut) to allow in-place mutations of the AST.

To support mutating extension nodes, I added children_mut() to the ExtensionExpr trait. Because the extension holds the inner expression in an Arc<dyn ExtensionExpr>, walk_expr_mut attempts to unwrap it using Arc::get_mut. Currently, if Arc::get_mut fails (meaning there are multiple references to the shared Arc), 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_extension method to the ExprVisitorMut trait 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::Extension must be handled differently depending on whether it is immutable or mutable.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 6, 2026

Codecov Report

❌ Patch coverage is 83.69565% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.53%. Comparing base (c4bebc8) to head (58a425e).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/util/visitor.rs 83.69% 30 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@scintillavoy
Copy link
Copy Markdown
Contributor Author

❌ Patch coverage is 80.95238% with 32 lines in your changes missing coverage. Please review.

Tried to open the report, but it returns a "400 Bad Request" error when I click on a src/util/visitor.rs file to see the exact missed lines.

@evenyag
Copy link
Copy Markdown
Contributor

evenyag commented Apr 8, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/util/visitor.rs Outdated
Comment thread src/util/visitor.rs Outdated
@evenyag
Copy link
Copy Markdown
Contributor

evenyag commented Apr 10, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/util/visitor.rs
@evenyag evenyag requested a review from sunng87 April 13, 2026 02:42
Copy link
Copy Markdown
Contributor

@evenyag evenyag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread src/util/visitor.rs
@sunng87 sunng87 merged commit e692489 into GreptimeTeam:main Apr 16, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants