Repository navigation
feat(ts): type a generic type's runs of its parameter as each instance holds them - #375
Merged
Merged
Conversation
Quest-Claim: d74d0a947b771e46
…e holds them A generic type's `[T; N]`, `[T]`, `Vec<T>`, and `Cow<[T]>` are `rt.ArrayOf<T>`, `rt.SliceOf<T>`, `rt.VecOf<T>`, and `rt.CowOf<T>`, which also hold the byte form of the `u8` instance, and each instance's read casts the field to what it holds, as `rt.Ptr` fields are. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…olds its runs Also covers a generic type JS copies and an enum of runs, at bytes, at u16, and at a type that drops, and records Rc and Arc of a slice as a follow-up quest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…yte-fields # Conflicts: # ts/fixtures/lang/expected/harness.ts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…yte-fields Drops the reject fixture's `mistyped` case, which #376 wrote through the typing gap this branch closes: no other typing gap that translation leaves to `tsc` is known. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated
marked this pull request as ready for review
November 1, 2026 07:31
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Contributor
|
quest land removed this pull request from the queue: Conflicts with the base: ts/fixtures/lang/expected/harness.ts, ts/fixtures/lang/src/harness.rs, ts/fixtures/reject/census.md, ts/fixtures/reject/mistyped.txt, ts/fixtures/reject/src/lib.rs, ts/src/lower/drop.rs |
Collaborator
Author
|
Maintainer decision, 2026-11-01: keep the four names (written by Claude Opus 5.5) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A generic type's definition typed a
[T; N],[T](behind a reference or aBox),Vec<T>, orCow<[T]>field asT[]orrt.Cow<T>. Itsu8instance stores aUint8Array, anrt.ByteSlice, anrt.ByteVec, or anrt.ByteCowthere. Translation succeeded, buttscrejected every instance's code that made or read one. Reproduced by addingRuns<u8>to the lang fixture: 16tscerrors onmain.Approach
Follows #371's
rt.Ptr:rt.ArrayOf<T>(T[] | Uint8Array),rt.SliceOf<T>(T[] | ByteSlice),rt.VecOf<T>(T[] | ByteVec), andrt.CowOf<T>(Cow<T> | ByteCow).defined_field_tyrecords these fields besidert.Ptrones (ptr_fieldsis nowinstanced_fields).held_fieldcasts each instance's read to what that instance holds, andfield_valuecasts a constructed value where a function type in the field takes one.&mutto such a field, such asmem::take(&mut runs.list), assigns through the cast.assignablenow looks throughas, which TS accepts as an assignment target.[Symbol.dispose]glue types its fields with no byte form and casts each read. Only an instance whose parameter drops runs the glue, so that parameter is neveru8.Differential test (
generics::runsin the lang fixture, against native wasm32):Runs,Run, andFixedatu8and atu16. Each is made, written through its fields and through&muts to them, copied, compared, and printed.RunsandRunof a type that logs its drops prove the glue's drop order.Impact
rt.ArrayOf<T>,rt.SliceOf<T>,rt.VecOf<T>, orrt.CowOf<T>, notT[]orrt.Cow<T>. A hand-written caller reading one casts it to its instance's form. This is breaking; there is aMIGRATE.mdentry.rt.ArrayOf,rt.SliceOf,rt.VecOf, andrt.CowOf.strs.Counted<T>'sitems: &[T]changes, tort.SliceOf<T>.Alternatives
u8instance, asgeneric_erasurerefuses anOptionof a parameter that can beundefined. Smaller, but it would refuse any generic container instantiated at bytes, which is common in moq's codecs.T[] | Uint8Array) instead of named runtime types. These read the same, but the translator could not tell them apart from other unions with bytes in them, such asOption<&[u8]>, which isrt.ByteSlice | undefined. Named types matchrt.Ptr.T[] | Uint8Array | ByteSlice | ByteVec). Fewer names, butCow<[T]>still needs its own, and the separate names say which Rust type each field is.The four runtime names are an API choice I made without asking. Rename them in review if you prefer others.
Merge with #376
mistypedcase (feat(ts): type-check the whole output before a translation succeeds #376). It wrote through this exact gap, so translation now succeeds. I found no other typing gap that translation still leaves totsc. The[T],Vec<T>,HashMap<_, Vec<T>>,Rc<RefCell<Vec<T>>>, andBox<dyn Fn(&[T])>fields, and the cases ints-ptr-replace-unreadandts-box-places, all type-check. Socheck.rs's "a bug in rust2-ts" path has no fixture until the next gap turns up. The binding check (bind/wrong.toml) still covers the sametscrun.Follow-ups
quest/m3/ts-shared-slices.md:Rc<[T]>andArc<[T]>made from aVecor a slice are refused (unsupported call to <Rc<[T]> as From<Vec<T>>>::from). That is a separate gap from this mismatch.quest/m3/ts-ptr-replace-unread.mdandquest/m3/ts-box-places.mdlook stale: their example cases translate and type-check on this branch, the latter likely since fix(ts): a &mut into a Box is the place holding the box #369. They need a/quest-auditpass; I left them untouched to keep this PR to one problem.Review
mechanical fix by codex / Codex:
Merged base, preserved both fixture sets and field-read changes, regenerated snapshots; 11 fixture tests pass, task waker differential also fails on base.(head 85740cf)quest reviewby Codex, gpt-6.1-sol, medium effort.fcfe720d: no findings.147795a414f30de6127a63b4024fd59e328ab12b, after the merge of feat(ts): type-check the whole output before a translation succeeds #376: no findings.just cipasses locally on147795a4.🤖 Generated with Claude Code