Repository navigation
refactor(checker): unify function-entry and condition-diagnostics duplication - #145
Conversation
…helpers Mechanical prefix of #130. Semantics are unchanged; the full crate suite passes untouched. - apply_narrowing loses its unused _has_else parameter and returns early for Narrowing::None, so a no-narrowing if skips the match-arm work while still returning owned scopes. - merge_branch_bindings takes the branch scopes by reference; the caller no longer clones both just to keep reading them. - infer_if_expr no longer clones the branch scopes it consumes last. - One is_comparison predicate replaces the six-operator list written out at six sites. - One concrete_json_mode mapping replaces the JsonMode-to-Mode table written out three times. - extract_builtin_type_narrowing shares its inherits target lookup and first-argument identifier extraction; apply_narrowing shares the narrow-away-from-null sequence repeated across four arms. - try_s3_binop_dispatch and try_s3_unary_dispatch share the class vector walk. - equality_list_leaf_type loses its dead op parameter; unused span and name parameters are underscore-named at the signature instead of silenced in the body; a mid-file use moves to the top of misc.rs.
… emitter Second half of #130. Semantics are unchanged; the full crate suite passes untouched. - enter_function_body unifies the two ~55-line function-body walks in walk_stmt. The Assign arm passes its binding name plus a flag for the S3 dispatch context, the only line that differed. - emit_condition_diagnostics replaces the RY001/RY003/RY002 block written three times across walk_stmt's If and While arms and infer_if_expr. A ConditionContext selects the message noun and carries the While arm's missing RY002 case unchanged: the rule table scopes RY002 to `if` conditions, and that arm has never had it. - trusted_defusers is cached on the Checker instead of being rebuilt from DEFUSING_CALLS plus the whole fn table on every function per fixpoint iteration. collect_fns clears it, matching the only pass that writes fn_table.fns. - infer_call builds one ArgumentMatch per call. eval_mode_for_arg and bound_argument_index_matched consume it, so the argument loop is no longer O(n^2) and the assertion path matches once instead of three times. argument_eval_mode stays for the schema-call site outside infer/. - infer_data_frame calls longest_arg_length instead of repeating its ladder. infer_rep resolves times and each through rep_count. - list_binding_origin is inlined into its single caller. - The structure(x, class=...) doc comment moves from infer_injected_call, which handles typeshed injection, to infer_structure_call, which it describes.
|
Warning Review limit reachedNext included review available in 53 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Team Run ID: 📒 Files selected for processing (9)
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.
Important
One must-address finding inline: the new trusted_defusers cache can serve a stale, pre-propagation snapshot of the quoting flags to the pass-3 RY098 walk. Everything else in the unification verified equivalent.
Reviewed changes
- Unified function entry.
enter_function_bodyreplaces the two ~55-line body walks inwalk_stmt; verified verbatim against both removed arms — the S3 dispatch install (assignment form only, now thenamed_bindingflag),diagnostic_parameter_type,record_scope, and the push/pop ordering all preserve the old asymmetry exactly. - Unified condition diagnostics.
emit_condition_diagnostics+ConditionContextreplace the RY001/RY003/RY002 blocks in theStmt::Ifarm, theStmt::Whilearm, andinfer_if_expr; message nouns are byte-identical and the intentional While/RY002 split survives viaallows_length_rule. No bare RY001/RY002/RY003 emit sites remain outside the helper. - Cached defuser set.
Checker::trusted_defuserscaches the RY098 defuser set behind anArc, cleared bycollect_fns. Bothfn_tablereset sites (check,check_with_scope) are indeed followed by a collection round — but a second invalidation seam exists inside the fixpoint; see the inline comment. - One
ArgumentMatchper call.eval_mode_for_argandbound_argument_index_matchedconsume a match built once;match_argumentsguaranteesparam_for_arg.len() == args.len(), so the bounds-check swap is equivalent, andparam_names()ordering matchesparams. The keptargument_eval_mode/bound_argument_indexwrappers still serve their single-use callers innse.rs,call.rs, andmisc.rs. - Smaller folds.
infer_data_frame→longest_arg_length(fold verified identical to the removed ladder,Unknownabsorbing);infer_rep→rep_count(negative-literal and non-literal →Length::Unknownpreserved);list_binding_origininlined with zero remaining references; thestructure(x, class = ...)doc comment now sits oninfer_structure_callwith its claims still matching that code, andinfer_injected_callgot an accurate doc of its own.
Verification: cargo check -p ry-checker --all-targets clean, cargo test -p ry-checker --lib 460 passed, cargo test -p ry-checker --test corpus snapshots unchanged — no diagnostic drift on the fixtures.
openai-compatible/glm-5.3 | 𝕏
…on-walks # Conflicts: # CHANGELOG.md # crates/ry-checker/src/infer/binop.rs
There was a problem hiding this comment.
ℹ️ No new issues from the merge — one minor doc suggestion below. The open
trusted_defusersthread from the previous review is unaffected by this delta and still stands.
Reviewed changes
This run covers the delta since the prior review: the merge of origin/main (11 commits, notably #137 landing in base) into the branch — no new refactor work, and the merge introduced no conflict resolutions.
- Rebased the diff onto post-#137
main: the stacked #137 content left this PR's diff once it landed in base, and the merge left every refactor hunk untouched —collect.rsandinfer/{call,construct,misc,mod,pipe}.rsare byte-identical to the reviewed0062328state;lib.rsdiffers only by main's rewording of an unrelated comment above the severity-filter builders. - Absorbed main's checker-side inflow around the refactor:
binop.rsdropped a deadsymbol == "?"dispatch guard,nse.rsrenamed an unusedspanparameter, andproject.rsreplacedprev_return_slotswith ahas_prev_emitflag plus awith_transitive_callersextraction — none of them touch the refactor's seams (S3 dispatch install still only honors named bindings; project pass 3 still gets a freshwith_shared_tableschecker). - Re-ran the gates at the merge head:
cargo check -p ry-checker --all-targetsclean;cargo test -p ry-checker --lib460 passed,--test corpus5 passed,--test metamorphic16 passed — #132's new pipe-placeholder tests now exercise the unifiedemit_condition_diagnosticspath and stay green.
ℹ️ Nitpicks
- After the merge dropped #137's stacked entries into base, this PR ships a perf-relevant refactor with no
CHANGELOG.mdentry of its own: nothing under Unreleased → Changed covers the quadratic-to-linear argument matching or the cached defuser set, while #137 documented its same-genre change ("Less work perifduring checking"). A matching entry would keep the section consistent.
@v0 or keep the SHA fresh with Dependabot | Fix it ➔ | View workflow run | Using openai-compatible/glm-5.3 | 𝕏
The cache was built during fixpoint iteration 1 (nested function literals fire check_lazy_default_reachability in pass 2) and survived the quoting propagators, so the pass-3 RY098 walk could read a pre-propagation snapshot. Both propagators and signature seeding now clear it whenever they write quoting/defused flags. Regression test pins that a cached set matches the post-propagation table.
|
Addressed both reviews in bc916fa. Stale Test outcome. Your exact divergence cannot fire through the public API today. In Second review. Added the Unreleased → Changed entry for the once-per-call argument matching, the single function-entry walk, and the cached defuser set.
|
There was a problem hiding this comment.
✅ No new issues found. The
trusted_defusersstaleness from the earlier review is properly fixed, with regression coverage that provably fails on the pre-fix code.
Reviewed changes
This run covers the delta since the prior review: commit bc916fa, which resolves the open must-address thread about the stale trusted_defusers cache.
- Dropped the defuser cache when quoting flags move.
propagate_s3_generic_quotingandpropagate_forwarded_quotingnow cleartrusted_defuserswhenever a round changes the table, andseed_caller_visible_signaturesclears it when a seed applied (seed_caller_visible_signaturereturnsboolfor this). I traced every writer ofparams[].quoting/defused— all four sites (collection, both propagators, signature seeding) now invalidate, and both propagators setchangedon every actual flag write, so no write can slip past the clear. The remaininguses.defused = trueincollect.rswrites a localParameterUses, not the table. - Pinned the fix with a regression test.
defuser_cache_reflects_propagated_quotingasserts the S3-propagated generic lands in the cached set and that the full check emits no RY098. Mutation-verified: removing only the S3-propagator's clear trips the cache assertion withgabsent whileg.foois present — the test isolates exactly the reported bug, not a tautology. - Rewrote the invariant comments. The
misc.rs,lib.rs, andcollect.rsdoc comments now name the real invalidation sites instead of the disproven "frozen once collection ends" claim. - Added the missing CHANGELOG entry ("Less duplicate work per call and per function entry" under Unreleased → Changed), addressing the prior run's nit.
Verification: cargo fmt -p ry-checker --check clean, cargo clippy -p ry-checker --all-targets -- -D warnings clean, cargo test -p ry-checker --lib 461 passed (460 + the new test), --test corpus 5 passed, --test metamorphic 16 passed.
@v0 or keep the SHA fresh with Dependabot | View workflow run | Using openai-compatible/glm-5.3 | 𝕏
|
No changes needed. Review 5071491129 has 0 inline threads; its only actionable item is the nitpick asking for a Task list (4/6 completed)
|

Summary
Collapses the remaining large duplications inside
crates/ry-checker/src/infer/. Diagnostics and inferred types are unchanged. This PR is stacked on #137 and should merge after it.Changes
enter_function_bodyreplaces the two ~55-line body walks inwalk_stmt: theStmt::Assign { value: Expr::Function }arm and theStmt::FunctionDefarm. The only line that differed is the S3 dispatch context, installed for the assignment form alone, so the helper takes the binding name plus anamed_bindingflag.emit_condition_diagnosticsreplaces the RY001/RY003/RY002 block repeated in theStmt::Ifarm, theStmt::Whilearm, andinfer_if_expr. AConditionContextpicks the message noun and carries the RY002 case. On the While/RY002 divergence: it is intentional, not an omission. The rule table scopes RY002 toifconditions while RY001 and RY003 nameif/while, and theWhilearm has never carried RY002 back to the first commit that introduced these rules. The helper preserves that split throughConditionContext::allows_length_rulerather than widening it. The binop scan was left alone: it checks RY032 afterinfer_binop, not RY100 after inferring a condition, so it is not the same shape.check_lazy_default_reachabilityrebuilt aHashSetfromDEFUSING_CALLSplus every fn-table entry on every call, once per function per fixpoint iteration. The set now lives on theCheckerbehind anArcand is built on first use.collect_fnsclears it, which matches the existing invalidation story: collection is the only pass that writesfn_table.fns, and every table reset is immediately followed by a collection round.ArgumentMatchper call.argument_eval_modere-ranmatch_argumentsper argument, makinginfer_call's argument loop quadratic.eval_mode_for_argconsumes a match built once.bound_argument_index_matcheddoes the same for the assertion path, which matched up to three times per call site.argument_eval_modeandbound_argument_indexremain as self-matching wrappers for the call sites outsideinfer/.infer_data_framecallslongest_arg_lengthinstead of repeating its combine ladder.infer_represolvestimesandeachthrough onerep_counthelper instead of writing the negative-literal and non-literal early returns out twice.list_binding_originis inlined into its single caller.structure(x, class = ...)comment sat oninfer_injected_call, which handles typeshed injection. It now sits oninfer_structure_call, the function it describes, andinfer_injected_callgot a doc comment of its own.Verification
cargo fmt -p ry-checker --checkcargo clippy -p ry-checker --all-targets -- -D warningscargo test -p ry-checker— full suite, 594 tests across 16 binaries, all green.