Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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 @@ -51,5 +51,4 @@ Public API: the translator's output for moq-net's model.
- [The rest of std the model reaches](/quest/m2/ts-model/std-rest.md) - `Vec` and `VecDeque` capacity, and `RandomState`
- [hashbrown as the runtime's map](/quest/m2/ts-model/hashbrown.md) - hashlink's `hashbrown` tables translate as `rt.HashMap`, with std's capacity
- [A write through a mutable reference to a library object](/quest/m2/ts-model/library-place.md) - `*r = v` out of an `Option` writes the slot, not a copy, and `mem::take` of a `&mut Vec` and writes through guards and map lookups translate
- [bytes' BytesMut, Buf, and BufMut](/quest/m2/ts-model/bytes.md) - map without config, so the model's `BytesMut` binding goes
- [Async in the TypeScript translator](/quest/m2/ts-async.md) - kio's producers and consumers are futures
22 changes: 0 additions & 22 deletions quest/m2/ts-model/bytes.md

This file was deleted.

2 changes: 2 additions & 0 deletions quest/m3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ generic std gap is planned here even when moq never calls it.
- [Relink without rebuilding](/quest/m3/relink.md) - measure upstream's skip of dependency-only rebuilds on moq's edits once it reaches nightly
- [Unsafe code the translator can model](/quest/m3/ts-unsafe.md) - a dependency using only `unsafe` the translator can model translates from source
- [f32](/quest/m3/ts-f32.md) - `f32` and `Duration`'s `f32` methods translate as `f64` does
- [A mutable reference to a reference](/quest/m3/ts-mut-ref.md) - `&mut &[u8]` and `&mut &mut T` translate, so `Buf` of a `&[u8]` and `bytes`' forwarding impls do
- [The capacity of a BytesMut](/quest/m3/ts-bytes-capacity.md) - `BytesMut::capacity` and what reads it translate with `bytes`' values
- [Trait objects](/quest/m3/ts-dyn.md) - `dyn Error`, `dyn Iterator`, and `dyn Buf` translate, so a consumer neither rewrites nor binds them
- [Waiting: type-check in process with tsrs](/quest/m3/ts-tsrs.md) - rust2-ts checks bindings through tsrs instead of `tsc` once it is a stable library
- [An inclusive range folded through an adaptor](/quest/m3/ts-range-fold.md) - a `RangeInclusive` folded through `map`, `filter`, or `rev` ends in core's state, and `by_ref` of one type-checks
Expand Down
25 changes: 25 additions & 0 deletions quest/m3/ts-bytes-capacity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# [M] The capacity of a BytesMut

## Goal

[rust2-ts](/ts/README.md) translates `BytesMut::capacity`, `split_off`, `try_reclaim`,
`try_unsplit`, and `spare_capacity_mut` with `bytes`' values, and `rt.BytesMut` drops its
512 MiB limit on `reserve` for storage that was shared, proven by differential tests
against native Rust.

## Plan

Found by [#222](https://github.com/kixelated/rust2/pull/222) on 2026-10-29: `bytes`
reclaims a `BytesMut`'s storage in `reserve` once no other handle of it is alive, so its
capacity depends on whether the `Bytes` it froze and the handles it split off dropped.
`rt.ByteSlice`, which a `Bytes` is, is a value JS copies and counts no drops, so #222
refuses these. moq calls none of them. For the same reason, once its storage was shared
or taken from a `Bytes`, `reserve` throws a `rust2-ts:` error past 512 MiB, counting what
the handle read past, where `bytes`' panic, or its growing instead, depends on which
handles dropped. Exact capacity removes that limit.

- Count the live handles of a storage, as [shared ownership](/quest/m2/ts-shared.md) counts
an `Arc`'s, which makes a `Bytes` a value that drops.
- Measure the count's cost on the codec's [TS benchmark](/ts/README.md#bench).

Public API: the translator's output.
25 changes: 25 additions & 0 deletions quest/m3/ts-mut-ref.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# [M] A mutable reference to a reference

## Goal

[rust2-ts](/ts/README.md) translates a `&mut` to a reference, such as `&mut &[u8]` and
`&mut &mut T`, proven by differential tests against native Rust. Then `bytes`' `Buf` of a
`&[u8]` advances, the `Buf` and `BufMut` impls forwarding through `&mut T` translate from
`bytes`' MIR, and so does `Buf::copy_to_bytes` of a crate's own buffer, which reads it
through a `Take<&mut Self>`.

## Plan

Found by [#222](https://github.com/kixelated/rust2/pull/222) on 2026-10-29: a `&mut` to a
type JS copies is an `rt.Place`, but a reference is never one, so `&mut &[u8]` is refused
where it is made. moq-net's census refuses `<&mut &[u8] as Buf>::remaining` and
`has_remaining` and `<&[u8] as Buf>::copy_to_bytes` in `transport/memory.rs`, which writes
a `&[u8]` through `poll_write_buf<B: Buf>`.

- Writing a whole reference through it, `*r = &r[n..]`, is what `<&[u8] as Buf>::advance`
does, so a place of the reference is the likely shape, as for a value JS copies.
- Where only what the inner reference points at is read or written, as the forwarding
impls do, the outer reference could be the inner one's value instead. Measure whether
the codec's decode on the [TS benchmark](/ts/README.md#bench) cares.

Public API: the translator's output.
7 changes: 7 additions & 0 deletions quest/m3/ts-unsafe.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,12 @@ none of its own `unsafe`.
object there, judged by type over the whole program: a generic function writing a whole
`T` counts for every `T` its bounds allow. Judge by the instances translation reaches
if a consumer's pointer is refused only by that.
- A slice's pointer cast to an array's of its length, `*(s as *const [u8] as *const
[u8; N])`, which `bytes`' `Buf::get_u16` and wider read a crate's own buffer through
([#222](https://github.com/kixelated/rust2/pull/222)): the bytes keep their type, so
this reinterprets nothing. Those getters also need `<[u8]>::get` and `get_mut` of a
range, and each integer's `from_le_bytes` and `from_ne_bytes`, and `chunks_vectored`
needs `std::io::IoSlice`: 184 of moq-net's 197 refusals in `bytes`, the rest being 12
of [`f32`](/quest/m3/ts-f32.md) and one of [`&mut &[u8]`](/quest/m3/ts-mut-ref.md).

Public API: the translator's output.
2 changes: 2 additions & 0 deletions ts/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- `bytes::BytesMut` can't be bound: translation maps it, as an `rt.BytesMut`. Delete its
`[bind]` entry and the file it names.
- A binding's path names a dependency the package renames (`foo = { package = "bar" }`)
as the package does, `foo::Item`, no longer by its crate name, `bar::Item`.
- A panic aborts, as on wasm32: the output throws `rt.Panic` without running any cleanup,
Expand Down
36 changes: 32 additions & 4 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ crate translation reaches is refused, and so are two versions of one crate it re
| `pin!(x)`, `poll_fn(f)`, `future::pending()` | `x`; `rt.PollFn`, which drops `f` with itself; `rt.NEVER` |
| `Box::pin(x)`, `dyn Future<Output = T>` | `x`; `rt.Future<T>`: an `async` body or std's future as it is, and another future as an `rt.DynFuture` over its `poll`, which drops it with itself unless borrowed |
| `bytes::Bytes` | `rt.ByteSlice`, as `&[u8]` is: its clones and slices share bytes that never change |
| `bytes::BytesMut` | `rt.BytesMut`: a window of storage, which what it splits off and freezes share without overlapping |
| `rand::rngs::ThreadRng` | `rt.ThreadRng`, which holds no state |

`Vec<u8>` storage and `[x; N]` byte arrays up to 1 KiB share 8 KiB `ArrayBuffer`s, as Node's
Expand Down Expand Up @@ -308,9 +309,32 @@ of them:
- `bytes::Bytes` is an `rt.ByteSlice`. Its constructors, `len`, `is_empty`, `slice`,
`Clone`, `Deref`, `AsRef`, `PartialEq` with bytes, `Default`, `Debug`, and `From`
between it and `Vec<u8>`, `String`, `&'static [u8]`, and `&'static str` map to
`rt/bytes.ts`, panicking as `bytes` does. `Bytes::from_owner` reads its owner's bytes
once, as `bytes` does, and is refused for an owner that drops, which would drop with the
last clone of what it makes.
`rt/bytes.ts`, panicking as `bytes` does, and so do `split_to`, `split_off`,
`truncate`, `clear`, and `slice_ref`, whose panic names no addresses. `slice_ref` of
bytes from other storage throws, since Rust may share what JS copied, as a `&'static
str`'s bytes that `as_bytes` encodes anew. `Bytes::from_owner`
reads its owner's bytes once, as `bytes` does, and is refused for an owner that drops,
which would drop with the last clone of what it makes.
- `bytes::BytesMut` is an `rt.BytesMut`: a window of storage that the handles `split_to`
and `split` make and the `Bytes` that `freeze` makes share without overlapping, as
`bytes`' do. Its constructors, `len`, `is_empty`, `freeze`, `split_to`, `split`,
`truncate`, `clear`, `resize`, `reserve`, `extend_from_slice`, `unsplit`, `Clone`,
`Deref`, `DerefMut`, `AsRef`, `AsMut`, `PartialEq` with bytes, `Default`, `Debug`, and
`From` between it and `Bytes`, `Vec<u8>`, `&[u8]`, and `&str` map, panicking as `bytes`
does. A handle never split nor taken from a `Bytes` is a vector that grows and panics
as `Vec` does, counting the bytes it read past. Once its storage was shared, `bytes`'
capacity depends on whether the other handles of it dropped, such as a `Bytes` it froze,
which nothing here counts: its `reserve` throws past 512 MiB, counting what it read
past, where `bytes`' panic depends on that, and its capacity is refused, as are
`split_off`, `try_reclaim`, `try_unsplit`, and `spare_capacity_mut`, which read it.
- `Buf` and `BufMut` of a `Bytes`, a `BytesMut`, a `&[u8]`, and a `Vec<u8>` map: the
required methods, `has_remaining`, `copy_to_slice`, `copy_to_bytes`, each `get_` and
`put_` of an integer or `f64`, `put_slice`, `put_bytes`, and `put`, whose panics are
`bytes`'. `put` of the crate's own `Buf` into a `Vec<u8>` reads it through its methods
as `bytes` does, and into a `BytesMut` is refused, as `bytes` picks those methods by its
capacity.
The rest of `bytes`, such as the provided methods of the crate's own `Buf` and the impls
forwarding through a `&mut` or a `Box`, translates from its MIR, refused where that is.
- `rand::rng()` is an `rt.ThreadRng`, whose `random` of an integer or `bool` and
`random_range` of an integer range map to `rt/rand.ts`. Each value comes from
`crypto.getRandomValues`, uniform as `rand`'s are, though no seed reproduces them, as
Expand Down Expand Up @@ -602,7 +626,11 @@ built natively for wasm32 and run beside its translation on the same inputs by
- `stock` calls `bytes`, `rand`, and `tracing` with no config, against native Rust, whose
`rand::rng()` reads the fixture's own getrandom backend on wasm32. It checks `Bytes`'s
slices and panics, how each is made and printed, that no event evaluates a field, and
that each random value is in its range, every value of a small range drawn.
that each random value is in its range, every value of a small range drawn. It splits,
freezes, grows, and writes a `BytesMut` by ops its input picks, ending with every
piece's bytes, and reads and writes through `Buf` and `BufMut` generically, a buffer of
its own included. `caller.ts` names the inputs that reserve at the edges of
`BytesMut`'s 512 MiB limit.
- `bind` binds `buf::Blob`, a renamed dependency's type with `unsafe` inside, and a function and a type of its own that read through raw
pointers, the type dropping an `Arc` where Rust drops it, to the TS in `bind/`. Its
differential test runs them against native Rust. `wrong.toml` binds TS that doesn't match
Expand Down
Loading