Skip to content
2 changes: 1 addition & 1 deletion quest/m3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ generic std gap is planned here even when moq never calls it.
- [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
- [A zip of TrustedLen iterators folded by its size hint](/quest/m3/ts-zip-fold.md) - `count` and the other folds of a `zip` of `TrustedLen` iterators read only the pairs its size hint holds
- [A B-tree's drop order](/quest/m3/ts-btree-drop.md) - dropping a whole `BTreeMap` or `BTreeSet` drops its entries node by node, as std's does
- [Drop order in std's folds and iterators](/quest/m3/ts-drop-order.md) - the values that drop still refused in std's folds, zips, flattens, and collects drop as std's do
- [Drop order in std's folds and iterators](/quest/m3/ts-drop-order.md) - the values that drop still refused in std's consumers, zips, flattens, and collects drop as std's do
- [References to byte arrays std takes](/quest/m3/ts-byte-refs-taken.md) - `extend` by references to arrays, adaptors' closures over held arrays, and a collection of both forms translate
- [Equality of std containers of unlike elements](/quest/m3/ts-eq-unlike.md) - `==` and `next_if_eq` of a `Vec<Left>` against a `&[Right]`, and of `VecDeque` against `Vec`, translate
- [Waiting: a slice object for a mutable part of other values](/quest/m3/ts-slice-object.md) - waits on a moq profile showing the `Proxy` view's traps matter, then decides on an `rt.ByteSlice`-like form
Expand Down
46 changes: 26 additions & 20 deletions quest/m3/ts-drop-order.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,42 @@
## Goal

[rust2-ts](/ts/README.md) translates the values that drop which it still refuses
inside std's iterators and formatting, each dropping where std's does, in std's order,
inside std's iterators, each dropping where std's does, in std's order,
proven by the task fixture's differential tests against native Rust. None appears in moq's census at the pinned revision; rust2 aims to support
all of std.

## Plan

Moved from the m2 drop quest on 2026-10-27, once moq-net, its model, and kio had no
drop refusal left ([#139](https://github.com/moq-dev/rust2/pull/139)). Each is refused
with a span where std's order is one JS's can't follow yet:
drop refusal left ([#139](https://github.com/moq-dev/rust2/pull/139)). `DebugList::entries`,
ranges of bounds that drop, a drain or a B-tree's `range` of a range that drops, a hash
map's `into_keys` and `into_values`, and the closures `for_each` and `fold` own landed in
[#307](https://github.com/moq-dev/rust2/pull/307), with the task fixture's `inside` step.
Each left is refused with a span where std's order is one JS's can't follow yet:

- A closure that owns a value that drops given to a std function that takes another
value that drops by value, such as `for_each` of items that drop, that keeps it
other than in an adaptor, or that calls it through `FnOnce` other than where
`discards` in `library.rs` says, as `or_insert_with` does (`called_closures`).
- `into_keys` and `into_values` of a hash map whose other half drops: `fold` drops it
after the half it yields, `next` before.
- `zip` of two `TrustedRandomAccess` iterators of items that drop.
- A `flatten` whose inner iterator holds items once ended.
- A B-tree's `collect` of entries that drop, sorted by the crate's own `Ord`.
- `DebugList::entries` of items that drop.
- `RangeInclusive::new` of bounds that drop, such as `Arc::new(a)..=Arc::new(b)`, refused
where the range is built, found by [#247](https://github.com/moq-dev/rust2/pull/247) on
2026-10-29.
- A range that drops given to a drain or a B-tree's `range`, which std drops once it has
read the range's bounds, or at once for an empty B-tree.
value that drops by value, other than `for_each` and `fold` (`iter::releases`), such as
`reduce`, `max_by_key`, or `partition` of items that drop; one that keeps it other
than in an adaptor; or one that calls it through `FnOnce` other than where `discards`
in `library.rs` says, as `or_insert_with` does (`called_closures`). Each consumer whose
std folds takes a `release` the way `rt.iterFold` does. The reject fixture's
`called_closure` reproduces `or_insert_with`.
- `zip` of two `TrustedRandomAccess` iterators of items that drop, as the reject fixture's
`zip_dropped`, `v.iter().map(|&n| Noisy(n)).zip(0..2).count()`: std's `next` makes one
item past the shorter side and drops it, and its `next_back` trims the longer side.
- A `flatten` or `flat_map` whose inner iterator holds items once ended, as
`v.into_iter().map(|v| v.into_iter().take(1)).flatten()` of a `Vec<Vec<T>>` whose `T`
drops. std's `try_fold` keeps an ended inner iterator until the next one replaces it, or
drops it after the source once the source ends, where `next` drops it as it ends. Every
adaptor whose `try_fold` is its source's, such as `map`, `filter`'s `next`, and `rev`'s
through `try_rfold`, reads it that way, so `rt.Iter::folded` would follow through each,
a hot path to measure on the [TS benchmark](/ts/README.md#bench).
- A B-tree's `collect` of entries that drop, sorted by the crate's own `Ord`, as
`v.into_iter().collect::<BTreeSet<O>>()` of an `O` whose `Ord` is its own: an `Ord`
that disagrees with itself leaves equal keys in the order std's driftsort does, which
decides which of them drop.

Each `rt.Iter` has a `fold` and `rfold` that drop what it holds where std's do, and the
by-value consumers std folds go through it: build on those rather than `rt.drop`.

Watch the cost: measure any change to a hot path on the
[TS benchmark](/ts/README.md#bench).

Public API: the translator's output for values that drop in std's iterators.
8 changes: 4 additions & 4 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ crate translation reaches is refused, and so are two versions of one crate it re
| an iterator | `rt.Iter<Item>`, whose adaptors are runtime functions: `rt.iterMap(rt.iterSlice(v), f)` |
| `a..b`, `a..=b` | `rt.Range<T>`, `rt.RangeInclusive<T>`, which are iterators too |
| `a..`, `..b`, `..=b`, `Bound<T>` | `{ start }`, `{ end }`, `{ end, inclusive: true }`; `rt.RangeBound<T>`, a union tagged by variant |
| a range a drain or a B-tree's `range` takes | itself, or of a type other than std's ranges and a pair of `Bound`s, `rt.boundsOf` of it and its `start_bound` and `end_bound`, which the runtime calls where std's does |
| a range a drain or a B-tree's `range` takes | itself, or of a type other than std's ranges and a pair of `Bound`s, `rt.boundsOf` of it and its `start_bound` and `end_bound`, which the runtime calls where std's does; one that drops, the parameter of the call `rt.dropAfter` makes, which drops it once the call returns, as std drops it before it does anything JS can see |
| `HashMap`, `HashSet`, `BTreeMap`, `BTreeSet`, `VecDeque`, `BinaryHeap` | `rt.HashMap<K, V>` and so on, each a plain object whose functions are the runtime's: `rt.hashGet(map, key)` |
| `PeekMut<T>` | `rt.PeekMut<T>`, the `rt.Place` of a heap's greatest element, which sifts it down as it drops once `DerefMut` lent it |
| `Ordering`, `DefaultHasher`, `RandomState` | `rt.Ordering`, which is `-1`, `0`, or `1`; `rt.Hasher`; `rt.RandomState`, the keys of the `DefaultHasher` it builds, never changed once made |
Expand Down Expand Up @@ -645,9 +645,9 @@ behind `&`, `&mut`, `Box`, or `Arc` ([trait objects](/quest/m3/ts-dyn.md)), fail
hand-written TS ([bindings](#bindings)).

These fail translation: `f16` and `f128`, 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`, a std
that drops given to a std function that drops it beside another value that drops, other
than `for_each` and `fold`, as `reduce` 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`, a std
function without a mapping of its own that makes or reads an `Option` whose `None` is
`rt.None`, as `Iterator::scan` of `Option`s does, an `Option` of an `Option` of `()` or another
`Option`, an instance of a generic type whose field is an `Option` of a type parameter
Expand Down
5 changes: 4 additions & 1 deletion ts/fixtures/lang/expected/fmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,9 @@ export function wrapped(data: rt.ByteSlice, out: rt.ByteVec): void {
const held: rt.Range<rt.Arc<rt.i32>> = new rt.Range(new rt.Arc(a), new rt.Arc(b));
const _366: rt.Range<rt.Arc<Clip.Clip>> = new rt.Range(new rt.Arc(lo), new rt.Arc(hi));
const args22: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtRange(held, f, (value: rt.Arc<rt.i32>, f: rt.Formatter) => rt.i32Debug(value.value, f)), (f: rt.Formatter) => rt.fmtRange(_366, f, (value: rt.Arc<Clip.Clip>, f: rt.Formatter) => Clip.fmt$Debug(value.value, f))];
put(out, rt.fmtFormat([args22[0], " ", rt.fmtSpec({ plus: true, zero: true, width: 4 }, args22[0]), " ", args22[1]]));
const _362: string = rt.fmtFormat([args22[0], " ", rt.fmtSpec({ plus: true, zero: true, width: 4 }, args22[0]), " ", args22[1]]);
rt.dropAll([_366.start, _366.end]);
put(out, _362);
const shared: Shared.Shared = new Shared.Shared(new rt.Arc({ _0: at(7), _1: 5 }), new rt.Range(at(8) as rt.u16, 300), { end: at(9), inclusive: true });
const args24: rt.Fmt[] = [(f: rt.Formatter) => Shared.fmt$Debug(shared, f)];
put(out, rt.fmtFormat([args24[0], " ", rt.fmtSpec({ alternate: true }, args24[0])]));
Expand All @@ -707,6 +709,7 @@ export function wrapped(data: rt.ByteSlice, out: rt.ByteVec): void {
put(out, rt.fmtFormat([args26[0], " ", args26[1], " ", rt.fmtSpec({ align: ">", width: 9, precision: 2 }, args26[0])]));
t[Symbol.dispose]();
shared[Symbol.dispose]();
rt.dropAll([held.start, held.end]);
list[Symbol.dispose]();
rc[Symbol.dispose]();
nested_[Symbol.dispose]();
Expand Down
Loading