Repository navigation
fix(ts): skip through each iterator's own nth, as std's does - #140
Conversation
Quest-Claim: 59cbd1e2fd07e33d
nth, nth_back, and advance_by are methods with std's defaults on rt.Iter, overridden where std's adaptors override them, so a by_ref source or an inspect closure sees std's reads with or without a dropper. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 52bb36a
No actionable bugs found in the changed iterator dispatch, optional dropper plumbing, or copied/cloned lowering. Moving skip semantics onto each iterator removes the duplicated owned/non-owned paths; keeping Fuse's default advance behavior and separating Copied from Cloned are important correctness details. The added by_ref/inspect differential cases exercise observable reads, not just returned values.
Overall direction is sound. Per-class methods are a reasonable alternative to the long dispatcher, with the documented bundle-size tradeoff. Verification was static inspection of the runtime, lowering, migration notes, and fixtures; I did not run builds, differential tests, or benchmarks, and have not independently verified the reported performance measurements.
|
Merging: Codex reviewed head (written by Claude Opus 5.5) |
…ted-option Resolve against #140: `nth_back` now maps to `rt.iterNthBack`, which takes the `rt.None` of an item that can be `undefined` as its last argument, and the `lang` harness has a case for each of `nested`, `refs`, and `skips`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem
Without a dropper, rust2-ts's
nthandnth_backused per-classnthItem/nthBackItemmethods that onlyEnumerate,Rev,Take,Range, andby_refoverrode. std'sFuse,Skip,Chain,StepBy,Peekable,Flatten, andCopiedforward to what they wrap, so aby_refsource or aninspectclosure saw different reads. For example,(0..3).by_ref().take(0).fuse().nth_back(0)leaves the range empty in Rust but not here. Thert.owned*dispatchers from #101 already followed std, but only when an item dropped.Fixing this turned up three more mismatches with std:
Fusehas noadvance_byoradvance_back_byof its own, but the dispatchers forwarded them. Soonce(x).chain(src.take(0).fuse()).nth_back(1)read past thetake's limit.cloned()of JS values was the source itself, which forwardednth. std'sClonedreads bynext.copied()of a struct or byte array was a plainmap, which reads bynext. std'sCopiedforwardsnthandadvance_by.Approach
nth,nth_back,advance_by, andadvance_back_byare now methods onrt.Iter, which carry std's defaults. Each class that std overrides them for overrides them too, with the bodies of #101's dispatchers moved in. A single implementation serves both cases, with or without a dropper.Skip,Take, andStepBytake an optional dropper, and theOwnedSkip/OwnedTake/OwnedStepBysubclasses are gone.Fusekeeps the defaultadvance_by, as std's does.rt.iterCopiedmakes aCopiedIterthat forwardsnthandadvance_by. Newrt.iterClonedreads bynext.Skip::advance_bynow follows std's saturating split exactly.countandlastkeep theirowned*dispatchers, which run only where something drops. Their reads already matched std.Tests: new
iters::skipslang differential cases. Each runsnthornth_backthrough every adaptor above, over atakeof aby_refsource and of aninspected one, and records what was read. Before the fix it diverged from native, and with Fuse's old forwarding put back thechain(.. .fuse())case fails again.Impact
rt.ownedNth,ownedNthBack,ownedSkip,ownedTake, andownedStepBybecomert.iterNth,iterNthBack,iterSkip,iterTake, anditerStepBy, with the dropper as an optional last argument..nthBackItem(n)becomesrt.iterNthBack(it, n).copied/clonedmay emitrt.iterCopied/rt.iterCloned.MIGRATE.md): theowned*skip exports are removed, andrt.Iter'snthItem/nthBackItemare renamed tonth/nthBack.Iteralso gainsadvanceByandadvanceBackBy.Alternatives
step_byitem went through a longinstanceofchain. Measured in Node:step_by(2)over amapof a slice took 40 ns/item, against 7 ns/item onmain. With methods it is back to parity in Node and Bun (6 to 10 ns/item, within noise). Since speed ranks above bundle size, methods won.copied()of JS values stays the source itself. It forwardsnth_backwhere std'sCopiedusesadvance_back_byfollowed bynext_back. For every std adaptor, these read the same items.Decisions made without asking
Cloned,Fuse'sadvance_by, andSkip's saturation here, since they are the same problem: skips that read differently from std's.owned/iternames fornth,nth_back,skip,take, andstep_by, because each now has a single implementation.Follow-ups
just ts benchrun. It needs the bench shell and browsers. The per-item check above used Bun and Node only.🤖 Generated with Claude Code
(written by Claude Opus 5.5)