Repository navigation
feat(ts): translate Vec<u8> and [u8] edits and sorts - #214
Conversation
Quest-Claim: 3c0f810a2cea45eb
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… finish the quest Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # ts/fixtures/lang/expected/harness.ts
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 28d7467
No actionable bugs found in the changed mappings and runtime paths. Reusing index-based retain/dedup helpers while lending copied elements through AtIndex is a reasonable shared fix for bytes and other scalar elements. The byte-specific paths preserve slice offsets and vector length/capacity boundaries; direct numeric typed-array sorting avoids unnecessary comparator machinery. The added differential cases cover mutation callbacks, dedup argument order, empty inputs, subslices and bounds failures.
Verification: static diff, runtime helpers, lowering/place-call handling and generated fixture inspection only. No tests, differential or mutation runs, builds or benchmarks performed; reported results were not independently reproduced. Unwind behavior was not validated.
(Written by OpenAI)
# Conflicts: # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/src/harness.rs # ts/fixtures/reject/census.md
Problem
rust2-ts refused
retain,retain_mut,dedup,dedup_by,dedup_by_key,insert,remove, andswap_removeon aVec<u8>, andlast,reverse,swap, and the six sorts on a[u8]: the mappings inlibrary.rsskippedu8elements, which are anrt.ByteVecorrt.ByteSlicerather than an array, and nothing mapped them instead. Found by #204. No moq consumer: rust2 aims to support all of std.Approach
!is_u8skip inlibrary.rsnow has a byte counterpart. Those were all of them; the otherVecand slice mappings already handled bytes.Vec<u8>: newrt.byteVecInsert,Remove,SwapRemove,Retain,RetainMut,Dedup,DedupByMut, andDedupByKeyMut, which edit theUint8Arrayin place (copyWithinfor the shifts). The representation is unchanged.[u8]:rt.byteSliceLastandrt.byteSliceSwap, besidebyteSliceFirst.reverseand thesorts without a closure call the typed array's ownreverseandsortonbyteSliceView. A typed array sorts by value, and equal bytes can't be told apart, so stability doesn't matter. The closure sorts runrt.sliceSort*over the view, which now take any indexable.retain_mut,dedup_by, anddedup_by_keygive their closure a&mut, and a byte is a value JS copies, so it has to be passed as anrt.Place.place_callnow lists those three forVec, and the mapping picks a*Mutvariant that passes anAtIndexwhenever the elementneeds_place. That fixesVec<u16>and other copied elements too, which were refused for the same reason. One problem, one mechanism, so it's in this PR.vecRetain,vecDedupBy, and the byte versions share two index-based helpers,retainAtanddedupAt, so the logic exists once.("slice", "reverse")is nowelements(s).reverse()for every element type, andrt.sliceReverseis deleted.Tests: a new
edits::bytescase in the lang fixture checks against native wasm32 (50k random cases; 495,916 in total with the exhaustive short ones):v[1..]'s sort, reverse, swap, and last);insert,remove,swap_remove,swap, and a subslice range;sort_by_keywith tied keys, and unstable sorts only by keys or comparators with no ties, so std's order is the only valid one;u16versions ofretain_mut,dedup_by, anddedup_by_key.As a mutation check, breaking
byteVecDedupByMut's argument order andbyteVecSwapRemovemade the differential report 263 differences. There are no unwind tests.rejectused<[u8]>::sortas its example of an unsupported call. It now usesrotate_left, which is still unsupported, so line numbers don't shift.Census
moq-net: 3089 → 3087 refusals (the two
<[u8]>::lastcalls inzlib-rsinflate.rs). model and kio are unchanged.Impact
Vec<u8>and[u8], andretain_mut,dedup_by, anddedup_by_keytranslate on aVecof any element JS copies.rt.byteSliceLast,rt.byteSliceSwap,rt.byteVecInsert,rt.byteVecRemove,rt.byteVecSwapRemove,rt.byteVecRetain,rt.byteVecRetainMut,rt.byteVecDedup,rt.byteVecDedupByMut,rt.byteVecDedupByKeyMut,rt.vecRetainMut,rt.vecDedupByMut, andrt.vecDedupByKeyMut.rt.sliceSort,rt.sliceSortBy, andrt.sliceSortByKeyaccept any indexable.rt.sliceReverseis removed. There's aMIGRATE.mdentry.Alternatives
byteSliceView: forlastandswapthat builds a view on each call, which costs several times aByteSlice. So those got dedicated functions likefirst; only the O(n) methods use the view.Vec<u16>::retain_mutwould still be refused for the same reason.Follow-ups
None new.
u8::rotate_leftand[u8]::rotate_leftare still unsupported; therejectfixture records the second.🤖 Generated with Claude Code
(Written by Claude Opus 5.5)