Skip to content

Enumerable#zip: fast path only when every #each is built in (Greptile on #171) - #183

Merged
Largo merged 2 commits into
masterfrom
claude/zip-fast-path-greptile
Nov 10, 2026
Merged

Largo merged 2 commits into
masterfrom
claude/zip-fast-path-greptile

Conversation

@Largo

@Largo Largo commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Follow-up to #171 (part of #89). Greptile's two P1 comments on #171 hold against CRuby 4.0.9: the Enumerable#zip fast path read the receiver to the end and then each argument with #each, and allowed one custom #each among them. One is already too many.

case CRuby 4.0.9 master this PR
receiver's each sets h[:a] = 9 between yields, .zip(h) [[0, [:a, 1]], [1, [:b, 2]]] [:a, 9] in row 1 as CRuby
(1..1).zip(src), src.each has an ensure that raises [[1, 1]] RuntimeError as CRuby
(1..2).zip(src), src.each yields once, then raises StopIteration [[1, 1], [2, nil]] StopIteration as CRuby
(1..1).zip(src), src.each logs in ensure ensure not run ensure run as CRuby

Array#zip already matched CRuby in all four (MRI's take_items breaks out of #each too).

Change: the fast path now needs a built-in #each (Hash, Struct, Set, Integer Range) on the receiver and every argument; anything else goes through #next, as before #171. Set#zip(Hash) keeps its speedup (4 ms per 1000 elements, Debug); a custom Enumerable argument is back on #next. The second, now unused, branch of __zip_in_turn__ is removed.

Tests: Enumerable_ZipEnumerated1 gains the four cases (its expected output is CRuby's; the script's output is identical to CRuby 4.0.9's, and the new cases fail with master's prelude).

Verified (Debug net8.0): ruby/spec core/enumerable, enumerator, array, hash, struct, set: 0 failures; the 3 errors in array/hash/struct are the known "into" wording ones and identical on master. Enumerable_ZipEnumerated1 passes on net10.0. Full IronRuby.Tests net8.0: see the comment below.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge.

Summary

Enumerable#zip now uses its fast path only when the receiver and every enumerated argument have a built-in each.

  • Zip uses its faster path only when every iterator is built in.

Reviews (2) · Last reviewed commit: "ArrayTests.cs: restore CRLF line endings..." · Reviewed by Greptile

#171 let Enumerable#zip read a non-Array argument with #each, after the receiver, when at
most one of the receiver and the arguments had a custom #each. One is already too many
(found by Greptile on #171, each case checked against CRuby 4.0.9):

- A receiver's own #each can change an argument between its yields. MRI reads the
  argument in step, so `zip(h)` saw h[:a] before the change; IronRuby saw it after.
- An argument's own #each, cut short with break, runs its ensure clauses where MRI's
  Enumerator#next leaves it suspended: an ensure that raised made (1..1).zip(src) raise,
  and the ensure ran at all.
- A StopIteration raised by an argument's #each escaped instead of ending it with nils.

The fast path now needs a built-in #each (Hash, Struct, Set, Integer Range) on the
receiver and every argument; everything else goes through #next as before #171.
Set#zip(Hash) keeps its speedup; a custom Enumerable argument is back on #next.

Enumerable_ZipEnumerated1 gains the four cases; they fail on master's prelude.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 28 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 67 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7247a93 and a013e94.

Files selected for processing: 1

  • Src/IronRuby.Tests/Runtime/ArrayTests.cs

No actionable comments were generated in the recent review.

Walkthrough

Enumerable#zip now selects the in-turn path only when the receiver and all enumerated sources have quiet #each methods. A test checks the hash values observed when a custom enumerable mutates the hash between yields.

Changes: Enumerable#zip Iteration

Layer / File(s) Summary
Quiet iteration path
Src/StdLib/ironruby/ruby4.rb
The in-turn path now requires quiet #each methods on the receiver and every enumerated source. It reads each source’s yielded value directly; other cases use the Enumerator-based path.
Mutation test
Src/IronRuby.Tests/Runtime/ArrayTests.cs
The test documentation states the quiet-iteration condition. Enumerable_ZipEnumerated1 checks the hash values observed as a custom enumerable mutates the hash between yields.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • Largo/ironruby#114: Adds an indexed fast path for built-in Integer Ranges, another change to Enumerable#zip source selection.

Suggested reviewers: claude

Merge Risk: Minimal · previous review 7247a

The narrower zip fast path has no identified merge-blocking issue; normal checks remain appropriate.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the main change: Enumerable#zip uses the fast path only when every #each is built in. The parenthetical reference to Greptile and #171 is extra but does not obscure the ch…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title clearly identifies the main change: Enumerable#zip uses the fast path only when every #each is built in. The parenthetical reference to Greptile and #171 is extra but does not obscure the change.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 31e508c and 7247a93.

Files selected for processing: 2

  • Src/IronRuby.Tests/Runtime/ArrayTests.cs
  • Src/StdLib/ironruby/ruby4.rb

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

@Largo

Largo commented Nov 9, 2026

Copy link
Copy Markdown
Owner Author

Local full IronRuby.Tests (Debug net8.0) ran into its 25-minute timeout: the box was at load ~465 from other jobs. Its one failure, ErrorHighlight_Spots1, passes when run on its own. CI ran the full suite green on Linux and Windows, net8.0 and net10.0.

Greptile's P2 (CRLF → LF in ArrayTests.cs) was right: an edit script dropped the endings. Restored in 2nd commit; the diff is now 26+/5− in that file.

@Largo
Largo merged commit 9673b97 into master Nov 10, 2026
9 checks passed
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