Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions quest/m2/ts-model/std-rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ the rest of what the census refused in std. Decided with the maintainer on 2026-
capacity by element size, `with_capacity` exact, `shrink_to`, and what `collect` and
`clone` allocate), through every runtime function that allocates. Measure push cost on
the TS benchmark before and after.
- An extend reserves by the size hint only once the collection is full, so its `capacity
overflow` depends on capacity. Until it is modeled, `rt.vecCapacity` takes every `Vec`,
`VecDeque`, and `BinaryHeap` an extend starts from as full, which is std's for one
`Vec::new`, `vec!`, or a `TrustedLen` collect made, but not after a `reserve` or `pop`:
replace it with the real capacity.
- `RandomState` and `BuildHasher::hash_one` landed first, in
[#261](https://github.com/moq-dev/rust2/pull/261), for hashbrown's default hasher.

Expand Down
4 changes: 3 additions & 1 deletion quest/m3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ generic std gap is planned here even when moq never calls it.
- [Drop order in std's folds and iterators](/quest/m3/ts-drop-order.md) - the values that drop still refused in std's folds, zips, flattens, and collects drop as std's do
- [Set operations](/quest/m3/ts-set-ops.md) - `union`, `intersection`, `difference`, and `symmetric_difference` of hash and B-tree sets translate
- [References to byte arrays std takes](/quest/m3/ts-byte-refs-taken.md) - `extend` by references to arrays, adaptors' closures over held arrays, and a collection of both forms translate
- [Size hints of std's iterators](/quest/m3/ts-size-hints.md) - `size_hint` translates, and `Vec`'s collect and extend panic past `isize::MAX` as std's do
- [A closure's () result as a value](/quest/m3/ts-unit-closures.md) - a closure returning `()` whose result is a value, as in a `Vec<()>` collected from `map`, type-checks
- [std accessors with no mapping](/quest/m3/ts-unmapped-accessors.md) - `VecDeque::swap_remove_*`, `HashSet::replace`, `BTreeSet::get`, `take`, and `replace`, `Vec::pop_if`, and `Arc` and `Rc::into_inner` translate
- [Equality of std containers of unlike elements](/quest/m3/ts-eq-unlike.md) - `==` and `next_if_eq` of a `Vec<Left>` against a `&[Right]`, and of `VecDeque` against `Vec`, translate
Expand All @@ -37,3 +36,6 @@ generic std gap is planned here even when moq never calls it.
- [Waiting: a slice object for a mutable part of other values](/quest/m3/ts-slice-object.md) - waits on a moq profile showing the `Proxy` view's traps matter, then decides on an `rt.ByteSlice`-like form
- [Port the workflow guard to kixelated/quest](/quest/m3/quest-workflow-guard.md) - quest's environment guard parses YAML as this repository's does
- [A parameter read only where lowering leaves nothing](/quest/m3/ts-unread-params.md) - an instance whose lowering drops every read of a parameter marks it unused, so `tsc` accepts it
- [Zero-sized values made out of sight](/quest/m3/ts-zero-sized.md) - unit structs and empty arrays returned, and std adaptors of only zero-sized fields, translate
- [Array keys a collection holds](/quest/m3/ts-array-keys.md) - collections of `[T; N]` keys type-check
- [Zip's next_back in constant time](/quest/m3/ts-zip-back.md) - a reversed zip of random-access iterators skips the longer side's excess at once
15 changes: 15 additions & 0 deletions quest/m3/ts-array-keys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# [S] Array keys a collection holds

## Goal

rust2-ts translates a `HashMap`, `HashSet`, `BTreeMap`, or `BTreeSet` of `[T; N]` keys
to TypeScript `tsc` accepts, proven by a differential test against native Rust.

## Plan

Found by `hints.rs` in the lang fixture: a collection of `[u32; 275]` keys casts its
`rt.cmpSlice` collection of `ArrayLike` keys to one of `u32[]`, which `tsc` rejects. Its
`[u8; 3]` items, collected in a function generic over them, refuse as
[ts-byte-refs-taken](/quest/m3/ts-byte-refs-taken.md) describes.

Public API: the translator's output.
20 changes: 0 additions & 20 deletions quest/m3/ts-size-hints.md

This file was deleted.

18 changes: 18 additions & 0 deletions quest/m3/ts-zero-sized.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# [M] Zero-sized values made out of sight

## Goal

rust2-ts translates the zero-sized values MIR never assigns, proven by differential tests
against native Rust: a function or closure returning a unit struct or an empty array, as
`#[derive(Clone)]` of a unit struct and `|_| [0u8; 0]` do, and a std adaptor of only
zero-sized fields, as `iter::from_fn` of a closure capturing nothing is.

## Plan

Found by `hints.rs` in the lang fixture. The first emits `return _0` of a return place
`unassigned` skips, which `tsc` rejects, and the second refuses as "constructing
`std::iter::FromFn<..>` from another crate". Once they translate, along with
[ts-unit-closures](/quest/m3/ts-unit-closures.md), `hints::reserves` covers a `Vec` of
zero-sized elements, which holds `usize::MAX`, and `hints::hints` a flatten of `[T; 0]`.

Public API: the translator's output.
15 changes: 15 additions & 0 deletions quest/m3/ts-zip-back.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# [XS] Zip's next_back in constant time

## Goal

`next_back` of a `Zip` of two `TrustedRandomAccess` iterators, such as ranges or slices,
skips the longer side's excess in constant time as std's does, rather than reading each
item, so a zip of `0..u32::MAX` with `0..1` reversed returns at once. Benchmarked.

## Plan

`rt.TrustedZipIter` inherits `ZipIter`'s trim, which calls `nextBack` once per excess item.
std reads no excess item of a side whose `MAY_HAVE_SIDE_EFFECT` is false and indexes by
position; a side that may have side effects still runs them.

Public API: the translator's output.
6 changes: 5 additions & 1 deletion ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ An iterator over a slice, array, or `Vec`, or a small range, that only its `next
moves read steps in place, as two variables: the array and an index into it, or the
range's bounds, with no `rt.Iter` made. The crate's own `impl Iterator` returns `rt.DONE` from its `next` too, and joins
std's adaptors through `rt.iterFrom`. A caller calls `next()` for one item, or iterates
an `rt.Iter` with `for ... of`.
an `rt.Iter` with `for ... of`. Each `rt.Iter`'s `sizeHint` is std's `size_hint`, its upper
bound `undefined` for `None`, and a `collect` or `extend` into a `Vec`, `VecDeque`,
`BinaryHeap`, B-tree, or hash collection reserves by it where std's does, panicking with
std's capacity overflow past the most it holds. Capacity isn't modeled, so a collection
an `extend` starts from is taken as full.

A `str` is a JS string, which is UTF-16: `chars` steps by code point, and a search by a
`char`, a `&str`, a predicate, or an array or slice of chars, as in `rt.strSplit(s, "/")`, takes the text or the
Expand Down
2 changes: 1 addition & 1 deletion ts/fixtures/bind/expected/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export function keys(input: rt.ByteSlice, bytes: Blob.Blob, out: rt.ByteVec): vo
}
rt.iterExtendBytes(out, rt.iterMap(rt.btreeKeys(ordered), (n2: Nibble.Nibble): rt.u8 => {
return Nibble.get(n2);
}));
}), undefined, true);
}

//# sourceMappingURL=harness.ts.map
2 changes: 1 addition & 1 deletion ts/fixtures/codec/expected/bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ export function ordered(data: rt.ByteSlice, out: rt.ByteVec): void {
export function order(selector: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
let v: rt.u32[] = rt.iterToArray(rt.iterMap(new rt.Range(0, rt.u64Low(rt.u64Clamp(takeU64(data)[0], 1, 65536))), (i: rt.u32): rt.u32 => {
return rt.u32Rem(rt.u32Mul(i, 40503), 1 << 16);
}));
}), undefined, 4, true);
if (selector === 0) {
rt.sliceSort(v, rt.lt);
} else if (selector === 1) {
Expand Down
16 changes: 8 additions & 8 deletions ts/fixtures/crates/expected/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,35 @@ export function run(input: rt.ByteSlice): rt.ByteVec {
const p: Point.Point = { x: input.data[input.start] as rt.i32, y: input.data[input.start + 1] as rt.i32 };
const q: Point.Point = copy$Point(p);
Point.shift(q, 1, -1);
rt.iterExtendBytes(out, rt.iterSlice(Uint8Array.of(p.x & 0xff, p.y & 0xff, q.x & 0xff, q.y & 0xff)));
rt.iterExtendBytes(out, rt.iterSlice(Uint8Array.of(p.x & 0xff, p.y & 0xff, q.x & 0xff, q.y & 0xff)), undefined, true);
}
const _29: Item.Item | undefined = heaviest$Item(rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(input)), (_2: rt.u8): Item.Item => {
return { _0: _2 };
})));
}), undefined, 1, true));
if (_29 !== undefined) {
rt.byteVecPush(out, _29._0);
}
const log: rt.Arc<rt.Mutex<rt.ByteVec>> = new rt.Arc(new rt.Mutex(new rt.ByteVec()));
const guards: Guard.Guard[] = rt.iterToArray(rt.iterMap(rt.iterTake(rt.iterSlice(rt.byteSliceView(input)), 3), (_26: rt.u8): Guard.Guard => {
return Guard.new(_26, log);
}));
}), undefined, 8, true);
const held: Guard.Guard = Guard.new(255, log);
rt.dropAll(guards);
const _late: Guard.Guard = Guard.new(254, log);
held[Symbol.dispose]();
_late[Symbol.dispose]();
const _58: rt.Mutex<rt.ByteVec> = rt.mutexLock(log.value);
const _54: rt.Iter<rt.u8> = rt.iterSlice(rt.byteSliceView(rt.byteVecSlice(_58.value)));
rt.iterExtendBytes(out, _54);
rt.iterExtendBytes(out, _54, undefined, true);
rt.mutexUnlock(_58);
if (input.length >= 3) {
const item: Item.Item = { _0: input.data[input.start] };
let n: rt.u32 = input.data[input.start + 1] as rt.u32;
const guard: Guard.Guard = Guard.new(input.data[input.start + 2], log);
const _77: Tally.Tally[] = [new Tally.Item(item), new Tally.u32$Place(rt.place(() => n, (value) => n = value)), new Tally.Guard(guard)];
const _87: Uint8Array = rt.u32ToBeBytes(tally(_77, input.data[input.start])).reverse();
rt.iterExtendBytes(out, rt.iterSlice(_87));
rt.iterExtendBytes(out, rt.iterSlice(Uint8Array.of(item._0, n & 0xff)));
rt.iterExtendBytes(out, rt.iterSlice(_87), undefined, true);
rt.iterExtendBytes(out, rt.iterSlice(Uint8Array.of(item._0, n & 0xff)), undefined, true);
const boxed: Tally.Tally[] = [new Tally.Guard(guard), new Tally.Item(item), new Tally.u32(n)];
rt.sliceSwap(boxed, 0, 2);
rt.vecTruncate(boxed, 2, rt.drop);
Expand All @@ -62,7 +62,7 @@ export function run(input: rt.ByteSlice): rt.ByteVec {
rt.dropAll(boxed);
const _133: rt.Mutex<rt.ByteVec> = rt.mutexLock(log.value);
const _129: rt.Iter<rt.u8> = rt.iterSlice(rt.byteSliceView(rt.byteVecSlice(_133.value)));
rt.iterExtendBytes(out, _129);
rt.iterExtendBytes(out, _129, undefined, true);
rt.mutexUnlock(_133);
}
const iter2: Countdown.Countdown = Countdown.new(rt.min(input.length, 4) & 0xff);
Expand All @@ -76,7 +76,7 @@ export function run(input: rt.ByteSlice): rt.ByteVec {
const kept: rt.i16[] = [(input.length << 16) >> 16, 7];
const filled: rt.i16[] = copy$i16s(kept);
Slots.fill(Slots.withBase(kept[0]), filled);
rt.iterExtendBytes(out, rt.iterSlice(Uint8Array.of(kept[0] & 0xff, kept[1] & 0xff, filled[0] & 0xff, filled[1] & 0xff)));
rt.iterExtendBytes(out, rt.iterSlice(Uint8Array.of(kept[0] & 0xff, kept[1] & 0xff, filled[0] & 0xff, filled[1] & 0xff)), undefined, true);
const _181: rt.u8 = first(input);
rt.byteVecPush(out, _181);
const _184: rt.u8 = last.last(input);
Expand Down
19 changes: 18 additions & 1 deletion ts/fixtures/lang/caller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,21 @@ const iters = Array.from({ length: 12 }, (_, kind) => [[], [2, 7, 9, 14], [0, 2,
const hintedOp = op("strs::hinted");
const hinted = Array.from({ length: 10 * 7 * 21 }, (_, i) => Uint8Array.of(hintedOp, i % 10, Math.floor(i / 10) % 7, Math.floor(i / 70)));

export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...formats, ...parsed, ...singlesCases, ...singlesFormats, ...singlesParsed, ...dyns, ...cells, ...shared, ...locks, ...onces, ...bounds, ...unsafeCells, ...edits, ...subslices, ...consumers, ...closures, ...elements, ...ranges, ...reducers, ...sliceEdits, ...drains, ...iters, ...hinted, ...peekedOthers];
/**
* `hints::hints` of each iterator, each pair of lengths, and each of its arms, read three
* times each way, with as many bytes as the first length's index.
*/
const hintsOp = op("hints::hints");
const hints = Array.from({ length: 24 * 8 * 8 * 8 * 2 }, (_, i) => {
const [kind, n, m, arm, back] = [i % 24, Math.floor(i / 24) % 8, Math.floor(i / 192) % 8, Math.floor(i / 1536) % 8, Math.floor(i / 12288)];
const steps = (arm << 5) | ((back ? 0b101 : 0b010) << 2) | 3;
return Uint8Array.of(hintsOp, kind, n, m, steps, ...Array.from({ length: n }, (_, b) => b * 37));
});

/** `hints::reserves` of each collection and element type, each shape, length, and limit on what it reads. */
const reservesOp = op("hints::reserves");
const reserves = Array.from({ length: 13 * 5 * 5 * 4 * 5 }, (_, i) =>
Uint8Array.of(reservesOp, i % 65, Math.floor(i / 65) % 5, Math.floor(i / 325) % 4, Math.floor(i / 1300)),
);

export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...formats, ...parsed, ...singlesCases, ...singlesFormats, ...singlesParsed, ...dyns, ...cells, ...shared, ...locks, ...onces, ...bounds, ...unsafeCells, ...edits, ...subslices, ...consumers, ...closures, ...elements, ...ranges, ...reducers, ...sliceEdits, ...drains, ...iters, ...hinted, ...peekedOthers, ...hints, ...reserves];
Loading