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
13 changes: 3 additions & 10 deletions quest/m3/ts-drop-order.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,20 @@ Moved from the m2 drop quest on 2026-10-27, once moq-net, its model, and kio had
drop refusal left ([#139](https://github.com/kixelated/rust2/pull/139)). Each is refused
with a span where std's order is one JS's can't follow yet:

- A consumer that std folds (`count`, `fold`, `sum`, `collect`, ...) of an iterator
holding a closure that drops beside anything else that drops: std's `fold` drops an
adaptor's closure as its own ends, before the source, where dropping the adaptor
drops it after (`folds` and `held` in `iter.rs`).
- 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, or that a `fold` reads where
both its source and inner iterators 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`.
- A `collect` in place of a `zip` whose second iterator drops.
- `DebugList::entries` of items that drop.

The fold refusals share one fix: give each `rt.Iter` a `fold` that drops what it holds
where std's `fold` for that adaptor does (`Map` and `Filter` delegate to their source's
with their closure wrapped, `TakeWhile`, `Chain`, and `Peekable` each fold their own
way), and have by-value consumers drop through it rather than `rt.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).
Expand Down
8 changes: 8 additions & 0 deletions ts/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
- A trait object in a function's suffix is named for its trait and the types it binds:
`show$dynstdfmtDebug` is `show$dyn_Debug`, and `poll$dyn_Future_u64` is a
`dyn Future<Output = u64>`'s.
- A runtime consumer that takes an iterator by value is told whether it drops rather than
given `rt.drop`: `iterFold`, `iterForEach`, `iterSum`, `iterProduct`, `iterMax`,
`iterMin`, `iterMaxByKey`, `iterMinByKey`, and `durationSum` take `true`, and
`ownedCount` and `ownedLast` take only what drops an item. `iterToArray`,
`iterToByteVec`, `iterExtend`, `iterExtendBytes`, `dequeExtend`, `hashExtend`,
`hashExtendKeys`, `btreeExtend`, and `btreeExtendKeys` take an `rt.Take`, `"next"` or
`"fold"`, for how std's reads it; `iterToArray` takes `"place"` where its `inPlace` was
`true`.
- `rt.FromUtf8Error` holds its `rt.Utf8Error` as std's does: `e.validUpTo` and
`e.errorLen` are `e.error.validUpTo` and `e.error.errorLen`.
- The runtime no longer exports `ownedNth`, `ownedNthBack`, `ownedSkip`, `ownedTake`, or
Expand Down
3 changes: 2 additions & 1 deletion ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ std's collections, `Arc`, and the std functions that may discard an operand
where std's do. So do iterators: one that owns its items, as a `Vec`'s `into_iter` or a
map's `drain` does, drops those it still holds by `[Symbol.dispose]`, an adaptor drops
what it skips or rejects, and a consumer that takes an iterator by value drops it, a
panic included. A `Drop` impl that
panic included: through each `rt.Iter`'s own `fold` where std's folds, which drops each
adaptor's closure as its fold ends, before what it wraps, as std's does. A `Drop` impl that
panics leaves the rest to drop as Rust's does: a class's glue and the runtime's droppers
go on to the rest of the value and its container, but a hash table leaks its other
entries, as std's does.
Expand Down
219 changes: 107 additions & 112 deletions ts/fixtures/lang/expected/dyns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export function shared(data: rt.ByteSlice, out: rt.ByteVec): void {
objects = rt.iterToArray(rt.iterMap(new rt.Range(0, 3), (_2: rt.i32): rt.Arc<Shape.Shape> => {
const _34: rt.Arc<Hits.Hits> = rt.arcClone(hits);
return new rt.ArcDyn(_34, new Shape.Hits(_34.value));
}), false, undefined, rt.drop);
}), undefined, rt.drop);
unwind = 244;
_385 = true;
const sum: rt.u32 = rt.iterFold(rt.iterSlice(objects), 0, (sum2: rt.u32, s2: rt.Arc<Shape.Shape>): rt.u32 => {
Expand Down Expand Up @@ -439,12 +439,12 @@ export function shared(data: rt.ByteSlice, out: rt.ByteVec): void {
}
const _113: rt.Arc<Square.Square> = new rt.Arc({ side: x as rt.u16 });
return new rt.ArcDyn(_113, new Named.Square(_113.value));
}), false, undefined, rt.drop);
}), undefined, rt.drop);
unwind = 242;
_384 = true;
kept = rt.iterToArray(rt.iterMap(rt.iterStepBy(rt.iterSlice(tris), 2), (a0: rt.Arc<Named.Named>): rt.Arc<Named.Named> => {
return rt.arcClone(a0);
}), false, undefined, rt.drop);
}), undefined, rt.drop);
unwind = 211;
for (const _298 of tris) {
const _310: string = _298.value.label$Named();
Expand Down Expand Up @@ -504,140 +504,135 @@ export function shared(data: rt.ByteSlice, out: rt.ByteVec): void {
b15: {
b16: {
b17: {
b18: {
if (unwind === 0) {
throw e;
}
if (unwind === 206) {
break b17;
}
if (unwind === 207) {
break b18;
if (unwind === 0) {
throw e;
}
if (unwind === 206) {
break b16;
}
if (unwind === 207) {
break b17;
}
if (unwind === 208) {
break b17;
}
if (unwind === 209) {
break b16;
}
if (unwind === 210) {
break b16;
}
if (unwind === 211) {
break b16;
}
if (unwind === 212) {
break b14;
}
if (unwind === 213) {
break b14;
}
if (unwind === 214) {
break b13;
}
if (unwind === 215) {
break b12;
}
if (unwind === 216) {
break b12;
}
if (unwind === 217) {
break b12;
}
if (unwind === 218) {
break b12;
}
if (unwind === 219) {
break b11;
}
if (unwind === 220) {
break b10;
}
if (unwind === 221) {
rt.drop(_189);
break b10;
}
if (unwind === 222) {
break b10;
}
if (unwind === 223) {
rt.drop(_168);
} else if (unwind !== 224) {
if (unwind === 225) {
break b10;
}
if (unwind === 208) {
break b18;
if (unwind === 226) {
break b10;
}
if (unwind === 209) {
break b17;
if (unwind === 227) {
break b10;
}
if (unwind === 210) {
break b17;
if (unwind === 228) {
break b10;
}
if (unwind === 211) {
break b17;
if (unwind === 229) {
break b10;
}
if (unwind === 212) {
break b15;
if (unwind === 230) {
break b10;
}
if (unwind === 213) {
break b15;
if (unwind === 232) {
break b9;
}
if (unwind === 214) {
break b14;
if (unwind === 233) {
break b9;
}
if (unwind === 215) {
break b13;
if (unwind === 234) {
break b9;
}
if (unwind === 216) {
break b13;
if (unwind === 235) {
break b9;
}
if (unwind === 217) {
break b13;
if (unwind === 236) {
break b9;
}
if (unwind === 218) {
break b13;
if (unwind === 237) {
break b8;
}
if (unwind === 219) {
break b12;
if (unwind === 238) {
break b7;
}
if (unwind === 220) {
break b11;
if (unwind === 239) {
break b6;
}
if (unwind === 221) {
rt.drop(_189);
break b11;
if (unwind === 242) {
break b15;
}
if (unwind === 222) {
break b11;
if (unwind === 244) {
break b12;
}
if (unwind === 223) {
rt.drop(_168);
} else if (unwind !== 224) {
if (unwind === 225) {
break b11;
}
if (unwind === 226) {
break b11;
}
if (unwind === 227) {
break b11;
}
if (unwind === 228) {
break b11;
}
if (unwind === 229) {
break b11;
}
if (unwind === 230) {
break b11;
}
if (unwind === 231) {
break b10;
}
if (unwind === 232) {
break b9;
}
if (unwind === 233) {
break b9;
}
if (unwind === 234) {
break b9;
}
if (unwind === 235) {
break b9;
}
if (unwind === 236) {
break b9;
}
if (unwind === 237) {
break b8;
}
if (unwind === 238) {
break b7;
}
if (unwind === 239) {
break b6;
}
if (unwind === 242) {
break b16;
}
if (unwind === 244) {
break b13;
}
if (unwind === 246) {
break b9;
}
break b5;
if (unwind === 246) {
break b9;
}
break b11;
break b5;
}
break b10;
}
rt.dropAll(kept);
}
if (_384) {
rt.dropAll(tris);
}
rt.dropAll(kept);
}
if (_384) {
rt.dropAll(tris);
}
rt.drop(m);
}
rt.drop(n);
}
if (_385) {
rt.dropAll(objects);
rt.drop(m);
}
rt.drop(n);
}
if (_385) {
rt.dropAll(objects);
}
rt.drop(hits);
}
rt.drop(hits);
}
}
if (_386) {
Expand Down
Loading