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
11 changes: 7 additions & 4 deletions quest/m2/ts-shared.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
[rust2-ts](/ts/README.md) translates `Arc`, `Rc`, and `Weak` with Rust's exact
counts: `strong_count`, `weak_count`, and `upgrade` match native, and the last
strong drop runs `Drop` where Rust runs it. `Mutex`, `RwLock`, atomics,
`OnceLock`, `Cell`, and `RefCell` translate as the single-threaded values they
are in JS, proven by differential tests.
`OnceLock`, `OnceCell`, `Cell`, and `RefCell` translate as the single-threaded
values they are in JS, proven by differential tests.

## Plan

Expand All @@ -18,8 +18,11 @@ The async spike ([#16](https://github.com/kixelated/rust2/pull/16)) landed what
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. `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`.
their orderings as std does. `rt.OnceCell` and `rt.OnceLock` hold their `Option<T>`, and
a `OnceLock` initialized from within its own initialization panics as wasm32's does;
their `Clone`, `Debug`, `PartialEq`, `get_mut`, and `get_or_try_init` are still refused.
Left: `Rc`, `weak_count` (a dropped `Weak` counts nothing yet), `RwLock`, `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
Expand Down
1 change: 1 addition & 0 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ in `rt/str.ts`, collections in `rt/collections.ts`, ownership, atomics, and asyn
| 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 |
| `OnceCell<T>`, `OnceLock<T>` | `rt.OnceCell` and `rt.OnceLock`, holding the `Option<T>` in `v`; a `OnceLock` initialized from within its own initialization panics, as wasm32's does |
| `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 |
Expand Down
21 changes: 20 additions & 1 deletion ts/fixtures/lang/caller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,23 @@ const dyns = [[], [1, 2], [3, 0, 7], [255, 1, 255, 0, 1, 2, 3, 4, 5], [0, 3, 2,
Uint8Array.of(op("dyns::dyns"), 0, ...bytes),
);

export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...dyns];
/**
* `cells` scripts of (op, operand) pairs on every kind, so each cell and value type: reads
* and sets, a `None` and a `()` held, initializing from within initialization and
* panicking in it, empty and full, and a cell replaced.
*/
const cellsOp = op("cells::cells");
const cellScripts = [
[0, 0, 1, 5, 0, 0, 1, 6, 2, 7, 4, 0, 0, 0, 4, 0, 2, 9, 0, 0],
[1, 3, 0, 0, 1, 4, 4, 0, 1, 6, 2, 3],
[3, 4, 3, 5],
[5, 3],
[6, 3],
[7, 1],
[2, 1, 5, 3, 6, 3, 7, 1],
[8, 4, 0, 0, 8, 5, 0, 0, 1, 3, 8, 6],
[],
];
const cells = Array.from({ length: 256 }, (_, kind) => cellScripts.map((script) => Uint8Array.of(cellsOp, kind, ...script))).flat();

export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...dyns, ...cells];
Loading