Repository navigation
refactor(checker): mechanical scope-clone and duplication cleanup in infer - #137
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.
|
Warning Review limit reachedNext included review available in 38 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.
ℹ️ No critical issues — one deferable nitpick below.
Reviewed changes — a single-commit mechanical refactor of crates/ry-checker/src/infer (prefix of #130); every hunk was traced for arm-for-arm equivalence against the pre-PR code, and the crate's gates were re-run locally.
- Scope-clone removal:
apply_narrowingdrops its dead_has_elseparameter and early-returns forNarrowing::Nonewith exactly what the old empty arm produced;merge_branch_bindingsandinfer_if_exprnow take/consume the branch scopes instead of cloning them — the solewalk_stmtcall site only reads the scopes afterward, so both are equivalent. is_comparisonpredicate: replaces the six-operator list at six sites; each site's variant set checked identical, andindex.rscorrectly keeps its extraInvia||.concrete_json_modeconsolidation: the helper's_ => return Nonefallback (union, compound specs, unrecognized) makes the restructuredapply_sigmatch equivalent to its old inline table arm-for-arm, andjson_rtype_scalar's.unwrap_or(Mode::Opaque)matches its old_ => Mode::Opaque.- Narrowing dedup:
predicate_call_target/first_arg_ident/narrow_away_from_null_incollapse the repeated sequences; the only semantic delta anywhere is theElsearm'sdebug_assert_eq!now firing unconditionally rather than only when the binding narrows — strictly stronger and debug-only. - S3 dispatch split:
s3_dispatch_on_operandis the old unary body verbatim (plus the inferable-return comment, which previously lived only in the binop copy); both wrappers preserve their guards and operand order. - Small cleanups:
equality_list_leaf_type's deadopparameter,_span/_namerenames, the"t"check, and the data-mask.filter(...)(the removed.expectwas unreachable) are all equivalent. - Verification:
cargo check --all-targetsandclippy -D warningsclean; 460 unit tests plus the corpus, metamorphic, recall_rules, real_world, and project suites all pass locally (oracle/semantic_lists are CI-gated, R is unavailable in this runner). Corpus snapshots pinning diagnostics unchanged also pass.
ℹ️ Nitpicks
try_s3_binop_dispatch'ssymbol == "?"guard (crates/ry-checker/src/infer/binop.rs:230) is dead code:op_symbolis exhaustive overBinOpKindand never returns"?". This PR removed the doc vestige of that wildcard (op_symbol's "Returns?for unknown ops" sentence) — dropping the clause here would finish the cleanup, or defer it to #130.
openai-compatible/glm-5.3 | 𝕏
op_symbol is exhaustive over BinOpKind and never returns "?", so the symbol == "?" clause could never fire. Removes it per review.
…dedup # Conflicts: # CHANGELOG.md
|
Dropped the dead |
There was a problem hiding this comment.
✅ No new issues found — the prior review's nitpick is addressed and the merge landed cleanly.
Reviewed changes — the two commits pushed since the last review: the dead-guard cleanup it suggested, plus a merge of main whose interaction with the refactor I verified end-to-end.
- Dropped the dead
?guard intry_s3_binop_dispatch(4b6f279): thesymbol == "?"clause was unreachable (op_symbolis exhaustive overBinOpKind), andsymbolremains in use for the operand loop atcrates/ry-checker/src/infer/binop.rs:237, so behavior is identical. This closes out the one nitpick from the previous review. - Merged
origin/main(6be578f, bringing #139, #140, #132, #138, #136, #133):git diff df5f573..HEAD -- crates/ry-checker/src/infer/contains only the guard hunk — main's dead-code sweep and test additions touch disjoint files, so the refactor's equivalences all still hold on the merged tree. TheCHANGELOG.mdconflict resolution is coherent: this PR's "Less work perif" entry survives intact under### Changedalongside main's new entries. - Verification:
cargo clippy -p ry-checker --all-targets -- -D warningsclean, and the fullcargo test -p ry-checkerrun passes post-merge — 460 unit tests plus every integration target (corpus, metamorphic, oracle, project, recall rules, real world, snapshots), 0 failures.
@v0 or keep the SHA fresh with Dependabot | View workflow run | Using openai-compatible/glm-5.3 | 𝕏

Summary
Mechanical prefix of #130. It removes gratuitous scope clones, dead
parameters, and duplicated helper logic inside
crates/ry-checker/src/infer.Semantics do not change. The undo-log redesign of scope storage stays
tracked in #130.
Changes
apply_narrowingdrops its unused_has_elseparameter and returnsearly for
Narrowing::None, so the common no-narrowingifskips thematch-arm work while returning exactly what it returned before.
merge_branch_bindingstakes the branch scopes by reference. The callsite in
walk_stmtno longer clones both scopes just to keep readingthem.
infer_if_exprno longer clones the branch scopes it consumes last.is_comparisonpredicate replaces theLt | Le | Gt | Ge | Eq | Nelist written out at six sites (binop, call, recall, index).
concrete_json_modemapping replaces the JsonMode-to-Modetable written out three times (
json_rtype_scalar, union memberfiltering,
apply_sig). Each caller keeps its own fallback fornon-concrete specs.
extract_builtin_type_narrowingshares theinheritstarget lookup andthe first-argument identifier extraction.
apply_narrowingshares the narrow-away-from-null sequence that wasrepeated across four arms.
try_s3_binop_dispatchandtry_s3_unary_dispatchshare the classvector walk.
equality_list_leaf_typeloses its deadopparameter.spanandnameparameters are underscore-named at thesignature, matching the sibling
_spanconvention, instead of silencedwith
let _ = x;in the body.tcallee check uses plain string equality like its neighbors, andthe data-mask lookup uses
.filter(...)instead of a re-borrow plusexpect.usefloating mid-file in misc.rs moves to the top, and a stale docsentence on
op_symbol(the match is exhaustive) is gone.Verification
cargo fmt -p ry-checkercargo clippy -p ry-checker --all-targets -- -D warningscargo test -p ry-checker— full crate suite, all green: 460 unittests plus every integration suite (corpus, metamorphic, oracle,
project, recall rules, real world, snapshots), 0 failures.