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
10 changes: 3 additions & 7 deletions quest/m2/ts-shared.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,11 @@ is its own guard and counts its borrows: a conflicting borrow panics, and a conf
lock aborts, each with wasm32's message. Their `get_mut`, `into_inner`, `try_borrow`,
`Ref::map`, and `Ref::clone` are still refused.
A `thread_local!` key is an `rt.LocalKey`, a module's value that makes its value on
first use, as wasm32's `LazyStorage` does, and never drops it. A `RefCell` key's `set`
and `with_borrow_mut` are still refused: std's bodies write through a `&mut`, which a
body of std's can't yet.
Left: `static` atomics, below, which a module's value, as a thread-local's, can hold.
first use, as wasm32's `LazyStorage` does, and never drops it. A `static` atomic is a
module's value too, an `rt.Atomic` of the value the static's memory starts with.
Left: the counters' cost, below.

- `Send` and `Sync` bounds have no meaning in JS; accept them.
- 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.
6 changes: 3 additions & 3 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ crate translation reaches is refused, and so are two versions of one crate it re
| `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; `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` |
| `PoisonError<T>`, `TryLockError<T>` | the `T` it holds; `rt.TryLockError<T>`, tagged as `Bound` is |
| `Cell<T>`, `RefCell<T>`, `RwLock<T>` | `rt.Cell`, the place holding its value in `v`; `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 |
| `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, and the `Cell` and `RefCell` helpers lower from std, except a `RefCell` key's `set` and `with_borrow_mut` |
| `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`; 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 |
| `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. A `static` one is a module's value, named for the static, that every use shares |
| `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`; `T \| rt.OuterPending` where `T` can already be pending, as `Poll<Poll<u8>>` can, so `Ready(Pending)` keeps apart from `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 Expand Up @@ -556,7 +556,7 @@ fields overlap in different types ([unsafe](/quest/m3/ts-unsafe.md)), and trait
behind `&`, `&mut`, `Box`, or `Arc` ([trait objects](/quest/m3/ts-dyn.md)), fail translation. Until they translate, an item that needs one, such as a `dyn Error`, binds to
hand-written TS ([bindings](#bindings)).

These fail translation: formatting and parsing an `f64`, and `f64::clamp`, whose panic formats them ([float formatting](/quest/m2/ts-model/floats.md)), `f32` ([`f32`](/quest/m3/ts-f32.md)), statics, async closures, a `Poll` of a `Poll` of a `Poll`, a future whose output can be pending, an instance of a generic type whose field is a `Poll` of a type parameter that can be pending, a closure that owns a value
These fail translation: formatting and parsing an `f64`, and `f64::clamp`, whose panic formats them ([float formatting](/quest/m2/ts-model/floats.md)), `f32` ([`f32`](/quest/m3/ts-f32.md)), statics other than atomics and the bytes of an immutable one, async closures, a `Poll` of a `Poll` of a `Poll`, a future whose output can be pending, an instance of a generic type whose field is a `Poll` of a type parameter that can be pending, a closure that owns a value
that drops given to a std function that drops it beside another value that drops, as
`for_each` of items that drop does, or keeps it other than in an iterator adaptor, and
values that drop in some iterators ([drop order](/quest/m3/ts-drop-order.md)), a `Cow` of other than `str`,
Expand Down
4 changes: 2 additions & 2 deletions ts/fixtures/lang/expected/core/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ export function mapOr$Option_Noisy_u8_borrows_closure0(self: Noisy.Noisy | undef
return f(self);
}

export function mapOr$Option_Noisy_u8_locals_closure12(self: locals_Noisy.Noisy | undefined, default_: rt.u8, f: (a0: locals_Noisy.Noisy) => rt.u8): rt.u8 {
export function mapOr$Option_Noisy_u8_locals_closure18(self: locals_Noisy.Noisy | undefined, default_: rt.u8, f: (a0: locals_Noisy.Noisy) => rt.u8): rt.u8 {
if (self === undefined) {
return default_;
}
Expand Down Expand Up @@ -419,7 +419,7 @@ export function mapOr$Option_Pair_u8_copies_closure0(self: Pair.Pair | undefined
return f(self);
}

export function mapOr$Option_PhantomData_u8_u8_locals_closure9(self: undefined | rt.None, default_: rt.u8, f: (a0: undefined) => rt.u8): rt.u8 {
export function mapOr$Option_PhantomData_u8_u8_locals_closure14(self: undefined | rt.None, default_: rt.u8, f: (a0: undefined) => rt.u8): rt.u8 {
if (self === rt.None) {
return default_;
}
Expand Down
2 changes: 1 addition & 1 deletion ts/fixtures/lang/expected/core/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function mapOr$Result_u8_u16_u8_results_closure7(self: rt.Result<rt.u8, r
return default_;
}

export function mapOr$Result_usize_AccessError_u8_locals_closure3(self: rt.Result<rt.usize, never>, default_: rt.u8, f: (a0: rt.usize) => rt.u8): rt.u8 {
export function mapOr$Result_usize_AccessError_u8_locals_closure8(self: rt.Result<rt.usize, never>, default_: rt.u8, f: (a0: rt.usize) => rt.u8): rt.u8 {
if (self.ok) {
return f(self.value);
}
Expand Down
Loading