Repository navigation
feat(ts): translate a slice's parts by inclusive and checked ranges and by fixed size - #279
Conversation
Quest-Claim: 9800f92fe6b8bba4
…nd by fixed size `&v[a..=b]`, `&v[..=b]`, a pair of `Bound`s, and their `&mut`, `get` and `get_mut` of each kind of range, and `first_chunk`, `last_chunk`, `split_first_chunk`, `split_last_chunk`, and their `_mut` forms translate, of bytes and other values. A range std's ranges don't take apart in place passes as the `rt.Bounds` drains read, which the runtime checks as std's `SliceIndex` does, `a..=b` by its own fields. A mutable part of other values is the runtime's `sliceView`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # ts/fixtures/lang/caller.ts # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/src/harness.rs # ts/fixtures/lang/src/lib.rs
# Conflicts: # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/src/harness.rs
|
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 18 seconds. 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. Comment |
# Conflicts: # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/src/harness.rs
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 49cc13e.
No actionable bugs found. Reusing the bounds and slice-view machinery is a sound direction without multiplying helpers for every range shape. The separate inclusive-index checks preserve exhausted-range behavior; checked ranges reject invalid bounds, and fixed-size first/last splits preserve tuple ordering and zero-length cases. Mutable byte and non-byte results retain write-through to their source.
The differential fixtures exercise boundary pairs, usize::MAX, exhausted inclusive ranges, fixed-size chunks and mutations; the new range API remains explicitly unsupported rather than silently mislowered.
Verification limits: source/generated-fixture inspection and an independent static review only. I did not run the translator, differential/mutation tests, or CI; reported results were not independently verified.
Closes the quest
quest/m3/ts-slice-ranges.md.Problem
rust2-ts refused a slice's remaining parts with a span:
&v[a..=b],&v[..=b], and their&mut;getandget_mutof any range; andfirst_chunk,last_chunk,split_last_chunk, and the_mutforms of those andsplit_first_chunk. The lang fixture's new case hit 63 such refusals before this change.Approach
a..b,a..,..b, and..are still taken apart in place, as indexing already did.getandget_mutof a range now go through that sameindexpath, into newsliceGetRange,sliceGetRangeMut, andbyteSliceGetRange. These giveundefinedunlessstart <= end <= len, as std'sgetdoes.SliceIndexrange (a..=b,..=b, or a pair ofBounds) is passed whole, as thert.Boundsthat feat(ts): translate drains and B-tree ranges of Bound pairs and the crate's own RangeBounds #267 added for drains.collections::plain_boundsis factored out ofboundsso both use one check. Two runtime functions turn the range into a start and end:sliceIndexBoundspanics as std'sindexdoes. Fora..=bit checks the range's own fields:b >= lenreportsslice_index_fail(a, b, len), and an exhausted range starts atb + 1. Every other range goes throughboundsRange, which already is std'sinto_slice_range.sliceGetBoundsgives the exclusive start and end without checking them.getthen applies the samestart <= end <= lenrule, which matches std'sgetfor each kind of range: JS numbers don't overflow atusize::MAX + 1.sliceView. Parts of bytes are already views.first_chunk(_mut)::<N>maps toget_range(_mut)(s, 0, N), andsplit_first_chunk(_mut)maps tosplit_at(_mut)_checked(N). This deletessliceSplitFirstChunkandbyteSliceSplitFirstChunk. Thelast_chunkandsplit_last_chunkforms get small runtime functions of their own.In this nightly,
&v[a..=usize::MAX]no longer panics with a separate overflow message. It panics withslice_index_fail's range message, and the differential tests match that.Tests
The new lang case
slices::rangescovers bytes,u16, an object struct, and a[u32; 5]. It checks:usize::MAXgetreturningNonefor ranges that are out of range or backwardsnextand exhausted by a foldBoundkind at either end_mutpart landing in the sourcecaller.tsenumerates 3,240 targeted inputs. The differential run reports 0 differences. As a mutation check, I made the runtime indexa..=bthroughboundsRangeand then dropped the exhausted flag. The cases caught these as 360 and 60 differences.Impact
sliceGetRange,sliceGetRangeMut,byteSliceGetRange,sliceIndexBounds,sliceGetBounds,sliceLastChunk,sliceLastChunkMut,sliceSplitLastChunk,sliceSplitLastChunkMut,byteSliceLastChunk, andbyteSliceSplitLastChunk. RemovessliceSplitFirstChunkandbyteSliceSplitFirstChunk; generated code callssplit_at_checked's functions instead. These are internal runtime functions, so there is noMIGRATE.mdentry.getbyte slices by range. This also closes the m3 gap the quest names for std slices.Alternatives
a..=bapart in place, as exclusive ranges are, would avoid allocating a range object. I rejected it because it needs theexhaustedflag and std's distinct panic messages for each source of the range. Passing the range whole reuses feat(ts): translate drains and B-tree ranges of Bound pairs and the crate's own RangeBounds #267'srt.Bounds. Inclusive ranges are rare on hot paths.Follow-ups
[u8]::fillis still refused.quest/m3/ts-slice-edits.mdalready tracks it, so the fixture uses a loop instead.core::range::RangeInclusive(the new range API) as a slice index still refuses with a span, as an unsupported call.Review
quest review, codex gpt-6.1-sol, medium effort, session01a18ccd.4ab00ddf: no findings.431cfde6(merge of origin/main with hand-resolved fixture conflicts): no findings.49cc13e6(merge of feat(ts): parse bool, char, and NonZero through str::parse #278 with a hand-resolved harness conflict): no findings.12c99141aaa213343ee5250585dbbbfa68b6ec6c(merge of fix(ts): refuse a pointer whose variable mem::replace, swap, take, or a write through an alias replaces #277 with the same harness-list conflict): no findings.just cipassed locally on12c99141.🤖 Generated with Claude Code
(written by Claude Opus 5.5)