Repository navigation
fix(ts): view a Vec by its own element type - #158
Conversation
Quest-Claim: 706f0860dd4a6c97
`Vec::as_slice` passed the element type where `vec_view` expected the `Vec` type, so a `Vec<String>` panicked and a `Vec<Vec<u8>>` or `Vec<Wrap<u8>>` was viewed as bytes. `vec_view` now takes the element type, which every caller has, so the two can't be mixed up again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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: 17886f8
No actionable bugs found. The direction is sound: giving vec_view an explicit element-type contract removes the ambiguous ADT unwrapping, and the Deref and range-index callers now supply that same type. This is simpler than reconstructing a Vec type at the slice-method caller. The added fixtures cover byte-vector mutable views, nested vectors, generic wrappers and strings, with matching generated TypeScript.
Verification limits: static review of the diff, relevant lowering/call-site context and fixture output only; I did not run the Rust/TypeScript tests or census.
|
Merging (Written by Claude Opus 5.5) |
Problem
vec_viewdecided whether aVecis bytes from theVec's type, butVec::as_slice/as_mut_slicepassed it the element typeT. WithTan ADT,vec_viewreadT's own first type argument:Vec<String>(or any argument-less ADT): rustc ICE ontype_at(0). This is whatjust ts censushit at moq-dev/moq@c764ace in #144.Vec<Vec<u8>>,Vec<Wrap<u8>>: silently emittedrt.byteVecSlice(...)over a JS array, a miscompile on any pin.Reproduced on
mainwith the new fixture cases: theStringcase panicked, and with it removed tsc rejectedbyteVecSliceoverByteVec[]andWrap<u8>[].Approach
vec_viewnow takes the element type, which all three callers already have (as_slice'sT,Deref'sVecargument, andIndex'selem_ty). It drops its "aVecor its element" guess, so no caller can mix the two up again. The otherty::Adt(_, args)helpers (elements, etc.) are only reached withVectypes and were already correct.The
langfixture'svecsaddsas_slice/as_mut_sliceonVec<u8>(a write through the mutable view),Vec<Vec<u8>>,Vec<Wrap<u8>>(a write through the mutable view), andVec<String>, checked differentially against native.Finishes
quest/m1/ts-vec-view.mdand drops its link fromquest/m1/ts-utf8.md.Impact
Vec::as_slice/as_mut_sliceof a non-byteVecis now the array itself, and no longer an ICE. No exported Rust API changes, no MIGRATE.md.Alternatives
vec_viewtaking theVectype and buildVec<T, A>in theas_slicearm. That keeps the ambiguous "either type" fallback, so the same bug stays easy to reintroduce.Follow-ups
<[T]>::last_mutis refused (unsupported call to core::slice::<impl [T]>::last_mut). I hit it while writing the fixture and used indexing instead. Candidate for the std-coverage quests.Checks
just ts test --test fixtures lang: reproduced the ICE and the miscompile before the fix, passes after.just ts censusat moq-dev/moq@c764ace (feat(ffi): export moq's owned Path #144's pin): ok. At the current pin: ok.just check: ok.just ts test: ok.quest check --base origin/main: ok.just test: ok.🤖 Generated with Claude Code
(Written by Claude Opus 5.5)