Repository navigation
feat(ts): translate Iterator::cycle - #327
Merged
Merged
Conversation
Quest-Claim: ec5ea6db4c23475c
rt.iterCycle holds the iterator as std's Cycle does, with a clone of it made by the rt.Clones the translation gives, and clones that again each time the one it reads ends. Its next, size_hint, try_fold, and advance_by follow std's at the pinned toolchain, and a count of one that holds a Cycle goes through rt.ownedCount, which advances a Take as std's Take::count does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/src/harness.rs
# Conflicts: # ts/fixtures/lang/expected/harness.ts # ts/fixtures/reject/census.md # ts/fixtures/reject/expected.txt
kixelated
marked this pull request as ready for review
October 31, 2026 04:41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Iterator::cyclewas refused (unsupported call to <std::slice::Iter<'_, u8> as std::iter::Iterator>::cycleat the reject fixture'scycled,fixtures/reject/src/lib.rs:124:11). #322 gave eachrt.Iteraclone(h), which is everythingCycleneeds.Approach
rt.iterCycle(it, h)builds aCycleIterthat follows std'sCycleat the pinnednightly-2026-10-15(core/src/iter/adapters/cycle.rs):new(:22):origisit.clone(h), made whencycle()is called, anditerisit.next(:35): readsiter. When that ends,origis cloned and only then is the olditerdropped, asself.iter = self.orig.clone()does.size_hint(:46):(0, Some(0))passes through, any other(0, _)gives(0, None), and everything else gives(usize::MAX, None).try_fold(:56), modeled asfolded(): reads the rest ofiter, then one fresh clone, stopping if that clone was empty, then keeps cloning with no further empty check, exactly as std does.foldis std's default, bynext(folded(true)returns the cycle itself).advance_by(:87): advancesiter, then fresh clones, and stops at a clone that advances no further.nthstays the default (advance_bythennext).Clone(derived): clonesorigand theniter. Drop:origand theniter, in field order.cyclewith the inner iterator'srt.Clones.clonesnow coversCycle, and alsoiter::Empty, which it lacked (feat(ts): clone std's iterators and adaptors #322 cloned that one only through the zero-sized path).Take::countadvances its iterator byadvance_by(take.rs:60), nottry_fold. For aCyclethese differ:advance_bystops at an empty clone, whiletry_foldreads past it. So acountof an iterator that holds aCyclenow goes throughrt.ownedCount, which already advances aTake.cycledroot andcyclefrom the README's refusal list. Otherunsupported callentries still cover that refusal.Tests: a new
cycles::cyclesdifferential case, against native wasm32, covering:iter::empty, an emptyVec<Logged>, and a filter that rejects every item;cycle;take(n)across several wraps, throughcount,fold,any,collect,zip, andskip/step_by;nthacross wraps, with ownedLoggeditems cloned and dropped;findandpositionexiting early;cycle().clone(), including of owned items mid-pass, and a cycle of a cycle;next,Take::count, and a fold each behave differently.I checked the test with mutations of the translated runtime. Each of these makes the differential fail:
try_foldbynext, dropping before cloning, a wrong size hint, the clone order, the drop order, noadvance_byoverride, anditerCountin place ofownedCount.Impact
cycletranslates tort.iterCycle, andcountof an iterator holding aCycleemitsrt.ownedCount.iterCycle. No breaking change.Alternatives
countof aTakethroughownedCount. I didn't: onlyCyclemakesTake::countdiffer from a fold, and the narrower check keeps the owned dispatch out of bundles that don't need it.Follow-ups
None.
Review
Codex (
quest review), gpt-6.1-sol, medium effort:(written by Claude Opus 5.5)
🤖 Generated with Claude Code