Skip to content

refactor(checker): mechanical scope-clone and duplication cleanup in infer - #137

Merged
sims1253 merged 3 commits into
mainfrom
refactor/infer-clone-dedup
Aug 31, 2026
Merged

sims1253 merged 3 commits into
mainfrom
refactor/infer-clone-dedup

Conversation

@sims1253

Copy link
Copy Markdown
Owner

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_narrowing drops its unused _has_else parameter and returns
    early for Narrowing::None, so the common no-narrowing if skips the
    match-arm work while returning exactly what it returned before.
  • merge_branch_bindings takes the branch scopes by reference. The call
    site in walk_stmt no longer clones both scopes just to keep reading
    them.
  • infer_if_expr no longer clones the branch scopes it consumes last.
  • A single is_comparison predicate replaces the Lt | Le | Gt | Ge | Eq | Ne
    list written out at six sites (binop, call, recall, index).
  • A single concrete_json_mode mapping replaces the JsonMode-to-Mode
    table written out three times (json_rtype_scalar, union member
    filtering, apply_sig). Each caller keeps its own fallback for
    non-concrete specs.
  • extract_builtin_type_narrowing shares the inherits target lookup and
    the first-argument identifier extraction.
  • apply_narrowing shares the narrow-away-from-null sequence that was
    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, matching the sibling _span convention, instead of silenced
    with let _ = x; in the body.
  • The t callee check uses plain string equality like its neighbors, and
    the data-mask lookup uses .filter(...) instead of a re-borrow plus
    expect.
  • A use floating mid-file in misc.rs moves to the top, and a stale doc
    sentence on op_symbol (the match is exhaustive) is gone.

Verification

  • cargo fmt -p ry-checker
  • cargo clippy -p ry-checker --all-targets -- -D warnings
  • cargo test -p ry-checker — full crate suite, all green: 460 unit
    tests plus every integration suite (corpus, metamorphic, oracle,
    project, recall rules, real world, snapshots), 0 failures.

…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.
@coderabbitai

coderabbitai Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 38 minutes.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: 2ab772f0-3114-4d84-8643-5142fa2a7d33

📥 Commits

Reviewing files that changed from the base of the PR and between 8577b2d and 6be578f.

📒 Files selected for processing (9)
  • CHANGELOG.md
  • crates/ry-checker/src/infer/binop.rs
  • crates/ry-checker/src/infer/call.rs
  • crates/ry-checker/src/infer/construct.rs
  • crates/ry-checker/src/infer/index.rs
  • crates/ry-checker/src/infer/misc.rs
  • crates/ry-checker/src/infer/mod.rs
  • crates/ry-checker/src/infer/pipe.rs
  • crates/ry-checker/src/infer/recall.rs

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 — 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_narrowing drops its dead _has_else parameter and early-returns for Narrowing::None with exactly what the old empty arm produced; merge_branch_bindings and infer_if_expr now take/consume the branch scopes instead of cloning them — the sole walk_stmt call site only reads the scopes afterward, so both are equivalent.
  • is_comparison predicate: replaces the six-operator list at six sites; each site's variant set checked identical, and index.rs correctly keeps its extra In via ||.
  • concrete_json_mode consolidation: the helper's _ => return None fallback (union, compound specs, unrecognized) makes the restructured apply_sig match equivalent to its old inline table arm-for-arm, and json_rtype_scalar's .unwrap_or(Mode::Opaque) matches its old _ => Mode::Opaque.
  • Narrowing dedup: predicate_call_target / first_arg_ident / narrow_away_from_null_in collapse the repeated sequences; the only semantic delta anywhere is the Else arm's debug_assert_eq! now firing unconditionally rather than only when the binding narrows — strictly stronger and debug-only.
  • S3 dispatch split: s3_dispatch_on_operand is 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 dead op parameter, _span/_name renames, the "t" check, and the data-mask .filter(...) (the removed .expect was unreachable) are all equivalent.
  • Verification: cargo check --all-targets and clippy -D warnings clean; 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's symbol == "?" guard (crates/ry-checker/src/infer/binop.rs:230) is dead code: op_symbol is exhaustive over BinOpKind and 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.

Pullfrog  | Fix it ➔ | View workflow run | Using 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.
@sims1253

Copy link
Copy Markdown
Owner Author

Dropped the dead symbol == "?" guard in try_s3_binop_dispatch (4b6f279): op_symbol is exhaustive over BinOpKind and never returns "?", so the clause could not fire. Full ry-checker suite passes locally (595 tests, 0 failures); clippy and fmt clean.

@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 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 in try_s3_binop_dispatch (4b6f279): the symbol == "?" clause was unreachable (op_symbol is exhaustive over BinOpKind), and symbol remains in use for the operand loop at crates/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. The CHANGELOG.md conflict resolution is coherent: this PR's "Less work per if" entry survives intact under ### Changed alongside main's new entries.
  • Verification: cargo clippy -p ry-checker --all-targets -- -D warnings clean, and the full cargo test -p ry-checker run passes post-merge — 460 unit tests plus every integration target (corpus, metamorphic, oracle, project, recall rules, real world, snapshots), 0 failures.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | View workflow run | Using openai-compatible/glm-5.3 | 𝕏

@sims1253
sims1253 merged commit 196850f into main Aug 31, 2026
16 checks passed
@sims1253
sims1253 deleted the refactor/infer-clone-dedup branch August 31, 2026 21:20
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