Skip to content

feat(ts): translate a slice's fill, fill_with, rotations, copy_within, copy_from_slice, and clone_from_slice - #282

Merged
kixelated merged 6 commits into
mainfrom
quest/m3/ts-slice-edits
Oct 30, 2026
Merged

kixelated merged 6 commits into
mainfrom
quest/m3/ts-slice-edits

Conversation

@kixelated

@kixelated kixelated commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A slice's fill, fill_with, rotate_left, rotate_right, copy_within, copy_from_slice, and clone_from_slice were refused as unsupported calls, except bytes' copy_from_slice and copy_within. [u8]::fill was among them (found by #279), so the slices::chunked and slices::ranges fixtures wrote loops instead.

Consumers: moq's bbr3::max_filter (samples.fill(sample)) and moq-video (pixels.fill(0)).

Reproduced first: translating the new slices::edits fixture before the change gave 42 distinct unsupported 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, Copy structs, logging Clone types, 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 a ByteSlice for bytes. They follow std's semantics:

  • fill: clone_from into 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. A TrivialClone is copied with no Clone call, as std specializes. When nothing is cloned or dropped, it maps to JS's Array.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's assertion 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, Bound pairs, any RangeBounds) is checked through rt.boundsRange, as slice::range checks it. Copy aggregates are copied, never shared.
  • copy_from_slice: copies Copy aggregates, 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. A TrivialClone goes through copy_from_slice, including its panic message, as std does.
  • clone_from is 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 an Option. Anything else (a clone_from of 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_mut halves, 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 shared copyWithin, the wrong clone_from_slice message, fill_with order, a rotation off by one, and a shared copy_from_slice. The fixtures' fill loops now call fill, and poke_words rotates, so every view kind is exercised.

Impact

  • Translator output: these calls now translate instead of being refused. No public Rust API change.
  • Runtime: new sliceFill, sliceFillWith, sliceRotateLeft, sliceRotateRight, sliceCopyWithin, sliceCopyFromSlice, sliceCloneFromSlice, byteSliceFill, byteSliceFillWith, byteSliceRotateLeft, and byteSliceRotateRight. byteSliceCopyWithin keeps its signature.

Alternatives

  • Mapping copy_within in library.rs with an rt.Bounds for every range: simpler, but it allocated a Range per call in the codec's encoder. I kept the in-place path for plain ranges and added boundsRange for the rest.
  • Calling a type's own 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

  • The reject fixture's rotated and shifted (now supported) became refilled and recloned, which refuse a clone_from of the crate's own.
  • clone_from is added to the census's VERBATIM.

Follow-ups

None needed for moq. A fill or clone_from_slice of a type whose own clone_from is refused stays a census entry.

Review

  • Reviewer: Codex (quest review), gpt-6.1-sol, medium effort
  • Reviewed head: 7627dd6
  • Round 1: no findings
  • Local checks: just ci passed on this head

Merge of main at 150524b6 (#283, #285) into 7627dd69, as 05b4c885: ordered main's errors::eqs before slices::edits in the case list and regenerated harness.ts (the new case and one renumbered local). Recorded skip, too trivial to review; just ci passed on 05b4c885.

(written by Claude Opus 5.5)

🤖 Generated with Claude Code

kixelated and others added 4 commits October 30, 2026 05:55
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>
@kixelated kixelated changed the title A slice's edits in place feat(ts): translate a slice's fill, fill_with, rotations, copy_within, copy_from_slice, and clone_from_slice Oct 30, 2026
@kixelated
kixelated marked this pull request as ready for review October 30, 2026 15:05
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 07f14efb-c9d5-45fa-bcff-9696dae16d5a
Commits

Reviewing files that changed from the base of the PR and between 150524b and 05b4c88.

Files selected for processing: 18
  • quest/m3/README.md
  • quest/m3/ts-slice-edits.md
  • ts/fixtures/lang/caller.ts
  • ts/fixtures/lang/expected/core/option.ts
  • ts/fixtures/lang/expected/harness.ts
  • ts/fixtures/lang/expected/slices.Counted.ts
  • ts/fixtures/lang/expected/slices.Noisy.ts
  • ts/fixtures/lang/expected/slices.ts
  • ts/fixtures/lang/src/harness.rs
  • ts/fixtures/lang/src/slices.rs
  • ts/fixtures/reject/census.md
  • ts/fixtures/reject/expected.txt
  • ts/fixtures/reject/src/lib.rs
  • ts/fixtures/reject/ts.toml
  • ts/runtime/rt.ts
  • ts/src/census.rs
  • ts/src/lower/library.rs
  • ts/src/lower/mir/call.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

# Conflicts:
#	ts/fixtures/lang/expected/harness.ts
#	ts/fixtures/lang/src/harness.rs

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant