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
1 change: 0 additions & 1 deletion quest/m3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ generic std gap is planned here even when moq never calls it.
- [Unsafe code the translator can model](/quest/m3/ts-unsafe.md) - a dependency using only `unsafe` the translator can model translates from source
- [The capacity of a BytesMut](/quest/m3/ts-bytes-capacity.md) - `BytesMut::capacity` and what reads it translate with `bytes`' values
- [Trait objects](/quest/m3/ts-dyn.md) - std's other traits, generic traits, traits with an associated type, and `Any::type_id` translate, so a consumer neither rewrites nor binds them
- [The rest of a trait object in a struct's last field](/quest/m3/ts-dyn-tail-rest.md) - a `Cell`, `UnsafeCell`, or `ManuallyDrop` of one, a `dyn Future` there, and a raw pointer to one translate
- [Placeholders written to a crate's own fmt::Write](/quest/m3/ts-fmt-calls.md) - `write!` with placeholders into a crate's own writer translates, its `write_str` seeing each call std makes
- [Waiting: drop the lang fixture's mul_add allowance](/quest/m3/ts-fma-allowance.md) - the differential fails on any `mul_add` difference again once wasm32's `fma` rounds exactly
- [Waiting: type-check in process with tsrs](/quest/m3/ts-tsrs.md) - rust2-ts checks bindings through tsrs instead of `tsc` once it is a stable library
Expand Down
29 changes: 0 additions & 29 deletions quest/m3/ts-dyn-tail-rest.md

This file was deleted.

12 changes: 9 additions & 3 deletions 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
| closure | an arrow function, with `[Symbol.dispose]` if it owns a value that drops, and what makes its clone if a clone can't be itself |
| `fn` pointer, function item as a value | the function, or std's an arrow that calls it as a written call does, as a closure is typed: a `()` result is `undefined`, where a declared function returns `void` |
| `&dyn Trait`, `&mut dyn Trait`, `Box<dyn Trait>`, `Arc<dyn Trait>`, `Rc<dyn Trait>`, `Weak<dyn Trait>`, `Pin<P>` of one | an object with the trait's methods, its supertraits' included: `shape.area$Shape()`; behind an `Arc` or an `Rc`, an `rt.ArcDyn` sharing the count of the `Arc` it was made from |
| a pointer to a struct whose last field unsizes to a trait object: `Rc<RefCell<dyn Trait>>`, `Arc<Mutex<dyn Trait>>`, `Arc<RwLock<dyn Trait>>`, the crate's own `&Tail<dyn Trait>` | `rt.tailDyn` of the struct it was made from: the same struct, whose other fields, borrows, and lock are that struct's own, and whose last field is the trait object a `&mut` to that field would be, made where it is read |
| a pointer to a struct whose last field unsizes to a trait object: `Rc<RefCell<dyn Trait>>`, `Arc<Mutex<dyn Trait>>`, `Arc<RwLock<dyn Trait>>`, `&mut Cell<dyn Trait>`, `Rc<UnsafeCell<dyn Trait>>`, `Arc<Mutex<dyn Future + Unpin>>`, the crate's own `&Tail<dyn Trait>` | `rt.tailDyn` of the struct it was made from: the same struct, whose other fields, borrows, and lock are that struct's own, and whose last field is the trait object a `&mut` to that field would be, made where it is read; a `dyn Future`'s polls the one future in place and drops it with the struct. A `ManuallyDrop<dyn Trait>` is the trait object of what it holds, which a box of it never drops |
| `dyn Error` | an object of its `fmt$Debug` and `fmt$Display`, and its `source` where a call dispatches to it: `e.source$Error()` |
| `dyn Any` | an instance of the class its value's type was wrapped in, which a downcast checks for: `a instanceof of$dyns_Square ? a.v : undefined` |
| `dyn Fn`, `dyn FnMut`, `dyn FnOnce` | the closure or function it was made of: `(a0: rt.u8) => rt.u32` |
Expand All @@ -134,7 +134,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, of what a `Box<T>` is for a slice or `str`, with its strong and weak counts, an `Arc<[u8]>` of an `Arc<str>`'s bytes sharing its count, 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 guard's `map` and `filter_map` make `rt.MutexMap`s, each where the part it lends is, which hold the mutex locked until they drop, 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 a guard's `map`, `filter_map`, `try_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; `RwLockWriteGuard::downgrade` keeps the lock as one read, and `Ref::leak` and `RefMut::leak` keep the borrow until `RefCell::undo_leak` ends it; `Cell::update` calls its function on a copy, and `RefCell::replace_with` on the value, borrowed as `borrow_mut` does, or its place where JS copies it; refused for a part of a sized type JS can't write in place, such as a binding's |
| `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 and `Cell::as_ptr`'s pointer, and `get_mut`'s reference, 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`, `try_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; `RwLockWriteGuard::downgrade` keeps the lock as one read, and `Ref::leak` and `RefMut::leak` keep the borrow until `RefCell::undo_leak` ends it; `Cell::update` calls its function on a copy, and `RefCell::replace_with` on the value, borrowed as `borrow_mut` does, or its place where JS copies it; 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 that each copy of the key is, 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 Expand Up @@ -523,7 +523,13 @@ and a `Pin` the pointer it holds. A `Weak<T>` unsized to a `Weak<dyn Trait>` kee
of what the box is, which drops it with the last clone. A pointer to a struct whose last
field unsizes to a trait object, such as `RefCell<dyn Trait>`, is an `rt.tailDyn` view of
the struct it was made from, behind an `rt.ArcDyn` in an `Arc`, and two such pointers are
equal if their views are of one struct. A `dyn Error`'s or `dyn Buf`'s object holds only
equal if their views are of one struct. A raw pointer unsized to a trait object, or to a
struct of one, is what a box of the object it points at unsizes to, which drops it as
`Box::from_raw` of it does, or what a `&mut` to its place does; one to a library value,
such as a cell, unsizes as each read finds the value there, and stays null or dangling.
One whose object would hold such a value as it is made, such as a `*mut dyn Iterator` of
a `*mut Range`, is refused. Pointers to trait objects don't compare, as each coercion
makes an object of its own. A `dyn Error`'s or `dyn Buf`'s object holds only
the methods some call through one dispatches to, so each buffer adds those of its impls,
not all of `Buf`'s; a TS caller sees the same in its type. It holds no `chunks_vectored`,
whose `IoSlice` has no JS value, so a call of it fails.
Expand Down
12 changes: 12 additions & 0 deletions ts/fixtures/lang/dyns/expected/core/task/poll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Generated by rust2-ts. Do not edit.

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

export function isReady$1ntq2i8(self: rt.Poll<rt.u8>): boolean {
if (self !== rt.Pending) {
return true;
}
return false;
}

//# sourceMappingURL=poll.ts.map
44 changes: 44 additions & 0 deletions ts/fixtures/lang/dyns/expected/dyns.Ticks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Generated by rust2-ts. Do not edit.

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

/**
* A future of the crate's own, which JS keeps as an object: pending until it has counted
* down, waking its waker each time, and noting its count as it drops.
*/
export class Ticks {
left: rt.u8;
polls: rt.u8;
log: rt.Arc<rt.RefCell<rt.ByteVec>>;

constructor(left: rt.u8, polls: rt.u8, log: rt.Arc<rt.RefCell<rt.ByteVec>>) {
this.left = left;
this.polls = polls;
this.log = log;
}

[Symbol.dispose](): void {
drop$ops_Drop(this);
this.log[Symbol.dispose]();
}
}

export function poll$Future(self: Ticks, cx: rt.Context): rt.Poll<rt.u8> {
const _3: rt.u8 = rt.u8WrappingAdd(self.polls, 1);
self.polls = _3;
const _9: rt.u8 | undefined = rt.u8CheckedSub(self.left, 1);
if (_9 === undefined) {
return self.polls;
}
self.left = _9;
cx.wakeByRef();
return rt.Pending;
}

export function drop$ops_Drop(self: Ticks): void {
const _5: rt.RefCell<rt.ByteVec> = rt.refCellBorrowMut(self.log.value);
rt.byteVecPush(_5.value, 240 | self.polls);
rt.refMutRelease(_5);
}

//# sourceMappingURL=dyns.Ticks.ts.map
Loading