Repository navigation
feat(ts): translate the methods of std's ranges - #325
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…onZeros Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
#320 left std's ranges with gaps no quest tracked. Reproduced in a probe crate, each a refusal with its span or a runtime throw:
containsrefused onRangeFrom,RangeTo,RangeToInclusive,RangeFull(throughRangeBounds), oncharand float ranges, and throughRangeBounds::containson every range type.is_emptyrefused oncharand float ranges.==andHashrefused on every range type butRangeFull, andRangeInclusive::into_innerrefused.Rangeconstant was refused, so even(1u8..3).contains(&x)and{:?}of1.5..2.0failed to translate.by_refcharcase (('a'..='z').by_ref().zip(0..3).count()) is fixed on main since feat(ts): translate start.. as an iterator, stepping as std's does past its type's maximum #320 passesrt.charStep. But a range of unsignedNonZeros, which std'sStepiterates, still translated and then threwrust2-ts: stepping a range of no integer typeat runtime (nthofNonZero<u8>ranges,nextofstart..).Approach
RangeBounds::containsdoes, by<=and<(a newlebesideltinrt/iter.ts). That way a NaN bound or item contains nothing, andRangeInclusive::is_emptyisexhausted || !(start <= end).containsruntime function.RangeBounds::containsmaps to the same function,RangeFull's totrue, and a pair ofBounds' tort.boundsContains.==,!=,Hash, and hash collections througheq_fn,hash_fn, andstd_key.rt.rangeEqandrt.rangeHashcompare and hash each bound through what the bound's type uses, and an inclusive range'sexhaustedflag too, as std's derived impls do.Rangeconstants translate asnew rt.Range(...), asRangeFromandRangeInclusiveconstants already did.NonZeros takesrt.nonZeroStep(int's Step, MAX). Where the integer would wrap, it stops atMAXor1, as std'sforward_overflowingandbackward_overflowingdo. Every remaining path tostepping a range of no integer typeandstepping a wide range without its typeneeds aSteptype with no JS value:Ipv4AddrandIpv6Addr, which translation already refuses as a type with a span, or the unstableAsciiChar.iters::range_methods, 1216 cases:charon either side of the surrogates,f32andf64with NaN, the infinities, and both zeros, andNonZeroofu8,u64,u128, andusize.contains(inherent, throughRangeBounds, and ofBoundpairs),is_empty,==,!=,Debug,Hash(also asHashSetkeys),start,end,start_bound,end_bound, andinto_inner.next,next_back, past its end until it wraps, folded until it is exhausted at its end,nth, andnth_back.containsandis_emptyuse the number comparison only when the item's type matches the bounds' type and neither is behind a&mut. Otherwise the call stays refused with its span. Two reject cases pin this:keyed_across(a crate's cross-typePartialOrd) andplace_bounds(&mutbounds).is_emptyandcontains,exhaustedin==andHash,RangeToInclusive's inclusive end,NonZerosaturation,Boundpairs) makes it report between 20 and 1198 differences.clonewas left to #322 (ts-iter-clone), which has since merged.Impact
NonZeros takesrt.nonZeroStep(rt.u8Step, 255)and the like, added tots/MIGRATE.md.rt.nonZeroStep,rt.rangeFromContains,rt.rangeToContains,rt.boundsContains,rt.rangeInclusiveIntoInner,rt.rangeEq, andrt.rangeHash.Alternatives
containsoverrt.Boundsfor every range type. Rejected: it builds twoBoundobjects per call, on what is often a hot path ((b'0'..=b'9').contains(&c)). Only theBoundpair goes through it.==andHashfunctions for each range type. One function each, reading the range's fields, is less code.Choices made without asking
RangeBounds::containsof a pair ofBounds is included, since it is the same trait method as the range types' owncontains.Follow-ups
{:?}of aBoundis refused, so the fixture writes bounds as bytes.quest/m3/ts-range-methods.mdand deleted it once the work was done.Review
Codex
gpt-6.1-sol, medium effort,quest review --base origin/main, 5 rounds in one session. Reviewed head:3ad03cf1fe9e5c44cc2cc1e587621e24e81591f0.just cipasses on that head.3f36dc21), medium,containsmapped against any item type, bypassing a crate's cross-typePartialOrd: fixed in61fdfaa1(reject casekeyed_across).61fdfaa1): no findings.just cithen caught a panic in that fix (it read a second type argument before checking the receiver was a range), fixed inbcf1c0b5.0b7c3d6c, after a hand-resolved merge of feat(ts): compare Cells and RefCells by what they hold, and one-time cells by their Option #324): no findings.e159b73f, after a merge of feat(ts): translate Iterator's comparisons against any IntoIterator #323), medium, bounds behind&mut(which may be anrt.Place) took the number comparison: fixed in3ad03cf1(reject caseplace_bounds).3ad03cf1): no findings.(written by Claude Opus 5.5)
🤖 Generated with Claude Code