Repository navigation
feat(ts): translate an array as a slice - #287
Conversation
Quest-Claim: fc56876c1aec3555
`<[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>
|
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 55 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: 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.
…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
left a comment
There was a problem hiding this comment.
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.
# Conflicts: # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/src/harness.rs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem
rust2-ts refused
<[T; N]>::as_sliceandas_mut_slicewith a span, as "unsupported call tostd::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.ByteSlicealready, and a reference to an array of other values is its JS array (never anrt.Place), which is also how a&[T]or&mut [T]is represented. So the slice is the array itself and writes throughas_mut_sliceland 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'sas_slice/as_mut_sliceof an element of the outer'sas_mut_slice; arrays lent by&mutto a function and written through their slices; androtate_left,rotate_right,fill, andcopy_from_slice(from #282) writing throughas_mut_slice. Mappingas_mut_sliceof other values to a copy fails that case, so it guards the writes.Impact
as_sliceandas_mut_sliceof an array translate instead of refusing. No runtime or API change.Alternatives
rt.sliceViewfor 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 aProxyper call for nothing.Follow-ups
Review
Codex
gpt-6.1-sol, medium effort, viaquest review --base origin/main, round 3 on head035e20387f11ae5a6bf6712830c3128627002763(after merging main with a hand-resolved harness conflict): no findings. Rounds 1 and 2 also reported none.just cipassed locally on that head.Merge of main at
074f8b7a(#286, #288, #289, #291) into035e2038, as53d1fcd9: ordered main'spointers::madebeforearrays::as_slicesin the case list and regeneratedharness.ts(the new case and one renumbered local). Recorded skip, too trivial to review;just cipassed on53d1fcd9.🤖 Generated with Claude Code
(written by Claude Opus 5.5)