Skip to content

fix(ts): view a Vec by its own element type - #158

Merged
kixelated merged 2 commits into
mainfrom
quest/m1/ts-vec-view
Oct 28, 2026
Merged

kixelated merged 2 commits into
mainfrom
quest/m1/ts-vec-view

Conversation

@kixelated

@kixelated kixelated commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

vec_view decided whether a Vec is bytes from the Vec's type, but Vec::as_slice/as_mut_slice passed it the element type T. With T an ADT, vec_view read T's own first type argument:

  • Vec<String> (or any argument-less ADT): rustc ICE on type_at(0). This is what just ts census hit at moq-dev/moq@c764ace in #144.
  • Vec<Vec<u8>>, Vec<Wrap<u8>>: silently emitted rt.byteVecSlice(...) over a JS array, a miscompile on any pin.

Reproduced on main with the new fixture cases: the String case panicked, and with it removed tsc rejected byteVecSlice over ByteVec[] and Wrap<u8>[].

Approach

vec_view now takes the element type, which all three callers already have (as_slice's T, Deref's Vec argument, and Index's elem_ty). It drops its "a Vec or its element" guess, so no caller can mix the two up again. The other ty::Adt(_, args) helpers (elements, etc.) are only reached with Vec types and were already correct.

The lang fixture's vecs adds as_slice/as_mut_slice on Vec<u8> (a write through the mutable view), Vec<Vec<u8>>, Vec<Wrap<u8>> (a write through the mutable view), and Vec<String>, checked differentially against native.

Finishes quest/m1/ts-vec-view.md and drops its link from quest/m1/ts-utf8.md.

Impact

  • Translator output only: Vec::as_slice/as_mut_slice of a non-byte Vec is now the array itself, and no longer an ICE. No exported Rust API changes, no MIGRATE.md.

Alternatives

  • Keep vec_view taking the Vec type and build Vec<T, A> in the as_slice arm. That keeps the ambiguous "either type" fallback, so the same bug stays easy to reintroduce.

Follow-ups

  • <[T]>::last_mut is 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 census at 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)

kixelated and others added 2 commits October 27, 2026 23:43
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>
@kixelated kixelated changed the title Vec views of the right type fix(ts): view a Vec by its own element type Oct 28, 2026
@kixelated
kixelated marked this pull request as ready for review October 28, 2026 07:17
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T07:18:55.762743Z 17886f8 Draft marked ready
🔒 Security Review ✅ Completed 2026-10-28T07:20:25.407703Z 17886f8 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 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.

@kixelated

Copy link
Copy Markdown
Collaborator Author

Merging 17886f8: Codex reviewed this head (code and security) with no findings, Check passed, and quest check --base origin/main passed on the head. No changes since the review, and nothing left to decide. Follow-up from the body: <[T]>::last_mut is unsupported, to be planned via /quest-plan.

(Written by Claude Opus 5.5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant