Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ca4fc85
chore(quest): claim quest/m2/ts-async-spike.md
kixelated Oct 24, 2026
5b7106e
wip(ts): async spike, generators from THIR with drops
kixelated Oct 24, 2026
e4c2dc2
wip(ts): async spike, MIR state machine prototype
kixelated Oct 24, 2026
32242a1
wip(ts): async spike, hoisted generators and the handoff bench's nati…
kixelated Oct 24, 2026
a578abb
wip(ts): async spike, generators win; delete the MIR state machines
kixelated Oct 24, 2026
255148d
wip(ts): async spike cleanup: one closure path, trimmed runtime, text…
kixelated Oct 24, 2026
85f5d68
Merge remote-tracking branch 'origin/main' into quest/m2/ts-async-spike
kixelated Oct 24, 2026
2b98b68
fix(ts): census-safe drop analysis, and refuse a pattern-bound parame…
kixelated Oct 24, 2026
d64f666
Merge remote-tracking branch 'origin/main' into quest/m2/ts-async-spike
kixelated Oct 24, 2026
abc7c4c
fix(ts): an async block drops only what it owns, on the path that mov…
kixelated Oct 24, 2026
fdfa210
Merge remote-tracking branch 'origin/main' into spike-ready
kixelated Oct 24, 2026
9ae90dd
Merge remote-tracking branch 'origin/main' into spike-ready
kixelated Oct 24, 2026
8919131
test(ts): a loop broken inside a drop scope still ends its match arm
kixelated Oct 24, 2026
776680c
fix(ts): rt.spawn yields after its poll budget even when a task wakes…
kixelated Oct 24, 2026
cd567b5
fix(ts): refuse dropping a borrow of a value that drops through an un…
kixelated Oct 24, 2026
90da987
fix(ts): refuse an operand that drops ahead of an .await in the same …
kixelated Oct 24, 2026
ac957b7
fix(ts): rt.spawn rejects when a finished future panics as it drops
kixelated Oct 24, 2026
9cc359a
fix(ts): a let that binds part of a value that drops leaves the rest …
kixelated Oct 24, 2026
32a2864
fix(ts): drop a pinned box, and refuse two more drops a cancel or pat…
kixelated Oct 24, 2026
724435b
fix(ts): a ref binding borrows its place, and `let _` still evaluates…
kixelated Oct 24, 2026
3091c74
Merge remote-tracking branch 'origin/main' into spike-ready
kixelated Oct 24, 2026
a9f34f9
fix(ts): copy an async block's Copy captures, and refuse replacing an…
kixelated Oct 24, 2026
71ba587
fix(ts): a ref temporary keeps its block scoped, and see Option and P…
kixelated Oct 24, 2026
cf4d5fb
Merge remote-tracking branch 'origin/main' into spike-ready
kixelated Oct 24, 2026
afed30f
fix(ts): replace a generator's mutable borrow in place, and decide re…
kixelated Oct 24, 2026
a013edf
fix(ts): an if let takes a temporary whole from every variant, and re…
kixelated Oct 24, 2026
c4e01e7
fix(ts): read through a Box without moving it, and close two more ref…
kixelated Oct 24, 2026
bb37176
Merge remote-tracking branch 'origin/main' into quest/m2/ts-async-spike
kixelated Oct 24, 2026
b6fe796
test(ts): regenerate snapshots after merging main
kixelated Oct 24, 2026
d02598c
chore(quest): count iterators that own a value that drops in the Drop…
kixelated Oct 24, 2026
746aad6
Merge remote-tracking branch 'origin/main' into quest/m2/ts-async-spike
kixelated Oct 24, 2026
56d31c9
fix(ts): drive the task fixture's u64s through rt.u64, after #26
kixelated Oct 24, 2026
daab443
test(ts): regenerate snapshots after merging main
kixelated Oct 24, 2026
3278409
fix(ts): refuse three more drops JS would skip, from Codex's review
kixelated Oct 24, 2026
2315345
fix(ts): refuse a rest pattern that moves values that drop out of a p…
kixelated Oct 24, 2026
4f6b19b
fix(ts): refuse replacing a pinned reference through a reference
kixelated Oct 24, 2026
781a919
fix(ts): refuse an array repeat of a value that drops
kixelated Oct 24, 2026
b2965a4
fix(ts): keep a move inside the arm of a `match` or `if` that takes it
kixelated Oct 24, 2026
d51a5d7
Merge remote-tracking branch 'origin/main' into quest/m2/ts-async-spike
kixelated Oct 24, 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
5 changes: 2 additions & 3 deletions quest/m2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ is not a goal, and types must be solid at the API boundary ([design](/ts/README.

## Required

- [Async and drop spike](/quest/m2/ts-async-spike.md) - generators from THIR against MIR state machines, deciding async, drop points, and the lowering
- [MIR lowering spike](/quest/m2/ts-mir-spike.md) - the whole lowering ported to MIR on two fixtures decides whether the translator moves
- [Fail the TS benchmark when Chrome hangs](/quest/m2/ts-bench-chrome-timeout.md) - a hung renderer fails the run loudly
- [A/B routes in the TS benchmark](/quest/m2/ts-bench-routes.md) - `--route name=dir` loads another translation for reproducible A/B runs
Expand All @@ -27,8 +26,8 @@ is not a goal, and types must be solid at the API boundary ([design](/ts/README.
- [Cheaper byte slices](/quest/m2/ts-byte-views.md) - splitting a `&[u8]` stops making a `Uint8Array` view per split
- [Wide-integer fast paths](/quest/m2/ts-wide-fast.md) - a fused `from_halves` and an unboxed limb product, kept only if measured faster
- [Error-path workload](/quest/m2/ts-bench-error-path.md) - the benchmark prices `?` on a frame split across reads
- [Drop in the TypeScript translator](/quest/m2/ts-drop.md) - a `Drop` type's `drop()` runs where Rust drops it
- [Async in the TypeScript translator](/quest/m2/ts-async.md) - async code translates with Rust's lazy futures
- [Drop in the TypeScript translator](/quest/m2/ts-drop.md) - every value that drops in moq-net and kio drops where Rust drops it
- [Async in the TypeScript translator](/quest/m2/ts-async.md) - moq-net's and kio's async code translates with Rust's lazy futures
- [Shared ownership](/quest/m2/ts-shared.md) - `Arc`/`Rc`/`Weak` keep exact counts, and locks and atomics become plain values
- [Collections](/quest/m2/ts-collections.md) - maps, sets, and queues keep Rust's key semantics
- [Tree-shaking spike](/quest/m2/ts-shake-spike.md) - classes, free functions, or free functions behind root facades, measured on speed, shaken size, and caller code
Expand Down
58 changes: 0 additions & 58 deletions quest/m2/ts-async-spike.md

This file was deleted.

42 changes: 30 additions & 12 deletions quest/m2/ts-async.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
# [L] Async in the TypeScript translator
# [M] Async in the TypeScript translator

## Goal

[rust2-ts](/ts/README.md) translates `async fn`, `.await`, and the `Future` and `Waker`
machinery kio is built on, keeping Rust's lazy futures: nothing runs until polled.
Differential tests against native Rust prove the same poll order and results.
[rust2-ts](/ts/README.md) translates the async code in moq-net's model and kio, keeping
Rust's lazy futures: nothing runs until polled, and dropping a future cancels it.
Differential tests against native Rust prove the same polls, wakes, drops, and results.

## Plan

Decided with the maintainer on 2026-10-23: async must keep Rust's lazy futures, so
an eager `async`/`await` mapping, as rust-js makes, is out. A future is a state
machine its executor polls; JS promises can sit at the edge, for callers.

The [spike](/quest/m2/ts-async-spike.md) picks between generators and MIR state
machines; rewrite this plan to its report before starting.
Decided by the async spike ([#16](https://github.com/kixelated/rust2/pull/16)) on
2026-10-24: an async body is a generator lowered from THIR, not a state machine lowered
from MIR. MIR's were about twice as fast per await level, but would need a second
lowering of everything an async body can hold, and read as basic blocks. What landed
there: an `async fn` returns `rt.future(body, drop, ...upvars)`, whose body is a
module-level `function*` of what it captured (a generator function made per call costs
V8 about 25 times as much), `.await` is a poll loop around `yield`, and `rt.spawn` runs
a future from a microtask as a promise. The task fixture's trace test covers a
kio-shaped channel at await depths 1, 4, and 16.

What moq-net still needs, by its census at the pinned revision:

- `Poll`'s helpers (about 270 calls: `is_ready`, `is_pending`, `map`, `map_ok`,
`map_err`), `pin!` (47), `poll_fn` (51 with its `poll`), and `Box::pin` (17, a boxed
future that binds to hand-written TS at the boundary, per the
[model](/quest/m2/ts-model.md)).
- An async block that captures part of a variable (47), or borrows a number mutably
(4); async closures.
- kio's own API, reached across crates (`Pending`, `Consumer::poll`,
`Waiter::poll_future`, `Tasks`), with the atomics, `OnceLock`, and coop budget behind
it, which the model quest brings along.
- The edge: `rt.spawn`'s shape for callers, and cancelling a spawned task.

If a profile of moq's client finds await overhead, `yield*` between translated futures
would skip each level's `poll`; measure it on the [TS benchmark](/ts/README.md#bench).

Decided with the maintainer on 2026-10-24: the async spike
([#16](https://github.com/kixelated/rust2/pull/16)) merges with generators from
Expand All @@ -30,6 +49,5 @@ Public API: the translator's output for async code.

## Required

- [Async and drop spike](/quest/m2/ts-async-spike.md) - the lowering this builds on
- [MIR lowering spike](/quest/m2/ts-mir-spike.md) - rewrite to the spike's report before starting
- [Drop in the TypeScript translator](/quest/m2/ts-drop.md) - a dropped future drops its state
- [Drop in the TypeScript translator](/quest/m2/ts-drop.md) - async bodies hold the values that drop it still refuses
56 changes: 44 additions & 12 deletions quest/m2/ts-drop.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,48 @@

## Goal

[rust2-ts](/ts/README.md) translates types that implement `Drop`, which it refuses
today: each value's `drop()` runs where Rust drops it, in Rust's drop order, including
on early return, `?`, and panic, proven by differential tests against native Rust.
[rust2-ts](/ts/README.md) translates every value that drops in moq-net's model and kio:
each `drop()` runs where Rust drops it, in Rust's drop order, including on early
return, `?`, panic, and a cancelled future, proven by differential tests against
native Rust.

## Plan

Decided with the maintainer on 2026-10-23: `Drop` becomes an explicit `drop()`,
exposed as `[Symbol.dispose]` for JS callers. kio's producers close their channel
when the last one drops, so moq-net's model needs this first.
Decided by the async spike ([#16](https://github.com/kixelated/rust2/pull/16)) on
2026-10-24: drop points come from the THIR lowering's own scopes, not MIR. What landed
there: a class that drops gets `[Symbol.dispose]` as drop glue (its `Drop` impl, then
each field); a variable drops in a `finally` at the end of its scope; a move leaves
`undefined` behind, so a variable moved on some paths drops on the others. The task
fixture's trace test proves it on kio's waiters, wakers, and channels.

THIR does not say where drops happen; MIR does, after drop elaboration. The
[spike](/quest/m2/ts-async-spike.md) decides whether to read drop points from MIR
beside the THIR lowering or move the lowering itself; rewrite this plan to its
report before starting.
What still fails translation, each with its span (the reject fixture has one of each),
ranked by the census of moq-net at the pinned revision (kio's has 28 in all):

- Dropping a value whose drop no `[Symbol.dispose]` carries (657): a `Result`, an
`Option` or `Poll` of one, an enum or tuple holding one, a `Vec` of one. Each needs
glue of its own, switching on the variant.
- A method taking `self` by value that drops (155), which can't leave `this` undefined.
- A temporary that drops, unless a call or binding takes it whole (280): borrowed, a
field or index of one, a `match`, `if let`, `let`, or let chain that moves only part
of it, and a guarded arm that binds one. Rust drops it at the end of its statement, or
of the `match`.
- A `for` loop over values that drop (60): each at the end of its iteration, and the
rest on a `break`.
- An iterator that owns a value that drops (55): a `Vec` of one moved into it, or an
adaptor over items that drop. An `rt.Iter` drops nothing it skips, consumes, or still
holds when it is dropped.
- A std mapping that may discard an operand that drops (19): `bool::then_some`,
`Option::ok_or`, `map_or`, and `unwrap_or`, and `Result::ok`. Each refuses any operand
that drops today, even one it always keeps, such as `ok_or`'s option: `keeps_operands`
in `library.rs` should name the operands each mapping may discard instead.
- Struct update syntax from a value that drops (16), a closure capturing one (13), a
generic type that implements `Drop` (11), a parameter that drops bound by a pattern,
a rest pattern that moves values that drop out of a place, and an array repeat of a
value that drops.
- A value that drops, moved ahead of an `.await` in the same call (3) or in the place
an assignment writes it to, which a cancel would leave in a temporary no scope drops,
and an `Arc` or `Mutex` holding a borrow of a value that drops, which JS would drop
as the value itself.

Decided with the maintainer on 2026-10-24: the async spike
([#16](https://github.com/kixelated/rust2/pull/16)) merges with drop points from
Expand All @@ -25,9 +53,13 @@ too. Also in scope, found since: a temporary that drops and is held across an
`.await` is owned instead of refused (3 refusal sites), which needs declarations
at scope level.

Public API: the translator's output for `Drop` types.
Watch the cost: each move of a value that drops writes `undefined` to where it was, and
each scope holding one becomes a `try`/`finally`. A pass that proves a variable moved on
every path, or on none, would drop most of both; measure it on the
[TS benchmark](/ts/README.md#bench) before adding it.

Public API: the translator's output for values that drop.

## Required

- [Async and drop spike](/quest/m2/ts-async-spike.md) - where drop points come from
- [MIR lowering spike](/quest/m2/ts-mir-spike.md) - rewrite to the spike's report before starting
4 changes: 0 additions & 4 deletions quest/m2/ts-mir-spike.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,3 @@ exception would skip drops that THIR's `finally` blocks run. That its output rea
basic blocks no longer counts against it.

Public API: none unless the translator moves; then its whole output.

## Required

- [Async and drop spike](/quest/m2/ts-async-spike.md) - the task fixture, its trace test, and the THIR lowering this compares against
6 changes: 6 additions & 0 deletions quest/m2/ts-shared.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Decided with the maintainer on 2026-10-23: deterministic reference counts in
`rt.ts`, not GC-backed `WeakRef`. kio's `WaiterList` frees slots when
`Weak::upgrade` fails and reads `weak_count`, so drop timing is observable.

The async spike ([#16](https://github.com/kixelated/rust2/pull/16)) landed what its
kio-shaped fixture needs, in `rt/task.ts`: `rt.Arc` counts strong references and
drops its value with the last, `rt.Weak` upgrades while one is left, and `rt.Mutex`
is its own guard. Left: `Rc`, `weak_count` (a dropped `Weak` counts nothing yet),
`RwLock`, atomics, `OnceLock`, `Cell`, and `RefCell`.

- `Send` and `Sync` bounds have no meaning in JS; accept them.
- Keep Rust's failure modes where they are defined: a `RefCell` double borrow
panics. A re-entrant `Mutex` lock on one thread is unspecified in Rust; pick
Expand Down
4 changes: 4 additions & 0 deletions ts/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading