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
14 changes: 8 additions & 6 deletions quest/m2/ts-shared.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ Decided with the maintainer on 2026-10-23: deterministic reference counts in
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`.
is its own guard. `rt.Atomic` holds a `bool` or an integer, and its operations check
their orderings as std does. Left: `Rc`, `weak_count` (a dropped `Weak` counts nothing
yet), `RwLock`, `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
a loud failure (panic) and document it.
- The census of moq-net's [model](/quest/m2/ts-model/README.md) on 2026-10-27 adds:
atomics as `Atomic<T>` with `Ordering` arguments (about 345 refusals, 125 in
`stats.rs`), `PoisonError::into_inner` with a lock poisoned by a panic while held,
`thread_local!` (`LocalKey::with`), `thread::panicking`, and `Mutex::get_mut`. Atomics
are 139 of kio's 172 refusals here.
`PoisonError::into_inner` with a lock poisoned by a panic while held,
`thread_local!` (`LocalKey::with`), `thread::panicking`, and `Mutex::get_mut`.
- A `static` atomic (`static NEXT: AtomicU64`, 2 in moq-net and 1 in kio) is still
refused as a constant of type `&Atomic`: a `static` with interior mutability needs one
module-level value that every use shares.
- Measure the counter overhead on the [TS benchmark](/ts/README.md#bench).

Public API: the translator's output for shared and interior-mutable types.
3 changes: 2 additions & 1 deletion ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ and each type a module of its own beside it, holding the type and its functions
(`coding/decode.Decoder.ts`), each with a `.ts.map` source map into the Rust it came
from. `rt.ts` beside them is the
runtime: what std does that JS does not, with iterators in `rt/iter.ts`, `str`'s searches
in `rt/str.ts`, collections in `rt/collections.ts`, ownership and async in
in `rt/str.ts`, collections in `rt/collections.ts`, ownership, atomics, and async in
`rt/task.ts`, `f64`'s methods in `rt/float.ts`, and `Duration` in `rt/time.ts`. What translates from std's own MIR,
`Option`'s, `Result`'s, and `Poll`'s methods, goes in a module under its crate's name, as
`core/option.ts` holds `map$Option_u64_u64_rescale_closure0`.
Expand Down Expand Up @@ -91,6 +91,7 @@ in `rt/str.ts`, collections in `rt/collections.ts`, ownership and async in
| a type that drops | a class with `[Symbol.dispose]`: its `Drop` impl, then its fields |
| a type's function | a function of the type's module, taking `self` first: `Decoder.slice(dec, 4)` after `import * as Decoder` |
| `Arc<T>`, `Weak<T>`, `Mutex<T>` | `rt.Arc`, counted; `rt.Weak`; `rt.Mutex`, its own guard |
| `AtomicU32` and the others of `bool` and integers | `rt.Atomic<T>`, the `rt.Place` of its value; an `atomic::Ordering` is its discriminant, and one an operation can't take panics as std's does |
| `async fn` | a function returning `rt.Future<T>`: a class of its own, its coroutine's state machine |
| `Poll<T>`, `Waker`, `Context` | `T \| typeof rt.Pending`, refused if `T` can already be pending; `rt.Waker`, which is also the context |
| `pin!(x)`, `poll_fn(f)`, `future::pending()` | `x`; `rt.PollFn`, which drops `f` with itself; `rt.NEVER` |
Expand Down
16 changes: 16 additions & 0 deletions ts/fixtures/lang/expected/atomics.Stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Generated by rust2-ts. Do not edit.

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

export function default$Default(): Stats {
return { sent: new rt.Atomic(0), open: new rt.Atomic(false), peers: new rt.Atomic(0) };
}

/** Counters shared by `Arc`, in fields, as moq-net's stats are. */
export interface Stats {
sent: rt.Atomic<rt.u64>;
open: rt.Atomic<boolean>;
peers: rt.Atomic<rt.usize>;
}

//# sourceMappingURL=atomics.Stats.ts.map
Loading