Repository navigation
feat(ts): translate a slice's fill, fill_with, rotations, copy_within, copy_from_slice, and clone_from_slice - #282
Conversation
Quest-Claim: 7cfa938e12ec555e
…, copy_from_slice, and clone_from_slice 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 48 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 |
# 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: 7627dd6
No actionable bugs found. The runtime mappings preserve mutable-view writes, byte offsets, overlapping copy semantics, and independent copies of Copy aggregates. The fill/clone paths clone before dropping replaced values, move the final fill value, and drop it for an empty slice. Refusing unsupported custom clone_from implementations is preferable to silently substituting clone semantics; the specialized copy path also preserves its distinct length-mismatch behavior.
Direction is sound: reuse the existing views and bounds checks rather than introducing a second slice representation. The differential fixtures target useful boundaries, clone/drop ordering, and aliasing cases.
Static review of the changed lowering/runtime code, surrounding drop/closure and view handling, and generated fixtures, plus an independent second pass only. I did not run translation, TypeScript checks, native differential tests, or the reported mutation checks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem
A slice's
fill,fill_with,rotate_left,rotate_right,copy_within,copy_from_slice, andclone_from_slicewere refused as unsupported calls, except bytes'copy_from_sliceandcopy_within.[u8]::fillwas among them (found by #279), so theslices::chunkedandslices::rangesfixtures wrote loops instead.Consumers: moq's
bbr3::max_filter(samples.fill(sample)) and moq-video (pixels.fill(0)).Reproduced first: translating the new
slices::editsfixture before the change gave 42 distinctunsupported call to core::slice::<impl [T]>::{fill, fill_with, rotate_*, copy_within, copy_from_slice, clone_from_slice}errors with spans, over bytes,u16,u32,Copystructs, loggingClonetypes,Options, and every range kind.Approach
Each maps to a runtime function over a plain array or a
sliceView(so mutable chunks and subslices write through), or aByteSlicefor bytes. They follow std's semantics:fill:clone_frominto each slot except the last. Each clone is made before the old value drops. The last slot gets the value itself, and an empty slice drops it. ATrivialCloneis copied with noClonecall, as std specializes. When nothing is cloned or dropped, it maps to JS'sArray.fill.fill_with:f()for each slot in order, each before the old value drops. The function drops after the call, as with other spent closures.rotate_left/rotate_right: panic with std'sassertion failed: mid <= self.len()/k <= self.len().copy_within: range fields are still read where the range is made, as before. Every other range kind (a..=b,Boundpairs, anyRangeBounds) is checked throughrt.boundsRange, asslice::rangechecks it.Copyaggregates are copied, never shared.copy_from_slice: copiesCopyaggregates, with std's length-mismatch message.clone_from_slice: checks lengths first (destination and source slices have different lengths), then clones in order, each before the old value drops. ATrivialClonegoes throughcopy_from_slice, including its panic message, as std does.clone_fromis honored only where it acts as*self = source.clone()does:Clone's default, or std's own over such types when nothing drops or the type is anOption. Anything else (aclone_fromof the crate's own) is refused with a span.Proven by
slices::edits, run differentially against native wasm32 on plain slices, mutable chunks,split_at_muthalves, and subslices. The caller adds exhaustive cases over zero to four items at every three bounds. Clone and drop order is checked with values that log. Eight mutations of the runtime were each caught: cloning the last slot, dropping before the clone, not dropping on an empty fill, a sharedcopyWithin, the wrongclone_from_slicemessage,fill_withorder, a rotation off by one, and a sharedcopy_from_slice. The fixtures'fillloops now callfill, andpoke_wordsrotates, so every view kind is exercised.Impact
sliceFill,sliceFillWith,sliceRotateLeft,sliceRotateRight,sliceCopyWithin,sliceCopyFromSlice,sliceCloneFromSlice,byteSliceFill,byteSliceFillWith,byteSliceRotateLeft, andbyteSliceRotateRight.byteSliceCopyWithinkeeps its signature.Alternatives
copy_withininlibrary.rswith anrt.Boundsfor every range: simpler, but it allocated aRangeper call in the codec's encoder. I kept the in-place path for plain ranges and addedboundsRangefor the rest.clone_from: it takes&mut self, which for values JS copies needs a place per slot. Refused for now. Std's overrides that only reuse memory are accepted.Choices made without asking
rotatedandshifted(now supported) becamerefilledandrecloned, which refuse aclone_fromof the crate's own.clone_fromis added to the census'sVERBATIM.Follow-ups
None needed for moq. A
fillorclone_from_sliceof a type whose ownclone_fromis refused stays a census entry.Review
quest review), gpt-6.1-sol, medium effortjust cipassed on this headMerge of main at
150524b6(#283, #285) into7627dd69, as05b4c885: ordered main'serrors::eqsbeforeslices::editsin the case list and regeneratedharness.ts(the new case and one renumbered local). Recorded skip, too trivial to review;just cipassed on05b4c885.(written by Claude Opus 5.5)
🤖 Generated with Claude Code