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/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ Decided with the maintainer on 2026-10-24: the translator's output ranks correct
then speed, then the size of the consumer's final tree-shaken, minified JS; readability
is not a goal, and types must be solid at the API boundary ([design](/ts/README.md#design)).

Decided with the maintainer on 2026-10-26: the translator targets browsers. A native
runtime such as Node or Bun calls Rust through [rust2-ffi](/ffi/README.md), so Node and
Bun matter only as proxies for V8 and JavaScriptCore, and a speed call that splits them
from the browsers goes to the browsers.

The fork's feature quests folded into the [exporter](/quest/m1/ffi-export.md);
[m1](/quest/m1/README.md#plan) records why.

Expand Down
29 changes: 16 additions & 13 deletions quest/m2/ts-mir-size.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@
## Goal

[rust2-ts](/ts/README.md)'s bundles on `just ts bench` are no larger than the THIR
lowering's were, without giving up the speed MIR gained: the codec's at most 27483
bytes minified and 8437 gzipped, and the async handoff's at most 10901 and 3446.
lowering's were, without giving up the speed MIR gained: the codec's at most 30629
bytes minified and 9422 gzipped, and the async handoff's at most 10949 and 3458.

## Plan

At the move to MIR, the codec's bundle was 27750 bytes minified and 8876 gzipped (+1%,
+5%), and the async handoff's 18258 and 3993 (+67%, +16%), against THIR's numbers
above. Each candidate is measured on the bench's sizes and timings before it lands:
The codec's bundle is 30000 bytes minified and 9540 gzipped (+1.3% gzipped), and the
async handoff's 15119 and 3757 (+38%, +8.6%), against THIR's numbers above, built from
the same fixtures. Each candidate is measured on the bench's sizes and timings before
it lands:

- A coroutine's class, about 520 bytes minified each against about 140 for a THIR
generator: a base class in the runtime for the state and `poll` scaffolding, fields
only for what lives across an `.await`, and a resume function structured where the
graph allows (a dispatch at each loop header it enters) rather than a `switch` over
every block. Generators stay out: they measured 1.4-5.5x slower on the handoff.
- Tuple temporaries a destructuring `const [a, b] = ..` would avoid, and the `let`
list at the top of each function, where a local assigned once could be declared at
its assignment.
- A coroutine's class, about 360 bytes minified each against about 140 for a THIR
generator, for the drop, the checks for a resume after it finished, and the
`try`/`catch` that poisons it and drops what it holds on a panic, where a THIR
generator had a `finally` and the runtime's one `Async` class: a base class in the
runtime for that scaffolding, or one field for saved locals that are never live at
once (the layout's `storage_conflicts`). Each is timed in Chrome, which decides, with
the bundle minified, since what a `poll` compiles to decides how many levels V8
inlines: private fields cost Node 24 5% at depth 16 that way. Generators and closures
stay out: they measured 1.4-5.5x and 1.3-1.8x slower on the handoff.
- The handoff's code outside the classes, about 140 bytes gzipped over THIR's.
- The codec's `fill`, `encodeFrames`, and `decodeSplit`, whose blocks nest deeper than
THIR's loops did.

Expand Down
8 changes: 5 additions & 3 deletions ts/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# rust2-ts

A rustc driver that translates a subset of Rust to TypeScript with source maps. No WASM: the output is plain ES modules that Node, Bun, and bundlers run as is.
A rustc driver that translates a subset of Rust to TypeScript with source maps, for the browser. No WASM: the output is plain ES modules that bundlers take as is. A native runtime calls Rust through [rust2-ffi](/ffi/README.md) instead.

```bash
rust2-ts --config ts.toml (--out dir | --census file.md) [--manifest-path Cargo.toml] [-- cargo args]
Expand Down Expand Up @@ -173,6 +173,8 @@ Imports name the `.ts` file, which Node, Bun, and bundlers run as is. A `tsc` bu
Output is ranked correctness first, speed second, and bundle size third: the
consumer's final JS, after their bundler tree-shakes and minifies it, so type-only
constructs such as brand casts and annotations are free. Readable output is not a goal.
Speed is a browser's: `just ts bench` runs Node and Bun only as stand-ins for V8 and
JavaScriptCore, as Safari runs it, and where Node disagrees with Chrome, Chrome decides.
It stays `.ts`, so `tsc` keeps checking the internals, and minifying is the consumer's
bundler's job. Types must be solid at the API boundary: the `roots` items and
`printable` types use Rust's branded types (`rt.u64`), while internals cast as freely as
Expand Down Expand Up @@ -259,8 +261,8 @@ they need.
the coroutine transform's state machines, a class each. Against the THIR lowering it
replaced, MIR closes about 1,100 of the 1,400 drop refusals in moq-net's census, and
runs `just ts bench`'s codec 2-6% faster at the geometric mean and the async handoff
1.4-5.9x faster at depths 1 to 16 in Node, Bun, and Chrome, for 4% more gzip on the
codec's bundle and 16% on the async fixture's
1.4-5.9x faster at depths 1 to 16 in Node, Bun, and Chrome, for 1% more gzip on the
codec's bundle and 9% on the async fixture's
([size](/quest/m2/ts-mir-size.md)). Blocks become nested blocks, loops, and `if`s by
Ramsey's "Beyond Relooper", except a coroutine's resume function, which enters loops
in the middle and becomes a loop over a `switch` on the next block. Temporaries
Expand Down
Loading