Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
06e447d
chore(quest): claim quest/m2/ts-model/std-more.md
kixelated Oct 27, 2026
f04e960
wip(ts): std wrappers, slices, and str gaps
kixelated Oct 27, 2026
9961d74
feat(ts): translate saturating_mul, wrapping_mul, div_ceil, is_multip…
kixelated Oct 27, 2026
af05f2c
wip(ts): std-more fixtures, unwind tests, RangeInclusive stepping, an…
kixelated Oct 27, 2026
15ac882
Merge remote-tracking branch 'origin/main' into quest/m2/ts-model/std…
kixelated Oct 27, 2026
f1f19ef
wip(ts): move now-translated reject cases into lang
kixelated Oct 27, 2026
679de2e
chore(quest): finish quest/m2/ts-model/std-more.md
kixelated Oct 27, 2026
dd1818c
Merge remote-tracking branch 'origin/main' into quest/m2/ts-model/std…
kixelated Oct 27, 2026
5172a23
fix(ts): keep each element when a merge's comparator panics, and empt…
kixelated Oct 27, 2026
66e903f
Merge remote-tracking branch 'origin/main' into quest/m2/ts-model/std…
kixelated Oct 27, 2026
a3b072d
fix(ts): refuse Bound::copied rather than call Clone
kixelated Oct 27, 2026
ff7ce0e
Merge remote-tracking branch 'origin/main' into quest/m2/ts-model/std…
kixelated Oct 27, 2026
29b6c28
fix(ts): compare by PartialOrd's tests as std's sorts and Ord's defau…
kixelated Oct 27, 2026
c162134
Merge remote-tracking branch 'origin/main' into quest/m2/ts-model/std…
kixelated Oct 28, 2026
b49b28f
fix(ts): reach the edited drops scenario, and unwind clamp and split_…
kixelated Oct 28, 2026
a2ec291
Merge remote-tracking branch 'origin/main' into quest/m2/ts-model/std…
kixelated Oct 28, 2026
241faac
fix(ts): refuse hashing a slice of a type with its own hash_slice
kixelated Oct 28, 2026
46a37be
Merge remote-tracking branch 'origin/main' into HEAD
kixelated Oct 28, 2026
4905113
Merge remote-tracking branch 'origin/main' into quest/m2/ts-model/std…
kixelated Oct 28, 2026
74ce336
Merge remote-tracking branch 'origin/main' into HEAD
kixelated Oct 28, 2026
69e429d
Merge remote-tracking branch 'origin/main' into quest/m2/ts-model/std…
kixelated Oct 28, 2026
2e57ef9
Merge remote-tracking branch 'origin/main' into HEAD
kixelated Oct 28, 2026
ae497e5
Merge remote-tracking branch 'origin/main' into quest/m2/ts-model/std…
kixelated Oct 28, 2026
0e2c4f0
Merge remote-tracking branch 'origin/main' into quest/m2/ts-model/std…
kixelated Oct 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion quest/m2/ts-model/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Public API: the translator's output for moq-net's model.

