Repository navigation
feat(ts): call a crate's own find, rfind, find_map, for_each, reduce, and all where std does - #501
Merged
Merged
Conversation
Quest-Claim: 1d89173ccee245d3
… and all where std does Filter, SkipWhile, and FilterMap read their iterator by its find, rfind, or find_map, which Chain, Fuse, and Rev forward; Extend of hash and B-tree collections, LinkedList, (), and tuples reads it by for_each; max, min, max_by, and min_by reduce it, and is_sorted and is_sorted_by read it by all. rt.iterFrom calls the crate's own of each where std's does, but through &mut or a box, which forward none. Overrides std never calls in place of another, such as position or max, no longer refuse the impl. collect, eq, partial_cmp, and by_ref stay refused, and the quest now holds them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…calls # Conflicts: # ts/runtime/rt/iter.ts
kixelated
marked this pull request as ready for review
November 3, 2026 09:26
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 56 minutes. View limit details
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. CodeRabbit Verify
|
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
rust2-ts refused any
impl Iteratorof the crate that overrides a provided method other than the onesrt.iterFromalready called (size_hint,next_back,len,nth,nth_back,fold,rfold,count,last). std's adaptors and consumers call several more of a crate's own methods in place ofnext:Filter::nextandSkipWhile::nextcallfind,Filter::next_backcallsrfind, andFilterMap::nextcallsfind_map.Chain,Fuse, andRevforwardfindandrfind.ExtendofString, hash and B-tree collections,LinkedList,(), and tuples (sounzip) callsfor_each.max,min,max_by, andmin_bycallreduce.is_sortedandis_sorted_bycallall.Overrides std never calls in place of another, such as
positionormax, were refused too, though only the crate's own calls reach them.Approach
rt.Owngainsfind,rfind,findMap,forEach,reduce, andall. As withfold, the crate's method is translated once, for its closure as aBox<dyn FnMut>.find_map's foundBis au32stand-in, and the runtime boxes each value in an array where it crosses, so no value of it is theNone.eraseschecks each of these bodies as it checkedfold's, now over all of the method's type parameters.rt.Itergetsfind,rfind, andfindMapmethods. Their defaults read the iterator astry_folddoes.FromNextcalls its own;Chain,Fuse, andRevforward as std's do.Filter,SkipWhile, andFilterMapread their iterator by these innext, and byfoldedin theirtry_fold/foldpath.finds()keeps that path allocation-free unless the crate's own find is reachable.forEach,best(max/min/max_by/min_by), anditerIsSortedBydispatch to the crate's ownfor_each,reduce, orallwhen they are given the crate's iterator itself.Take's"fold", which models std'sfor_eachin every collection extend, now reads byforEach.()'s extend usesiterForEach.Iterator for &mut Iforwards (BORROWED) reaches a borrowed iterator's record.iterBoxalready forwards none of the new methods.find/rfindwhose predicate would take a&[u8; N](std lends the array, the crate's body a slice).collect,eq,partial_cmp, andby_refstay refused, with the message reworded sincecollect's caller is aFromIterator, not an adaptor.Tests:
lang/ends'Overridesnow also overridesfind,rfind,find_map,for_each,reduce,all,position, andmax, each logged. A newfoundconsumer reads it by value, through&mut, and boxed, plus plainRun, through every adaptor and consumer above, including thetry_foldpaths that must not callfind, afind_mapwhoseNoneisrt.None, and droppy comparators. Mutation check: disabling the Chainfindforwarding, thereducedispatch, or theforEachdispatch fails 20 inputs. The reject fixture covers the byte-arrayrfind, a still-refusedcollect, and afind_mapthat drops what it finds.Perf: a Node A/B of filter/filter_map/chain-find loops over the old and new runtime showed no regression (old 31 to 35 ms, new 31 to 32 ms median, noisy host). The full
just ts benchwasn't run (it needs the bench shell and browsers).Impact
find,rfind,find_map,for_each,reduce, orallnow translates, as does one overriding a method std never calls in place of another (any,position,rposition,max,min,max_by,min_by,max_by_key,min_by_key,sum,product,partition,unzip,cmp,ne,lt,le,gt,ge,is_sorted,is_sorted_by_key).rt.Owngains optional keys;rt.Itergainsfind,rfind,findMap, andfinds;rt.iterForEachreturnsundefined. All additive, so noMIGRATE.mdentry.Alternatives
collect,eq, andpartial_cmphere too. They are generic over another iterator or a collection, so one instance per iterator, asrt.Ownholds, doesn't fit. Each needs a call of the crate's instance at the call site std's mapping reaches. That is independently landable, so the quest now holds just those (plusby_ref, whichVec::splicecalls).FoldedinFilter::folded. Rejected: the shunts behindcollect::<Result<_, _>>callfolded()per item.Follow-ups
collect,eq,partial_cmp, andby_ref.Review
quest review, Codexgpt-6.1-solat medium effort, round 1 on head ff600d1 against base 5983791: 0 findings.best's doc and its fast-path condition ints/runtime/rt/iter.ts. The resolution keeps both: the crate's ownreducedispatch, and feat(ts): drop as std does in B-tree collects by a key's own Ord, max_by_key, and into_keys' ends #499'sdropKeycheck. No reviewer round covered it. Later merges of origin/main (feat(ts): translate a slice of one object behind any &mut #502, feat(ts): translate a function pointer or a boxed closure as a str pattern #504) did not conflict.just cipassed on 78793ba.🤖 Generated with Claude Code