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
3 changes: 2 additions & 1 deletion quest/m3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ generic std gap is planned here even when moq never calls it.
- [Places through an adaptor's argument](/quest/m3/ts-adaptor-places.md) - `iter.zip(&mut v)` of values JS copies lends places as `for x in &mut v` does
- [std's sorts call their tests in std's order](/quest/m3/ts-sort-order.md) - `slice::sort` and a B-tree's `collect` call `lt` or `cmp` as std's driftsort does past 16 elements
- [A B-tree's searches call Ord as std's do](/quest/m3/ts-btree-search-order.md) - a B-tree's lookups and inserts call a key's own `Ord` in std's order and number
- [The rest of a guard's maps](/quest/m3/ts-guard-maps.md) - `RefMut::map`, the guards' `filter_map` and `map_split`, and an `RwLock` guard's `map` translate
- [The rest of a boxed slice's impls](/quest/m3/ts-boxed-slice-rest.md) - `clone_from`, `AsRef`, `AsMut`, `TryFrom` into a boxed array, and `Box<str>` into bytes translate for boxed slices
- [The rest of a guard's methods](/quest/m3/ts-guard-rest.md) - `Debug` of `RefCell` and `RwLock` guards, `MutexGuard::map`, and the guards' `try_map` translate
- [Aborts in the differential](/quest/m3/ts-abort-differential.md) - the lang differential compares wasm32's aborts, so an `RwLock` locked again while held is tested
- [A reversed zip's per-pair cost](/quest/m3/ts-zip-rev-overhead.md) - a reversed by-index zip costs per pair what a forward one does, or the gap is explained
14 changes: 14 additions & 0 deletions quest/m3/ts-abort-differential.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# [S] Aborts in the differential

## Goal

The lang differential compares a wasm32 abort with the translation's, so the runtime's
abort of an `RwLock` locked again while held, `rwlock locked for reading` or `for writing`,
is tested as `RefCell`'s panics are. Today wasm32's `rtabort!` traps with no panic
message, which no translation's `rt.Panic` matches, so the fixtures avoid it.

## Plan

Tell an abort from a panic on both sides: natively by the trap without a panic hook's
message, and in the runtime by a distinct error or message prefix such as std's
`fatal runtime error: ..., aborting`. Keep the comparison exact for panics.
16 changes: 0 additions & 16 deletions quest/m3/ts-guard-maps.md

This file was deleted.

15 changes: 15 additions & 0 deletions quest/m3/ts-guard-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# [S] The rest of a guard's methods

## Goal

[rust2-ts](/ts/README.md) translates what is still refused of std's guards: `Debug` of a
`Ref`, a `RefMut`, and an `RwLock`'s guards, mapped or not; `MutexGuard::map` and
`filter_map` and the `MappedMutexGuard` they make; and `Ref::try_map` and
`RefMut::try_map`. Each releases its lock or cell as std's does, proven by differential
tests against native Rust.

## Plan

The maps reuse what a `RefCell` guard's map makes: an `rt.RefMap` of where its part is,
so a write through a mapped exclusive guard reaches the value. A `MutexGuard` is its
mutex, so a mapped one needs the mutex to unlock beside the part it lends.
2 changes: 1 addition & 1 deletion ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ crate translation reaches is refused, and so are two versions of one crate it re
| a type's function | a function of the type's module, taking `self` first: `Decoder.slice(dec, 4)` after `import * as Decoder` |
| `Arc<T>`, `Rc<T>`, `Weak<T>`, `Mutex<T>` | `rt.Arc` for either, with its strong and weak counts, and `new_cyclic`'s `Weak` upgrading only once its value is made, `get_mut` lending its value only while no other `Arc` or `Weak` shares it, `make_mut` cloning it into a new `rt.Arc` while another `Arc` shares it, or moving it there while only `Weak`s do, which then dangle, and `into_inner` giving it only from the last strong `Arc`, after which its `Weak`s no longer upgrade; `rt.Weak`, counted in its `rt.Arc` until it drops, and of no `Arc` once made by `Weak::new`; `rt.Mutex`, its own guard, which a lock gives as `Ok` and the guard's drop unlocks: locking it again while held panics and `try_lock` gives `WouldBlock`, as wasm32's do, and a panic aborts, so nothing poisons it and `thread::panicking` is `false`; a `Mutex`'s, a `RefCell`'s, and an `RwLock`'s `into_inner` gives its value and `get_mut` lends it, or an `rt.Place` of it where JS copies it |
| `PoisonError<T>`, `TryLockError<T>` | the `T` it holds; `rt.TryLockError<T>`, tagged as `Bound` is |
| `Cell<T>`, `UnsafeCell<T>`, `RefCell<T>`, `RwLock<T>` | `rt.Cell`, the place holding its value in `v`, for either of the first two: `UnsafeCell::get`'s pointer is the cell where it is an `rt.Place`, and otherwise the object in `v`, refused where the crate may put another cell or object in its place; `rt.RefCell` for either of the others, its own guard, counting its borrows: borrowing it while that conflicts panics as `RefCell`'s does, and locking it so aborts as wasm32's `RwLock` does; `try_borrow` and `try_borrow_mut` fail with `rt.BorrowError` and `rt.BorrowMutError` instead, a clone borrows the cell, `Ref::clone` counts another borrow of it, and `Ref::map` makes an `rt.RefMap`, the part it lends, which releases the cell's borrow as it drops |
| `Cell<T>`, `UnsafeCell<T>`, `RefCell<T>`, `RwLock<T>` | `rt.Cell`, the place holding its value in `v`, for either of the first two: `UnsafeCell::get`'s pointer is the cell where it is an `rt.Place`, and otherwise the object in `v`, refused where the crate may put another cell or object in its place; `rt.RefCell` for either of the others, its own guard, counting its borrows: borrowing it while that conflicts panics as `RefCell`'s does, and locking it so aborts as wasm32's `RwLock` does; `try_borrow` and `try_borrow_mut` fail with `rt.BorrowError` and `rt.BorrowMutError` instead, a clone borrows the cell, `Ref::clone` counts another borrow of it, and a guard's `map`, `filter_map`, and `map_split`, an `RwLock` guard's included, make `rt.RefMap`s, each where a part it lends is, which a write through a mapped `RefMut` reaches in place, sharing the cell's borrow until the last drops; refused for a part of a sized type JS can't write in place, such as a binding's |
| `thread_local!`, `LocalKey<T>` | an `rt.LocalKey`, a module's value, which makes its value on first use from the `const` or the expression and never drops it, as wasm32's do; `with` calls its function on that value, `try_with` never fails, the `Cell` and `RefCell` helpers lower from std, and a `RefCell` key's `set` and `with_borrow_mut` borrow it as `borrow_mut` does |
| `OnceCell<T>`, `OnceLock<T>` | `rt.OnceCell` and `rt.OnceLock`, holding the `Option<T>` in `v`, which is the place `get_mut` lends where JS copies the value; a `OnceLock` initialized from within its own initialization panics, as wasm32's does, and `get_or_try_init`'s error leaves either empty |
| `Once`, `OnceState` | `rt.Once`, an `rt.OnceLock` that holds `true` once `call_once` or `call_once_force` ran its function, and panics as wasm32's does if run again from within it; `rt.OnceState`, that `Once`, which a panic never poisons, as it aborts |
Expand Down
20 changes: 19 additions & 1 deletion ts/fixtures/lang/caller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,24 @@ const guards = [
[0xf6],
].map((bytes) => Uint8Array.of(op("borrows::guards"), 0, ...bytes));

/**
* `borrows::maps` scripts: each operation through mapped, filtered, and split guards, with
* parts written whole and split parts dropped in either order, and each borrow again
* while one holds the cell, which panics.
*/
const maps = [
[0x00, 0x01, 0x02, 0x03, 0x03, 0x04, 0x05, 0x15, 0x07, 0xf1, 0xf2, 0x0b, 0x06, 0x13, 0x0c],
[0x02, 0x22, 0x0d, 0xc6],
[0x0a, 0xd6],
[0xe6],
[0x02, 0xf6],
].map((bytes) => Uint8Array.of(op("borrows::maps"), 0, ...bytes));

/** `locks::mapped` scripts: writes and reads through mapped and filtered guards. */
const mappedLocks = [[0x04, 0x01, 0x02, 0x86, 0x05, 0x0a, 0x03, 0x02, 0x80, 0x01, 0x03]].map((bytes) =>
Uint8Array.of(op("locks::mapped"), 0, ...bytes),
);

/** `locks::rwlocks` scripts: `get_mut` and `into_inner` among writes and reads. */
const rwlocks = [[6, 7, 0, 6, 2, 14, 15, 1]].map((bytes) => Uint8Array.of(op("locks::rwlocks"), 0, ...bytes));

Expand Down Expand Up @@ -766,4 +784,4 @@ const gets = [0, 0x10].flatMap((text) => {
);
});

export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...formats, ...parsed, ...singlesCases, ...singlesFormats, ...singlesParsed, ...dyns, ...cells, ...shared, ...locks, ...guards, ...rwlocks, ...onces, ...bounds, ...unsafeCells, ...edits, ...subslices, ...consumers, ...closures, ...elements, ...ranges, ...reducers, ...sliceEdits, ...drains, ...iters, ...hinted, ...peekedOthers, ...hints, ...reserves, ...setOps, ...zeros, ...writes, ...floatsMulAdds, ...singlesMulAdds, ...unlikeEqs, ...ownNes, ...rangeFroms, ...compares, ...unlikeCompares, ...rangeMethods, ...wraps(), ...refOrders, ...saturates(), ...methods(), ...separated, ...asciiCases, ...gets];
export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...formats, ...parsed, ...singlesCases, ...singlesFormats, ...singlesParsed, ...dyns, ...cells, ...shared, ...locks, ...guards, ...maps, ...mappedLocks, ...rwlocks, ...onces, ...bounds, ...unsafeCells, ...edits, ...subslices, ...consumers, ...closures, ...elements, ...ranges, ...reducers, ...sliceEdits, ...drains, ...iters, ...hinted, ...peekedOthers, ...hints, ...reserves, ...setOps, ...zeros, ...writes, ...floatsMulAdds, ...singlesMulAdds, ...unlikeEqs, ...ownNes, ...rangeFroms, ...compares, ...unlikeCompares, ...rangeMethods, ...wraps(), ...refOrders, ...saturates(), ...methods(), ...separated, ...asciiCases, ...gets];
2 changes: 1 addition & 1 deletion ts/fixtures/lang/expected/atomics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import * as rt from "./rt.ts";
import * as Stats from "./atomics.Stats.ts";
import { thenSome$0kwiij6, thenSome$0n2gkz4, thenSome$0tjggir, thenSome$1s4itlz, thenSome$0jkru5t, thenSome$0b23a33, thenSome$1af3oea, thenSome$1ugl8af, thenSome$0d5am30, thenSome$07z8k4h } from "./core/bool.ts";
import { thenSome$0kwiij6, thenSome$0n2gkz4, thenSome$0tjggir, thenSome$1s4itlz, thenSome$0jkru5t, thenSome$0d5am30, thenSome$0b23a33, thenSome$1af3oea, thenSome$1ugl8af, thenSome$07z8k4h } from "./core/bool.ts";
import { isSomeAnd$09tpccf } from "./core/option.ts";
import { unwrapOr$1pnwyus as result_unwrapOr$1pnwyus, unwrapOr$0xokg9f as result_unwrapOr$0xokg9f, unwrapOr$1imvcmw as result_unwrapOr$1imvcmw, unwrapOr$06fxvgg as result_unwrapOr$06fxvgg, unwrapOr$0gr9tn5 as result_unwrapOr$0gr9tn5, unwrapOr$0hnup9g as result_unwrapOr$0hnup9g, unwrapOr$1dnnsw8 as result_unwrapOr$1dnnsw8, unwrapOr$1k2j44a as result_unwrapOr$1k2j44a, unwrapOr$0jmm2jy as result_unwrapOr$0jmm2jy, unwrapOr$1czbd6g as result_unwrapOr$1czbd6g } from "./core/result.ts";

Expand Down
32 changes: 32 additions & 0 deletions ts/fixtures/lang/expected/borrows.Parts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";
import type * as borrows_Tagged from "./borrows.Tagged.ts";

/**
* What mapped guards lend parts of: a number and a `String`, which JS copies, a `Vec` and
* a value that logs as it drops, which it doesn't, and bytes, which a reference views.
*/
export class Parts {
n: rt.u32;
text: string;
bytes: rt.ByteVec;
tagged: borrows_Tagged.Tagged;
maybe: rt.u16 | undefined;
quad: Uint8Array;

constructor(n: rt.u32, text: string, bytes: rt.ByteVec, tagged: borrows_Tagged.Tagged, maybe: rt.u16 | undefined, quad: Uint8Array) {
this.n = n;
this.text = text;
this.bytes = bytes;
this.tagged = tagged;
this.maybe = maybe;
this.quad = quad;
}

[Symbol.dispose](): void {
this.tagged[Symbol.dispose]();
}
}

//# sourceMappingURL=borrows.Parts.ts.map
Loading