Skip to content

feat(ts): translate the rest of std the model reaches - #168

Merged
kixelated merged 14 commits into
mainfrom
quest/m2/ts-model/std-rest
Oct 28, 2026
Merged

kixelated merged 14 commits into
mainfrom
quest/m2/ts-model/std-rest

Conversation

@kixelated

@kixelated kixelated commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Works on quest/m2/ts-model/std-rest.md, which this PR rewrites to what remains: Vec/VecDeque capacity and RandomState.

Problem

The model's census (ts/moq/model.toml) still refused std calls that no other quest owns. Consumer: moq-net's model, where each shows up at the span below.

Approach

Each one maps where std's other mappings do, with std's drops and panics:

  • Vec of any element (resume.rs, origin.rs, window.rs)
    • insert and remove panic with std's messages past the end, and insert drops the value it was given as it panics.
    • truncate and clear cut first, then drop the rest in order, and keep dropping after one drop panics, as drop_in_place of a slice does.
  • Clone
    • Box<T>::clone clones what it holds (track.rs, and through Option<Box<_>>'s clone in group.rs).
    • FromUtf8Error::clone copies its bytes (coding/decode.rs).
  • Conversions
    • From<T> for Option<T> is the value, since Some(x) is x, also where None is rt.None (track.rs's impl Into<Option<_>> parameters).
    • TryInto between integers maps as TryFrom does (expiry.rs's u128 to u64).
    • to_le_bytes is the big-endian bytes reversed (origin.rs).
  • mem::size_of is the size wasm32 lays the type out in, from layout_of. Translation targets wasm32, and the differential tests' native side is wasm32 (datagram.rs, group.rs, object.rs).
  • slice::from_ref is an array of the one value, or a byte slice of it (origin.rs, including passed to Option::map as a function).
  • Option::replace is mem::replace(self, Some(value)) on the place it borrows, through the same intercept (expiry.rs, track.rs).
  • Iterators
    • max, min, max_by_key, and min_by_key take any key PartialOrd orders: tuples, Reverse, Option, references, and the crate's own types (origin.rs's route ranking, cache.rs, track.rs).
    • The pinned nightly's max_by_key is map(KeyAndValue).max(), and max is reduce(Ord::max), which tests next < best through KeyAndValue's lt, the key's. So the runtime takes the key's or item's PartialOrd::lt as #173 builds it (the crate's own where it has one), tests lt(next, best), and reads all but the first item by fold, as #172 does. An item type's own Ord::max or min, keys that drop, and items or keys that are rt.Places are refused.
    • A B-tree's Iter, Keys, Range, and the rest read their end for max and min, as std's own overrides do, comparing nothing.
    • rposition and rfind read from the back.

Proof

  • lang (differential against wasm32, 50,000 cases plus the wide sweep), new cases:
    • iters::ranked:
      • min_by_key/max_by_key of ties, by tuples of Reverse and Option, and by keys borrowing from the items.
      • Tilt, an order whose cmp leans on its first operand, so operand order shows.
      • max/min of tuples and of Tilt.
      • rposition/rfind of a partly read iterator.
    • edits case 6: Vec edits of non-Copy elements past the end, Box and Option<Box> clones, Option::from and impl Into<Option<_>>, from_ref directly and through Option::map, FromUtf8Error's clone, and size_of of structs, tuples, Option<Box<_>>, arrays, and usize.
    • ints: to_le_bytes of every width (also in the wide sweep), and TryInto from u128 and i32.
    • refs: Option::replace of a local, through a &mut parameter (an rt.Place), and of an Option<Option<u8>> whose None is rt.None.
    • collections: B-tree keys().max(), iter().min(), range(..).max(), and values().max().
  • task's edited drop scenario, through the differential test and the host unwinding test:
    • insert, remove, truncate, and clear of keys that log their drops.
    • insert past the end dropping its value.
    • max_by_key and min dropping each loser.
    • A comparison panicking in max (the item, the best, then the rest drop).
    • clear with a drop that panics.
  • Mutation checks:

Measurements

just ts census, model, at the pinned moq revision: refusals fall from 1,164 on main (95a397c, with #141's dependencies) to 1,106; moq-net from 3,804 to 3,677; kio from 397 to 387. Every std call left in the model belongs to another quest, or to what this quest keeps: Vec/VecDeque capacity, reserve, and shrink_to, and RandomState.

Impact

Public API: the translator's output and runtime.

  • Calls that were refused now translate.
  • rt.iterMax, iterMin, iterMaxByKey, and iterMinByKey take a PartialOrd::lt after the iterator and any key function, which changes the output of every max/min of integers (rt.iterMax(it, rt.cmpLt(rt.cmp))). MIGRATE.md notes it.
  • rt.ts adds vecInsert, vecRemove, vecTruncate, and fromUtf8ErrorClone. rt/iter.ts adds iterRposition and iterRfind.

Choices made without asking

  • Dropped from this quest the items the first list named that neither census refuses any more: split_last, byte-vector retain and sort, Debug of Reverse and Bound, and slicing by ..=. They have no consumer in moq-net or kio; see follow-ups.
  • Vec<u8>'s insert and remove stay refused: moq-net calls neither.
  • to_le_bytes is toBeBytes(x).reverse() in the output rather than 12 new runtime exports.
  • size_of is the wasm32 layout, inlined as a number.

Decisions

Maintainer, 2026-10-28, recorded in std-rest for their own PR:

  • Vec/VecDeque capacity: std's exact growth everywhere, with push cost measured on the TS bench.
  • RandomState: random per state, from crypto.getRandomValues.
  • Land this now without them.

The translator is moving to abort on panic in its own quest, so this PR adds no further unwinding tests; the edited scenario's panic cases go with the rest of the host unwinding tests there.

Suggested follow-ups

  • An m3 quest for std gaps without a consumer: split_last, byte-vector retain and sort, Debug of Reverse and Bound, slicing by ..=, Vec<u8>'s insert and remove, and from_le_bytes.
  • mem::take of a &mut Vec captured by a closure (origin.rs:3212) is refused as "replacing the value behind a reference". That is a closure capture of a place, not std.
  • Option::get_or_insert_default stays refused 4 times with feat(ts): lend std's &mut to values JS copies as rt.Places #149 landed: three times under its place guard (group.rs:2397, 2408, 2413, &mut Option<Vec<_>> from a match on &mut self.fields) and once as an unsupported call (origin.rs:4052). No quest owns it now that std-places has landed.

Checks on d85402f (main merged after #141): just check, just ts test, and just ts census pass.

(Written by Claude Opus 5.5)

🤖 Generated with Claude Code

kixelated and others added 6 commits October 28, 2026 02:10
Vec's insert, remove, truncate, and clear of any element; Box's and
FromUtf8Error's Clone; From into an Option; mem::size_of as wasm32 lays
the type out; to_le_bytes; TryInto between integers; slice::from_ref;
rposition and rfind; and max, min, max_by_key, and min_by_key by any
key PartialOrd orders, testing next < best as std's Ord::max and min do.
A B-tree's iterators read their ends, as std's own max and min do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e takes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…orrows

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-rest

# Conflicts:
#	ts/MIGRATE.md
#	ts/fixtures/lang/expected/harness.ts
#	ts/fixtures/lang/src/harness.rs
#	ts/runtime/rt.ts
@kixelated kixelated changed the title The rest of std the model reaches feat(ts): translate the rest of std the model reaches Oct 28, 2026
@kixelated
kixelated marked this pull request as ready for review October 28, 2026 17:08
@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-28T18:05:38.197198Z c63a213 New commits
🔒 Security Review ✅ Completed 2026-10-28T18:06:43.302641Z c63a213 New commits
ℹ️ 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: d85402f

No actionable bugs found in the changed lowering/runtime paths and relevant surrounding code. The direction is sound: reuse the existing place replacement and comparison machinery, keep unsupported representations explicit, and leave capacity/RandomState semantics to the documented follow-up rather than approximate them here. Reversing the existing byte conversion is a suitably simple implementation.

Inspected the differential fixtures for vector edits/drop ordering, comparator operand order and ties, reverse searches, nested Option replacement, clones, integer conversions and wasm32 sizes. Verification was static GitHub inspection only; I did not run tests or independently verify the reported checks.

…-rest

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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: e091c5f
Compared with my review of d85402f, accounting for the main merge.

[P2] Regenerate the fixture snapshots after merging main — ts/fixtures/lang/expected/harness.ts:18. This still imports ranked, but the merge replaced expected/iters.ts with main's version, which no longer exports that function. The Rust iters::ranked implementation and harness case are still present, so the checked-in snapshot now has a missing export and cannot match a fresh translation; just ts test compares these snapshots. Other previously added snapshot sections in expected/refs.ts and task/expected/drops.ts were also removed by the merge. Regenerate the affected fixtures with the merged translator (UPDATE_EXPECT=1 just ts test) and rerun the normal snapshot check rather than retaining main's generated files.

The underlying std-mapping direction remains sound; this is a new merge regression, not an earlier open finding. Verification: static comparison of both heads/base changes, generated imports/exports and the documented test workflow; tests were not run.

@kixelated

Copy link
Copy Markdown
Collaborator Author

Re the review of e091c5f1: agreed. The merge commit kept main's lang iters.ts, nested.ts, and refs.ts and task drops.ts snapshots: I staged before regenerating. Fixed in the next commit, which commits the regenerated snapshots; just ts test (without UPDATE_EXPECT) and just check pass on it.

(written by Claude Opus 5.5)

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

The snapshot-regression P2 from my previous review is fixed: lang/expected/iters.ts again exports ranked and supplies the comparator arguments, and the generated Option-replacement and task drop scenarios are restored. Compared against e091c5f, separating the intervening main-only merge.

No new actionable bugs found in this update. Regenerating the snapshots is the right, minimal fix; no additional runtime design change is needed. Verification was static GitHub inspection of the snapshot changes and their source/import relationships. I did not run tests or independently verify the reported just ts test/just check results.

@kixelated

Copy link
Copy Markdown
Collaborator Author

Landing c63a213.

(written by Claude Opus 5.5)

@kixelated
kixelated merged commit 5849066 into main Oct 28, 2026
1 check passed
@kixelated
kixelated deleted the quest/m2/ts-model/std-rest branch October 28, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant