Skip to content

feat(ts): translate an array as a slice - #287

Merged
kixelated merged 8 commits into
mainfrom
quest/m3/ts-array-as-slice
Oct 30, 2026
Merged

kixelated merged 8 commits into
mainfrom
quest/m3/ts-array-as-slice

Conversation

@kixelated

@kixelated kixelated commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

rust2-ts refused <[T; N]>::as_slice and as_mut_slice with a span, as "unsupported call to std::array::<impl [u8; 4]>::as_mut_slice", for bytes and other values alike.

Approach

Each is the reference it takes. A reference to an array of bytes is an rt.ByteSlice already, and a reference to an array of other values is its JS array (never an rt.Place), which is also how a &[T] or &mut [T] is represented. So the slice is the array itself and writes through as_mut_slice land in it.

A differential case (arrays::as_slices) runs against native wasm32: arrays of bytes, u16, String, and nested arrays; empty [u8; 0] and [u16; 0]; an inner array's as_slice/as_mut_slice of an element of the outer's as_mut_slice; arrays lent by &mut to a function and written through their slices; and rotate_left, rotate_right, fill, and copy_from_slice (from #282) writing through as_mut_slice. Mapping as_mut_slice of other values to a copy fails that case, so it guards the writes.

Impact

  • Translator output: as_slice and as_mut_slice of an array translate instead of refusing. No runtime or API change.

Alternatives

  • The brief suggested rt.sliceView for other values. A view is only needed for a part of an array; the whole array is its own slice, so a view would add a Proxy per call for nothing.

Follow-ups

  • None.

Review

Codex gpt-6.1-sol, medium effort, via quest review --base origin/main, round 3 on head 035e20387f11ae5a6bf6712830c3128627002763 (after merging main with a hand-resolved harness conflict): no findings. Rounds 1 and 2 also reported none. just ci passed locally on that head.

Merge of main at 074f8b7a (#286, #288, #289, #291) into 035e2038, as 53d1fcd9: ordered main's pointers::made before arrays::as_slices 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 53d1fcd9.

🤖 Generated with Claude Code

(written by Claude Opus 5.5)

kixelated and others added 2 commits October 30, 2026 08:19
`<[T; N]>::as_slice` and `as_mut_slice` are the reference they take: a reference to an
array of bytes is an `rt.ByteSlice` already, and to one of other values its JS array, so
writes through the slice land in the array.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title An array as a slice feat(ts): translate an array as a slice Oct 30, 2026
@kixelated
kixelated marked this pull request as ready for review October 30, 2026 15:46
@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 55 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: 385066b0-d9bb-42a9-a644-0ed56e533b56
Commits

Reviewing files that changed from the base of the PR and between 074f8b7 and 53d1fcd.

Files selected for processing: 8
  • quest/m3/README.md
  • quest/m3/ts-array-as-slice.md
  • ts/fixtures/lang/expected/arrays.ts
  • ts/fixtures/lang/expected/harness.ts
  • ts/fixtures/lang/src/arrays.rs
  • ts/fixtures/lang/src/harness.rs
  • ts/fixtures/lang/src/lib.rs
  • ts/src/lower/library.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.

@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: 89873f3

No actionable bugs found. Returning the existing array reference matches the translator's representations: byte-array references already carry ByteSlice offsets, and other array references are the mutable JS array itself. The mapping preserves writes through borrowed and nested arrays without introducing a copy or an unnecessary full-array proxy.

The small identity mapping is the right direction. The differential fixtures cover byte/non-byte elements, strings, nested arrays, empty arrays, and mutable receivers passed through another function.

Static inspection of the mapping, surrounding reference/place handling, and generated fixtures, plus an independent second pass only. I did not run translation, differential tests, or CI, and have not independently verified the reported local CI pass.

kixelated and others added 4 commits October 30, 2026 08:50
…slice

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…slice

# 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: 035e203

No actionable regression found in the changes since the previous review. After accounting for the main merges, the meaningful delta strengthens the array-as-slice fixture: rotations, nested-array copy_from_slice, empty fill, and filling a borrowed array's subslice now exercise writes through the returned slices. The generated snapshots preserve aliases, and subsequent reads/final formatting observe the mutations. The identity mapping remains the simplest appropriate implementation.

Static comparison of the published head, current base and changed fixtures/snapshots, with an independent second pass only. I did not run translation, differential tests, or CI; reported passing checks were not independently rerun.

Luke Curley and others added 2 commits October 30, 2026 09:48
# Conflicts:
#	ts/fixtures/lang/expected/harness.ts
#	ts/fixtures/lang/src/harness.rs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated merged commit e7d7f5c into main Oct 30, 2026
@kixelated
kixelated deleted the quest/m3/ts-array-as-slice branch October 30, 2026 17:02
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