Repository navigation
feat(ts): translate slice windows and chunks, Vec::drain, and the order of bytes - #259
Conversation
Quest-Claim: b05241a68bd19e74
A slice's `windows` and `chunks` map to `rt.PartsIter`, of byte views or array copies as the slice is, panicking on a size of 0 as std's do. `Vec::drain` maps to a runtime port that leaves the vector what precedes the range until the drain drops, then drops what it holds and moves the tail back, so a forgotten drain leaks the rest as std's does; its `Drain` therefore always drops. Byte arrays, slices, and vectors order through `rt.cmpBytes`, which reads each byte form a key or operand holds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/src/harness.rs
`Vec::drain`, `VecDeque::drain`, and a B-tree's `range` passed a tuple of `Bound`s, or a crate's own `RangeBounds`, to the runtime's `bounds`, which read it as unbounded. Each now refuses it with its span. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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 27 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. Comment |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 9dd9b657a8d75e2b64a9a4d4ad6c157cb96ce1db.
No actionable findings from this review. The parts iterator's front/back accounting preserves chunk remainders and empty oversized windows, and byte ordering respects view offsets and logical lengths. The drain keeps only the source prefix until disposal, drops the remaining range before restoring the tail, and is marked as dropping even for Copy elements. The earlier local range-bounds finding is addressed by explicit refusal instead of treating unsupported bounds as unbounded.
Direction: runtime iterators and one byte comparator fit the existing representations; deferred drain restoration is simpler and more faithful than special-casing mem::forget. The differential cases cover partial consumption, reverse/skipping consumers, destructor order and forgotten drains. One small coverage improvement: exercise zero-sized non-byte chunks independently, so the earlier byte-chunks panic cannot mask its panic-message mutation.
Verification limits: static GitHub review, including an independent drain ownership/drop pass. I did not execute the translator, native/TS differential suite, mutation tests, census or just ci; the reported results are not independently verified.
(Written by OpenAI)
# Conflicts: # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/src/harness.rs # ts/fixtures/lang/src/lib.rs # ts/fixtures/reject/census.md # ts/runtime/rt/collections.ts
Problem
rust2-ts refused a slice's
windowsandchunks,Vec::drain, and<,<=,>,>=, andcmpof byte arrays, slices, and vectors (questm3/ts-slice-gaps, filed by #252). moq reaches the drains: kio'stask.rs, and moq-net'smodel/track.rsandpriority.rs. zlib-rs reacheswindows.Approach
windowsandchunksmap tort.PartsIterinrt/iter.ts, which yields byte views or array copies, as the slice is. Each part comes from its index, so it reads from both ends, has alen, and skips without making a part. The last chunk is the remainder, a window larger than the slice yields nothing, and a size of 0 panics with std's message. They are runtime iterators because std's iterators arert.Iters by design (README, "Iterators are the runtime's lazy classes"): std'sWindowsandChunkstypes don't translate.Vec::drainmaps tort.vecDrainandrt.byteVecDrain, which port std'sDrain. At creation the vector keeps only what precedes the range. When the drain drops, it drops what it still holds front to back, then moves the tail back. A forgotten drain therefore leaves the vector what came before the range and leaks the rest, as std's does. Because its drop does something JS can see,vec::Drainnow always drops, even when its items don't. It is a port and not std's MIR because std'sDrainreads elements out and moves the tail through raw pointers. Replacing it is recorded inquest/m3/ts-unsafe.md, as feat(ts): translate cmp::max and min, is_sorted, and BinaryHeap #252 did forBinaryHeap.rt.cmpBytes: by their bytes, then by length. It reads whichever form a key or operand holds (aUint8Array, anrt.ByteSlice, or anrt.ByteVec), so it covers direct comparisons,Ord'smax/min/clamp, B-tree keys, heap items, sorts, and tuples holding owned or borrowed bytes.slice::range's check, shared withVecDeque::drain, moved into onesliceRange.Vec::drain,VecDeque::drain, and a B-tree'srangenow refuse, with a span, a range argument the runtime can't read: a tuple ofBounds or a crate's ownRangeBounds. The runtime'sboundsused to read those as unbounded, which silently drained or ranged over everything (found in review).Proof: the lang fixture adds
slices::parts,slices::drains, andorders::bytes, run differentially against native wasm32. They cover drop order,nth/nth_backskips,last,count, forgotten drains, out-of-range and backwards ranges (panic messages compared), chunk remainders, windows larger than the slice, and prefixes of different lengths. Mutating the runtime showed the cases catch these mistakes: reversing the drop order, restoring the tail eagerly so a forgotten drain no longer leaks, yielding a window past the end, dropping the remainder chunk, and dropping the length tiebreak. One mutation survived: changingsliceChunks's zero-size panic message. In that case the bytechunks(0)runs first and panics with its own copy of the same message.Census against main at 9df3118: moq-net 1495 to 1506, model 420 to 431, kio 153 to 152.
task.rs, and moq-net'smodel/track.rsandpriority.rs) and zlib-rs'swindows.rangeover a(Bound, Bound)tuple, in moq-net'sledger.rs,model/track.rs, andmodel/expiry.rs, and in rangemap'smap.rsandinclusive_map.rs. Before this PR those calls passed the tuple to a runtime that reads it as unbounded, in a calltscrejects. Now translation refuses them with a span.quest/m3/ts-bound-ranges.mdtranslates them, and moq's model needs it.Impact
sliceWindows,sliceChunks,byteSliceWindows,byteSliceChunks,vecDrain,byteVecDrain, andcmpBytes. Nothing breaks, so there is noMIGRATE.mdentry.(Bound, Bound)or custom-RangeBoundsargument toVecDeque::drainand B-treerange/range_mut, which translated wrongly before.Choices made without asking
windows,chunks,Vec::drain, and ordering of all three byte forms, keys included. The quest named byte arrays only; slices and vectors share the same comparator.==and hashing of byte arrays stay refused, for a follow-up.rt.cmpBytesdispatches on the byte form at run time instead of statically, because one type, such as[u8; 2], is aUint8Arraywhen owned and anrt.ByteSlicebehind a reference, andpeelloses which. It costs twoinstanceofchecks per comparison. No bench was added: nothing performance-sensitive changed, and no moq hot path compares bytes.Alternatives
Windows,Chunks, andDrainfrom MIR. That would mean translating std's iterator structs, against the iterator design. ForDrainit would also mean the raw pointersts-unsafecovers.mem::forget. That would be wrong for every other leak, such asBox::leak.Follow-ups
quest/m3/ts-byte-keys.md:==of byte arrays, and byte arrays, slices, and vectors as hash keys.quest/m3/ts-slice-chunks.md:chunks_exact,rchunks, and the mutable chunks (zlib-rs and uuid reach these).quest/m3/ts-bound-ranges.md: drains and B-tree ranges of a(Bound, Bound).quest/m3/ts-unsafe.md:Vec::drainfrom std's MIR once raw pointers into aVectranslate.floats.ts'smapOr$Option_Ordering_u8_floats_closure0, and I changed the fixture to avoid it.Review
Codex (
quest review), gpt-6.1-sol, medium effort. Reviewed head e508d45, round 3: no findings. This head merges main at 9df3118 (#257, #260, #261), with hand-resolved conflicts inrt/collections.ts's imports (ByteSlice/ByteVecbeside #261'sHashing) and in the lang harness (main's cases first). #261'shash_fnstill refuses byte containers, so this branch's routing of them throughstd_key, for ordering, intercepts no hash mapping.Round 2, on 9dd9b65: no findings.
Round 1, on fe31040:
mir/mod.rsnext results: refuted. The branch didn't touch the file; fix(ts): return std's next from a function other than next as an Option #258 landed on main after the branch merged it, so the round showed fix(ts): return std's next from a function other than next as an Option #258's change reversed. Merging fix(ts): return std's next from a function other than next as an Option #258 left the file's diff empty.Local checks:
just cipassed on e508d45. Since then main gained only #264, which changes quests alone and merges without conflicts.(written by Claude Opus 5.5)
🤖 Generated with Claude Code