Skip to content

refactor(checker): collapse the six collect.rs AST walkers into one - #148

Merged
sims1253 merged 7 commits into
mainfrom
refactor/collect-ast-walks
Sep 1, 2026
Merged

sims1253 merged 7 commits into
mainfrom
refactor/collect-ast-walks

Conversation

@sims1253

@sims1253 sims1253 commented Aug 31, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • collect.rs carried six recursive AST walk families that differed only in a one-line leaf test: stmt_captures_all_arguments / expr_captures_all_arguments, stmt_quotes_parameter / expr_quotes_parameter, stmt_captures_promise_parameter / expr_captures_promise_parameter, and bquote_references_parameter.
  • One generic walker pair now carries the traversal: stmt_any takes a predicate, expr_any applies it at every expression node. Each family reduces to its predicate plus one call.
  • 253 lines of walkers became 96 lines of walker plus predicates.
  • Stacked on chore(checker): delete dead state, dedupe closure loop, share the test fixpoint #142 and merges after it.

Changes

  • Add stmt_any / expr_any in crates/ry-checker/src/collect.rs. The predicate runs at each expression node; the traversal recurses into compound statements, callees, and arguments. Stmt::FunctionDef and Expr::Function stay opaque, as before.
  • Re-express the families as four leaf predicates: captures_all_arguments (match.call / sys.call), quotes_parameter (substitute, promise-capture helper, bquote template), captures_promise_parameter (promise-capture helper, dots capture), and unquotes_parameter (.(param) inside a bquote template).
  • parameter_is_quoted calls the walker directly with those predicates.
  • Leave the sibling walkers alone. collect_parameter_uses_* accumulate side effects, first_parameter_use_* stop at the first use, block_force_flow tracks fall-through. Different semantics, not the same shape.
  • Second commit fixes one bug the diff surfaced; see below.

Arm-by-arm diff before unification: every Stmt arm and every Expr arm agrees across the families. Only the Expr::Call leaf test differs.

The one disagreement: bquote_references_parameter's Expr::Block arm delegated to stmt_quotes_parameter rather than its own predicate. Decision: bug, fixed in the second commit. The delegation computed the same value the caller's structural recursion already computed, so it decided nothing; a deliberate no-op delegation makes no sense. Meanwhile it skipped the unquote scan, so bquote({ 1 == .(x) }) lost quoting while bquote(list(.(x))) kept it. In R, bquote substitutes .(x) anywhere in the template, braces included. The fix walks braced bodies with the unquote predicate like every other arm. Failing test included: bquote_dot_in_a_braced_body_still_quotes. The first commit preserves the delegation verbatim, so the refactor and the fix are reviewable apart.

Verification

  • cargo fmt -p ry-checker clean.
  • cargo clippy -p ry-checker --all-targets -- -D warnings clean.
  • cargo test -p ry-checker green: 461 lib tests plus corpus snapshots, metamorphic, oracle, and invariants suites. The corpus snapshots pin diagnostics byte-for-byte; both commits passed them, so the refactor is behavior-preserving and the fix changes only the braced-bquote case.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where unquoted expressions inside braced bquote bodies were incorrectly analyzed as eagerly evaluated.
    • Unbound names within expressions such as .(x) are now handled correctly, preventing erroneous RY010 (unbound-variable) diagnostics.
    • Added coverage to ensure quoting behavior remains correct for braced expression bodies.

- Replace Project::prev_return_slots with a has_prev_emit bool; the
  full RType vector was cloned every emit and only tested for presence.
- compute_fixpoint_scope now calls with_transitive_callers instead of
  re-implementing its reverse-caller closure loop.
- The shared test helper check_with_scope delegates to the public
  Checker::check_with_scope instead of replaying collect plus a manual
  fixpoint.
- Drop the unused rationale field from Verdict in rule_evidence.rs;
  code and verdict are the asserted fields.
- Drop the cfg(test) is_package_library_file helper and its single
  assertion, which re-tested ry-workspace classification.
- Rename infer_schema_call's unused span parameter to _span.
- State the current constraint in the filter-builder comment instead
  of the move history.
The six collect.rs walker families (stmt/expr_captures_all_arguments,
stmt/expr_quotes_parameter, stmt/expr_captures_promise_parameter,
bquote_references_parameter) were mutual recursions with one shape and
a different leaf test. Collapse them into one generic pair,
stmt_any/expr_any, plus four leaf predicates.

Arm-by-arm diff before unification: every Stmt arm and every Expr arm
agrees across the families; only the Expr::Call leaf test differs. One
exception, preserved as-is: bquote_references_parameter's Expr::Block
arm delegates to the quotes-parameter statement walk instead of its own
predicate. That delegation computes the same value the caller's own
structural recursion already computes, so keeping it changes nothing.

