Skip to content

refactor(builtin): share Int/Int64/Double until via a private helper#3489

Open
bobzhang wants to merge 1 commit intomainfrom
feat/builtin-range
Open

refactor(builtin): share Int/Int64/Double until via a private helper#3489
bobzhang wants to merge 1 commit intomainfrom
feat/builtin-range

Conversation

@bobzhang
Copy link
Copy Markdown
Contributor

@bobzhang bobzhang commented Apr 27, 2026

Summary

  • Extracts the three near-identical loop bodies of Int::until, Int64::until, and Double::until into a single private generic helper until_impl[T : Add + Compare + Default] in builtin/range.mbt.
  • The three public functions become one-line delegates.
  • Public API is unchanged — no new traits, no new functions exported. git diff origin/main builtin/pkg.generated.mbti is empty.

Why

Three copies of the same loop, with the only differences being the literal numeric type. Sharing them via a small generic helper keeps each per-type wrapper focused on its signature and lets us evolve the loop in one place.

Semantics

Byte-for-byte identical to the previous behavior, including:

  • Zero-step yields an empty iterator.
  • Negative step descends.
  • inclusive=true includes end.
  • The overflow corner case (MAX_VALUE - 1).until(MAX_VALUE, inclusive=true) yields [MAX-1, MAX] and terminates without wrapping — covered by existing tests at builtin/iter_test.mbt:421-438 for both Int and Int64.

Test plan

  • moon test — 6364/6364 pass.
  • moon check — no new warnings.
  • diff <(git show origin/main:builtin/pkg.generated.mbti) builtin/pkg.generated.mbti — empty.

Diff size

2 files changed, 50 insertions(+), 63 deletions(-).

🤖 Generated with Claude Code

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@bobzhang bobzhang force-pushed the feat/builtin-range branch from 9dbea3a to ee09b2c Compare April 27, 2026 08:04
@bobzhang bobzhang changed the title feat(builtin): generic range over a Step trait refactor(builtin): share Int/Int64/Double until via a private helper Apr 27, 2026
Extract the three near-identical loop bodies of `Int::until`,
`Int64::until`, and `Double::until` into a single private generic
`until_impl[T : Add + Compare + Default]` in `builtin/range.mbt`. The
three public functions become one-line delegates.

Public mbti is unchanged — no new traits, no new functions exported.
Semantics are byte-for-byte identical, including the existing
overflow handling for `(MAX_VALUE - 1).until(MAX_VALUE, inclusive=true)`
on `Int` and `Int64` (covered by `builtin/iter_test.mbt:421-438`).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@bobzhang bobzhang force-pushed the feat/builtin-range branch from ee09b2c to 37f14fe Compare April 27, 2026 08:52
@coveralls
Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 4044

Coverage decreased (-0.005%) to 94.812%

Details

  • Coverage decreased (-0.005%) from the base build.
  • Patch coverage: 12 of 12 lines across 2 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 15574
Covered Lines: 14766
Line Coverage: 94.81%
Coverage Strength: 220329.59 hits per line

💛 - Coveralls

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.

2 participants