- [Shared ownership](/quest/m2/ts-shared.md) - kio's waiters are `Arc`/`Weak` with observable counts, and its atomics and locks are plain values
- [Translate safe dependencies with the package](/quest/m2/ts-model/crates.md) - kio, moq-clock, moq-pattern, and rangemap translate as one program with moq-net
- [Std gaps the model reaches](/quest/m2/ts-model/std-more.md) - ranges, wrappers, and `Vec`'s editing methods
- [Floats](/quest/m2/ts-model/floats.md) - `f64` translates, so `Bandwidth::scaled` and `Duration::mul_f64` do
- [Std's mutable references to values JS copies](/quest/m2/ts-model/std-places.md) - `as_mut`, `get_or_insert`, `iter_mut`, and the rest give an `rt.Place`
- [The rest of std the model reaches](/quest/m2/ts-model/std-rest.md) - the std calls the census still refuses
Expand Down
19 changes: 0 additions & 19 deletions quest/m2/ts-model/std-more.md

This file was deleted.

6 changes: 1 addition & 5 deletions quest/m2/ts-model/std-rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Goal

rust2-ts translates the std calls the model's census still refuses after
[std gaps](/quest/m2/ts-model/std-more.md) and [core's MIR](https://github.com/kixelated/rust2/pull/129),
[std gaps](https://github.com/kixelated/rust2/pull/124) and [core's MIR](https://github.com/kixelated/rust2/pull/129),
outside [Places](/quest/m2/ts-model/std-places.md), proven by differential tests against
native Rust.

Expand All @@ -19,7 +19,3 @@ calls core's bodies reach (`Default::default`, a payload's `Clone`).
refuses in std rather than only this list.

Public API: the translator's output.

## Required

- [Std gaps the model reaches](/quest/m2/ts-model/std-more.md) - ranges, wrappers, and `Vec`'s editing methods
21 changes: 15 additions & 6 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ in `rt/str.ts`, collections in `rt/collections.ts`, ownership and async in
| `Result<T, E>` | `rt.Result<T, E>`: `{ ok: true, value }` or `{ ok: false, error }`; `rt.OK` or `rt.ERR` where the payload is `undefined`, as in `Ok(())` |
| `ControlFlow<B, C>` | `rt.Result<C, B>`, `Ok` to continue; what `?` branches on is the value it was applied to |
| tuple, `[T; N]`, `&[T]`, `Vec<T>` | an array; for bytes, `Uint8Array` for `[u8; N]`, `rt.ByteSlice` for `&[u8]` and `&[u8; N]`, and `rt.ByteVec` for `Vec<u8>` |
| `&T`, `&mut T`, `Box<T>` | the value; a `&mut` to a value JS copies, such as a number, an `Option`, or a `String`, is an `rt.Place<T>` |
| `&T`, `&mut T`, `Box<T>`, `Reverse<T>`, `NonZero<T>` | the value; a `&mut` to a value JS copies, such as a number, an `Option`, or a `String`, is an `rt.Place<T>` |
| an iterator | `rt.Iter<Item>`, whose adaptors are runtime functions: `rt.iterMap(rt.iterSlice(v), f)` |
| `a..b`, `a..=b` | `rt.Range<T>`, `rt.RangeInclusive<T>`, which are iterators too |
| `a..`, `..b`, `..=b`, `Bound<T>` | `{ start }`, `{ end }`, `{ end, inclusive: true }`; `rt.RangeBound<T>`, a union tagged by variant |
| `HashMap`, `HashSet`, `BTreeMap`, `BTreeSet`, `VecDeque` | `rt.HashMap<K, V>` and so on, each a plain object whose functions are the runtime's: `rt.hashGet(map, key)` |
| `Ordering`, `DefaultHasher` | `rt.Ordering`, which is `-1`, `0`, or `1`; `rt.Hasher` |
| `Duration` | `rt.Duration`: `{ secs, nanos }`, std's whole seconds as an `rt.u64` and the nanoseconds past them, never changed once made |
Expand Down Expand Up @@ -143,7 +144,7 @@ std's adaptors through `rt.iterFrom`. A caller calls `next()` for one item, or i
an `rt.Iter` with `for ... of`.

A `str` is a JS string, which is UTF-16: `chars` steps by code point, and a search by a
`char`, a `&str`, or a predicate, as in `rt.strSplit(s, "/")`, takes the text or the
`char`, a `&str`, a predicate, or an array or slice of chars, as in `rt.strSplit(s, "/")`, takes the text or the
closure, which it calls on each char it reads, in the order std reads them. An offset it
returns, from `rfind` or `match_indices`, counts UTF-8 bytes, as Rust's does, and so does
one `&s[a..b]` takes, which reads the string up to it and panics as std does inside a
Expand Down Expand Up @@ -391,6 +392,11 @@ they need.
are a JS `Map`'s, the engine's own hash table; its other keys go into a second `Map`
by their translated hash, chained by `Eq`. `VecDeque` is a ring buffer over an array
whose length is a power of two.
- A slice's `sort` and `sort_unstable` are one stable merge sort of the runtime's own,
calling only the comparator, as std permits of an unstable sort: JS's `sort` moves
`undefined`, a `None`, to the end without comparing it, and each engine orders its
comparisons differently. A comparator that panics leaves each element once, in an
order std's sort would not match.
- Iterators are the runtime's lazy classes rather than generators or ES iterator
helpers: std's adaptors would lower from std's own bodies, whose slice iterators are
raw pointers, ES helpers lack most of them
Expand Down Expand Up @@ -442,7 +448,7 @@ without a mapping in `src/lower/iter.rs` (such as `cycle`, `unzip`, and `partiti
own `impl Iterator` with `next_back`, `len`, or another provided method of its own,
a pointer's address (`{:p}`), writing to a
`String` with `write!`, a `str` pattern other than a
`char`, a `&str`, or a predicate, a mutable `str` slice, a copy of a closure that changes
`char`, a `&str`, a predicate, or chars, a mutable `str` slice, a copy of a closure that changes
what it captured, `mem::swap`, `replace`, or `take` of a reference's whole pointee,
assigning an `Arc`, a waker, a `MutexGuard`, a pinned reference, or a future through a
reference, a switch on or a field of another crate's type without a mapping, and std
Expand Down Expand Up @@ -477,9 +483,11 @@ built natively for wasm32 and run beside its translation on the same inputs by
closures that log what each
adaptor reads, `Option`'s and `Result`'s combinators, with closures that log each call,
and std's collections, over keys whose own `Hash`, `Eq`, and `Ord`
disagree with JS's, `vec![x; n]` of types whose `Clone` counts its clones, and `&mut`
disagree with JS's, `vec![x; n]` of types whose `Clone` counts its clones, `&mut`
to values JS copies, of locals, fields, elements, and a map's values, passed on,
returned, kept in a struct, and captured. Its differential test runs through `caller.ts`, a
returned, kept in a struct, and captured, a `Vec`'s edits and sorts, with closures
that log what each is called with, and std's `Bound`, `Reverse`, and `NonZero`. Its
differential test runs through `caller.ts`, a
hand-written caller that also prints a `printable` error nothing translated prints,
and adds every 64- and 128-bit case over each pair of values next to a power of two,
where the runtime switches between numbers and limbs, and its limbs carry and borrow,
Expand Down Expand Up @@ -507,7 +515,8 @@ built natively for wasm32 and run beside its translation on the same inputs by

`tests/spawn.ts` checks that `rt.spawn` yields to a timer after its 128-poll budget, and
rejects when a future panics as it drops. `tests/retain.ts` panics in a collection's
`retain` at each item, and `retain_unwinds` checks that it leaves what std's leaves.
`retain` and `Vec::dedup_by` at each item, and `retain_unwinds` checks that each leaves and
drops what std's does; a sort whose comparator panics must leave each item once.

## Bench

Expand Down
12 changes: 6 additions & 6 deletions ts/fixtures/lang/expected/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1124,12 +1124,12 @@ export function stores(data: rt.ByteSlice, out: rt.ByteVec): void {
const hash: rt.HashMap<rt.u8, [rt.u8, rt.u8]> = rt.hashNew() as rt.HashMap<rt.u8, [rt.u8, rt.u8]>;
rt.hashInsert(hash, 0, copy$u8_u8(pair));
rt.hashInsert(hash, 1, copy$u8_u8(pair));
const _88: rt.Place<[rt.u8, rt.u8]> | undefined = rt.hashGetMut(hash, 0);
const _88: [rt.u8, rt.u8] | undefined = rt.hashGet(hash, 0);
if (_88 !== undefined) {
_88.v[0] = _88.v[0] ^ 1;
_88[0] = _88[0] ^ 1;
}
const _93: rt.Place<[rt.u8, rt.u8]> = rt.entryOrInsertMut(rt.entry(hash, 2), copy$u8_u8(pair));
_93.v[1] = _93.v[1] ^ 2;
const _93: [rt.u8, rt.u8] = rt.entryOrInsert(rt.entry(hash, 2), copy$u8_u8(pair));
_93[1] = _93[1] ^ 2;
rt.iterExtendBytes(out, rt.iterFlatMap(new rt.Range(0, 3), (k: rt.u8): Uint8Array => {
return mapOr$Option_u8_u8_u8s_stores_closure2_closure0(rt.hashGet(hash, k), rt.bytes(2).fill(255), (p2: [rt.u8, rt.u8]): Uint8Array => {
return Uint8Array.of(p2[0], p2[1]);
Expand All @@ -1138,9 +1138,9 @@ export function stores(data: rt.ByteSlice, out: rt.ByteVec): void {
const tree: rt.BTreeMap<rt.u8, [rt.u8, rt.u8]> = rt.btreeNew(rt.cmp) as rt.BTreeMap<rt.u8, [rt.u8, rt.u8]>;
rt.btreeInsert(tree, 0, copy$u8_u8(pair));
rt.btreeInsert(tree, 1, copy$u8_u8(pair));
const _106: rt.Place<[rt.u8, rt.u8]> | undefined = rt.btreeGetMut(tree, 1);
const _106: [rt.u8, rt.u8] | undefined = rt.btreeGet(tree, 1);
if (_106 !== undefined) {
_106.v[1] = _106.v[1] ^ 1;
_106[1] = _106[1] ^ 1;
}
rt.iterExtendBytes(out, rt.iterFlatMap(rt.btreeValues(tree), (p3: [rt.u8, rt.u8]): Uint8Array => {
return Uint8Array.of(p3[0], p3[1]);
Expand Down
15 changes: 11 additions & 4 deletions ts/fixtures/lang/expected/core/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,28 @@ export function unwrapOr$Option_Cow_str(self: string | undefined, default_: stri
return self;
}

export function unwrapOr$Option_char(self: rt.char | undefined, default_: rt.char): rt.char {
export function unwrapOr$Option_NonZero_u64(self: rt.u64 | undefined, default_: rt.u64): rt.u64 {
if (self === undefined) {
return default_;
}
return self;
}

export function unwrapOr$Option_i64(self: rt.i64 | undefined, default_: rt.i64): rt.i64 {
export function unwrapOr$Option_char(self: rt.char | undefined, default_: rt.char): rt.char {
if (self === undefined) {
return default_;
}
return self;
}

export function unwrapOr$Option_u16(self: rt.u16 | undefined, default_: rt.u16): rt.u16 {
export function unwrapOr$Option_i64(self: rt.i64 | undefined, default_: rt.i64): rt.i64 {
if (self === undefined) {
return default_;
}
return self;
}

export function unwrapOr$Option_u64(self: rt.u64 | undefined, default_: rt.u64): rt.u64 {
export function unwrapOr$Option_u16(self: rt.u16 | undefined, default_: rt.u16): rt.u16 {
if (self === undefined) {
return default_;
}
Expand Down Expand Up @@ -303,6 +303,13 @@ export function mapOr$Option_Vec_u8_u8_library_closure5(self: rt.ByteVec | undef
return f(self);
}

export function mapOr$Option_u16_u16_edits_closure21(self: rt.u16 | undefined, default_: rt.u16, f: (a0: rt.u16) => rt.u16): rt.u16 {
if (self === undefined) {
return default_;
}
return f(self);
}

export function mapOr$Option_u16_u8_hash_maps_closure0(self: rt.u16 | undefined, default_: rt.u8, f: (a0: rt.u16) => rt.u8): rt.u8 {
if (self === undefined) {
return default_;
Expand Down
20 changes: 20 additions & 0 deletions ts/fixtures/lang/expected/edits.Lean.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";

/**
* An order whose `partial_cmp` leans on its first operand, an odd one less than any, and
* whose `cmp` is by value, so what `Ord`'s defaults call, with which operand first, shows.
*/
export interface Lean {
_0: rt.u8;
}

export function partialCmp$PartialOrd(self: Lean, other: Lean): rt.Ordering | undefined {
if (rt.u8Rem(self._0, 2) === 1) {
return -1;
}
return rt.cmp(self._0, other._0);
}

//# sourceMappingURL=edits.Lean.ts.map
32 changes: 32 additions & 0 deletions ts/fixtures/lang/expected/edits.Named.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";

export function clone$Clone(self: Named): Named {
return { id: self.id, name: self.name };
}

export function eq$PartialEq(self: Named, other: Named): boolean {
if (!(self.id === other.id)) {
return false;
}
return self.name === other.name;
}

export function partialCmp$PartialOrd(self: Named, other: Named): rt.Ordering | undefined {
const cmp: rt.Ordering | undefined = rt.cmp(self.id, other.id);
if (cmp !== undefined) {
if (cmp === 0) {
return rt.cmpStr(self.name, other.name);
}
}
return cmp;
}

/** An element that is not `Copy`, cloned and compared field by field. */
export interface Named {
id: rt.u16;
name: string;
}

//# sourceMappingURL=edits.Named.ts.map
18 changes: 18 additions & 0 deletions ts/fixtures/lang/expected/edits.Stamp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";

export function partialCmp$PartialOrd(self: Stamp, other: Stamp): rt.Ordering | undefined {
return cmp$Ord(self, other);
}

export function cmp$Ord(self: Stamp, other: Stamp): rt.Ordering {
return rt.cmp(self._0, other._0);
}

/** The crate's own order, whose `min`, `max`, and `clamp` are `Ord`'s defaults. */
export interface Stamp {
_0: rt.u8;
}

//# sourceMappingURL=edits.Stamp.ts.map
15 changes: 15 additions & 0 deletions ts/fixtures/lang/expected/edits.Tally.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";

/** What `mem::take` leaves its own `Default` in place of. */
export interface Tally {
n: rt.u8;
names: string[];
}

export function default$Default(): Tally {
return { n: 7, names: ["fresh"] };
}

//# sourceMappingURL=edits.Tally.ts.map
Loading