Siblings left alone: collect_parameter_uses_* accumulate side effects,
first_parameter_use_* stop at the first use, block_force_flow tracks
fall-through. Different semantics, not the same shape.
bquote_references_parameter's Expr::Block arm delegated to the
quotes-parameter walk instead of its own predicate. It was copy-paste
drift, not intent: the delegation computed the same value the caller's
structural recursion already computed, so it decided nothing. Meanwhile
it skipped the unquote scan, and bquote({ 1 == .(x) }) lost quoting
while bquote(list(.(x))) kept it. In R, bquote substitutes .(x) anywhere
in the template, braces included.

Walk braced bodies with the unquote predicate like every other arm.
bquote_references_parameter collapses to one expr_any call.

Failing test included: bquote_dot_in_a_braced_body_still_quotes.
@coderabbitai

coderabbitai Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: cbd10ea5-9361-4795-9e53-6f61db1d2de0

📥 Commits

Reviewing files that changed from the base of the PR and between a701681 and b7ac382.

📒 Files selected for processing (2)
  • crates/ry-checker/src/collect.rs
  • crates/ry-checker/src/tests/quoting_data_mask.rs

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The checker refactors quoting analysis into shared walkers and predicates. bquote now detects unquotes inside braced bodies. A regression test verifies that the checker does not emit RY010, and the changelog records the fix.

Changes

bquote quoting analysis

Layer / File(s) Summary
Generic quoting walkers
crates/ry-checker/src/collect.rs
Shared statement and expression walkers replace duplicated quoting helpers. Parameter capture and normal-use behavior remain unchanged.
bquote braced-body support
crates/ry-checker/src/collect.rs, crates/ry-checker/src/tests/quoting_data_mask.rs, CHANGELOG.md
bquote uses the shared walker to find .() unquotes in braced bodies. A regression test checks that no RY010 diagnostic is emitted. The changelog documents the fix.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to b7ac3

This PR consolidates equivalent AST traversal code and includes a targeted fix for braced bquote expressions, with the documented checks passing. No actionable merge-blocking risk remains beyond normal review.

Poem

A rabbit checks a braced quote,
And finds the dot where values float.
Shared walkers trace the nested trail,
No RY010 sounds its warning bell,
The changelog marks the fix.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main refactoring: replacing six collect.rs AST walker families with one generic walker design. It does not mention the additional braced-bquote fix, but t…
Docstring Coverage ✅ Passed Docstring coverage is 88.24% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 2 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title clearly and concisely describes the main refactoring: replacing six collect.rs AST walker families with one generic walker design. It does not mention the additional braced-bquote fix, but the title does not need to cover every change.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/collect-ast-walks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — two minor suggestions.

Reviewed changes

  • Unified AST walker: the six collect.rs walker functions collapse into one stmt_any/expr_any pair whose only degree of freedom is a call-shaped leaf predicate. I re-derived the arm-by-arm diff against the old families: every Stmt and Expr traversal arm matches, the Expr::Call leaf test is carried by pred, and the one old disagreement (the Expr::Block delegation) is the deliberate fix below.
  • Braced-bquote quoting fix: bquote_references_parameter's Expr::Block arm no longer delegates to the quotes-parameter walk, so .(x) inside bquote({ ... }) now marks x quoted. I traced the net behavior delta — it is exactly this case; substitute(x) and promise-captures inside braced templates stay detected through expr_any's generic argument recursion, matching what the old delegation found, via a different path.
  • Verification: cargo fmt and cargo clippy --all-targets -- -D warnings clean; --test corpus snapshots and all 57 quoting-module tests pass locally; the new test was mutation-checked (it fails on the pre-fix walker with the expected RY010); no references to the removed walker names remain repo-wide.

ℹ️ Nitpicks

  • The fix commit changes shipped diagnostics (the argument of a bquote({ .(x) }) call no longer gets RY010), which reads like a one-bullet ### Fixed entry under Unreleased — fine to fold in when the stack on #142 lands, if that's the plan.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using openai-compatible/glm-5.3 | 𝕏

Comment thread crates/ry-checker/src/collect.rs Resolved
@sims1253 sims1253 reopened this Aug 31, 2026
@sims1253
sims1253 changed the base branch from cleanup/checker-dead-code to main August 31, 2026 21:25
…bquote fix

stmt_any claimed pred runs at every expression node and expr_any claimed
it runs at the node itself. pred only runs in expr_any's Expr::Call arm;
every other arm just recurses. Reword both headers to say call nodes,
and note that the quoting-capture predicates early-return on non-call
nodes, so the two contracts are equivalent. Left the code alone: hoisting
pred above the match would run every predicate on every node for no gain.

Also add the Unreleased Fixed entry for the second commit's behavior
change: bquote templates with braced bodies now quote their unquotes, so
an unbound name passed to such a call no longer gets RY010.
@sims1253

Copy link
Copy Markdown
Owner Author

