Repository navigation
refactor(checker): collapse the six collect.rs AST walkers into one - #148
Conversation
- 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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Team Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe checker refactors quoting analysis into shared walkers and predicates. Changesbquote quoting analysis
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to 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
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Title checkExplanation 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
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
ℹ️ No critical issues — two minor suggestions.
Reviewed changes
- Unified AST walker: the six
collect.rswalker functions collapse into onestmt_any/expr_anypair whose only degree of freedom is a call-shaped leaf predicate. I re-derived the arm-by-arm diff against the old families: everyStmtandExprtraversal arm matches, theExpr::Callleaf test is carried bypred, and the one old disagreement (theExpr::Blockdelegation) is the deliberate fix below. - Braced-bquote quoting fix:
bquote_references_parameter'sExpr::Blockarm no longer delegates to the quotes-parameter walk, so.(x)insidebquote({ ... })now marksxquoted. I traced the net behavior delta — it is exactly this case;substitute(x)and promise-captures inside braced templates stay detected throughexpr_any's generic argument recursion, matching what the old delegation found, via a different path. - Verification:
cargo fmtandcargo clippy --all-targets -- -D warningsclean;--test corpussnapshots 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
fixcommit changes shipped diagnostics (the argument of abquote({ .(x) })call no longer gets RY010), which reads like a one-bullet### Fixedentry under Unreleased — fine to fold in when the stack on #142 lands, if that's the plan.
openai-compatible/glm-5.3 | 𝕏
…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.
|
Addressed both review points in a701681.
cargo fmt, clippy -D warnings, the 461 lib tests, and the corpus suite are all green locally. |
|
Addressed the docstring-coverage warning: documented the five diff-touched functions that lacked docs ( |
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.
* 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

Summary
stmt_captures_all_arguments/expr_captures_all_arguments,stmt_quotes_parameter/expr_quotes_parameter,stmt_captures_promise_parameter/expr_captures_promise_parameter, andbquote_references_parameter.stmt_anytakes a predicate,expr_anyapplies it at every expression node. Each family reduces to its predicate plus one call.Changes
stmt_any/expr_anyincrates/ry-checker/src/collect.rs. The predicate runs at each expression node; the traversal recurses into compound statements, callees, and arguments.Stmt::FunctionDefandExpr::Functionstay opaque, as before.captures_all_arguments(match.call / sys.call),quotes_parameter(substitute, promise-capture helper, bquote template),captures_promise_parameter(promise-capture helper, dots capture), andunquotes_parameter(.(param)inside a bquote template).parameter_is_quotedcalls the walker directly with those predicates.collect_parameter_uses_*accumulate side effects,first_parameter_use_*stop at the first use,block_force_flowtracks fall-through. Different semantics, not the same shape.Arm-by-arm diff before unification: every
Stmtarm and everyExprarm agrees across the families. Only theExpr::Callleaf test differs.The one disagreement:
bquote_references_parameter'sExpr::Blockarm delegated tostmt_quotes_parameterrather 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, sobquote({ 1 == .(x) })lost quoting whilebquote(list(.(x)))kept it. In R,bquotesubstitutes.(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-checkerclean.cargo clippy -p ry-checker --all-targets -- -D warningsclean.cargo test -p ry-checkergreen: 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
bquotebodies were incorrectly analyzed as eagerly evaluated..(x)are now handled correctly, preventing erroneous RY010 (unbound-variable) diagnostics.