Addressed both review points in a701681.

  • Added the ### Fixed bullet under ## [Unreleased]: a .(x) in bquote({ 1 == .(x) }) is now recognized as quoting, so an unbound name passed at the call site no longer gets RY010. The PR body already described the fix, so I left it as is.
  • Applied your stmt_any wording verbatim and fixed expr_any's header to match: both now say pred runs at call nodes, and expr_any notes the predicates early-return on non-call nodes, so that is equivalent to every node. I did not hoist pred(expression) || above the match — it would run every predicate on every node for no gain, so the wording is the safer fix.

cargo fmt, clippy -D warnings, the 461 lib tests, and the corpus suite are all green locally.

@sims1253

sims1253 commented Sep 1, 2026

Copy link
Copy Markdown
Owner Author

Addressed the docstring-coverage warning: documented the five diff-touched functions that lacked docs (parameter_has_normal_use, is_single_promise_capture, is_dots_promise_capture, bquote_references_parameter, and the new braced-bquote test) in b7ac382. Docs state what each function does or what the test pins; pre-existing undocumented functions outside this diff are left as they were.

@sims1253
sims1253 merged commit 583177e into main Sep 1, 2026
15 checks passed
@sims1253
sims1253 deleted the refactor/collect-ast-walks branch September 1, 2026 15:44
sims1253 added a commit that referenced this pull request Sep 2, 2026
Adds ry_core::walk: a single pre-order Stmt/Expr walker with (a) a
Walk policy struct naming the five subtree edges the hand-rolled
visitors disagreed on (assignment targets, `<-` operands, `$`
subscript idents, function bodies, control tests), (b) a per-node
Descend::Skip answer for one-off prunes, (c) ControlFlow early
termination with payload, and (d) a fn_depth count for callbacks
that need function-nesting depth. The walkers differed on purpose;
the knobs expose the differences rather than erasing them.

Converted onto it (each site states its skip policy in one line):
- checker: collect_condition_assignment_names,
  assigned_names_in_body, collect_executed_identifiers (merged with
  collect_identifiers_in_stmt), collect_forwarded_calls_in_stmts
  (merged with _in_expr), vector_intent_parameters' visit pair,
  r6_rebound_members' visit pair, and PR #148's stmt_any/expr_any in
  collect.rs, which now delegate to the shared walker so exactly one
  walker exists.
- cli dump.rs: collect_local_bindings (+ _in_expr) and
  index_scope_bodies (+ _in_expr).
- workspace: the attachment walkers in packages.rs and
  collect_dynamic_bindings_stmt/_expr in lib.rs (depth tracking moves
  into the walker's fn_depth).

Left hand-rolled with a comment saying why: the RY098
force/identifier family in infer/misc.rs. Its rules select
individual children of a node (call args skipped unless the callee
is a strict builtin, literal-cond `if` takes one branch, `$` idents
skipped while the base is kept) and stop at the first identifier
forced in evaluation order -- an evaluation-order analysis, not a
subtree-skip policy.

Net -248 lines (949 deleted, 344 inserted, 357-line walker added).
All corpus/oracle/vendor snapshots byte-identical.
sims1253 added a commit that referenced this pull request Sep 2, 2026
* refactor: one shared AST walker for the hand-rolled visitors

Adds ry_core::walk: a single pre-order Stmt/Expr walker with (a) a
Walk policy struct naming the five subtree edges the hand-rolled
visitors disagreed on (assignment targets, `<-` operands, `$`
subscript idents, function bodies, control tests), (b) a per-node
Descend::Skip answer for one-off prunes, (c) ControlFlow early
termination with payload, and (d) a fn_depth count for callbacks
that need function-nesting depth. The walkers differed on purpose;
the knobs expose the differences rather than erasing them.

Converted onto it (each site states its skip policy in one line):
- checker: collect_condition_assignment_names,
  assigned_names_in_body, collect_executed_identifiers (merged with
  collect_identifiers_in_stmt), collect_forwarded_calls_in_stmts
  (merged with _in_expr), vector_intent_parameters' visit pair,
  r6_rebound_members' visit pair, and PR #148's stmt_any/expr_any in
  collect.rs, which now delegate to the shared walker so exactly one
  walker exists.
- cli dump.rs: collect_local_bindings (+ _in_expr) and
  index_scope_bodies (+ _in_expr).
- workspace: the attachment walkers in packages.rs and
  collect_dynamic_bindings_stmt/_expr in lib.rs (depth tracking moves
  into the walker's fn_depth).

Left hand-rolled with a comment saying why: the RY098
force/identifier family in infer/misc.rs. Its rules select
individual children of a node (call args skipped unless the callee
is a strict builtin, literal-cond `if` takes one branch, `$` idents
skipped while the base is kept) and stop at the first identifier
forced in evaluation order -- an evaluation-order analysis, not a
subtree-skip policy.

Net -248 lines (949 deleted, 344 inserted, 357-line walker added).
All corpus/oracle/vendor snapshots byte-identical.

* fix(checker): restore base traversal for block/if exprs and nested assigns

* test(workspace): pin attached_packages and dynamic-bindings walker semantics
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.

1 participant