From 8ec59b1a37b695466c229525aad3ca44f2f31f79 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 6 Nov 2026 23:16:53 -0800 Subject: [PATCH 1/3] chore(quest): claim quest/m3/ts-unsafe/vec-drain-mir.md Quest-Claim: 5e16ea94798f193b From d102dc9bac6702d088e37cd7ca2454c3c053d823 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Sat, 7 Nov 2026 04:40:11 -0800 Subject: [PATCH 2/3] quest(m3): record what std's Drain from MIR needs, and leave keeping it to the maintainer Co-Authored-By: Claude Opus 5.5 --- quest/m3/ts-unsafe/vec-drain-mir.md | 33 +++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/quest/m3/ts-unsafe/vec-drain-mir.md b/quest/m3/ts-unsafe/vec-drain-mir.md index 891bbd26e..8c7b709c0 100644 --- a/quest/m3/ts-unsafe/vec-drain-mir.md +++ b/quest/m3/ts-unsafe/vec-drain-mir.md @@ -11,9 +11,34 @@ it still matches std's items, drops, and what a forgotten drain leaves. ## Plan -moq calls it (`client.rs:821`, `priority.rs:216`) and the port works, so this is fidelity -to std rather than a blocker: the port must track std by hand. The B-tree port of -[#577](https://github.com/moq-dev/rust2/pull/577) is the precedent. Measure the TS -bench's drain-heavy workloads against the port. +moq calls it (`priority.rs:216`, a `Vec`'s full drain; `client.rs:821` drains a +`VecDeque`) and the port works, so this is fidelity to std rather than a blocker: the +port must track std by hand. The B-tree port of +[#577](https://github.com/moq-dev/rust2/pull/577) is the precedent. + +A spike in [#636](https://github.com/moq-dev/rust2/pull/636), on branch +`spike/vec-drain-mir`, translated `alloc::vec::drain` and `Vec::drain` as the crate's own +code. Over elements JS copies (`u8`, `u16`, `u32`), it passes `slices::drains` against +native once [#621](https://github.com/moq-dev/rust2/pull/621) lands. It also needed: +`Global` as nothing, a mapping of `slice::range`, `slice::Iter`'s `as_slice` and `Default`, +`<*mut T>::cast_slice`, `NonNull>::as_mut`, and an own iterator's `is_empty`. +It ran 3-12x slower than the port by CPU time per `slices::drains` call in Node: `set_len` +moves the range and the tail into the `Vec`'s room, which std's code then reads back +through a `Proxy` view and copies back one element at a time. + +Over elements JS keeps as objects, such as the fixture's `Item` or a `Waker`, +`as_ptr().add(start)`, `offset_from`, and `slice::from_raw_parts` are refused: a pointer +to such an element is that object, which knows no array it is in +([the epic](/quest/m3/ts-unsafe/README.md), decided 2026-11-01). Public API: the translator's output. + +## Waiting + +- Maintainer: whether std's `Drain` is still wanted, given it needs pointers into an array + of objects and runs 3-12x slower. Options: drop this quest and keep the port, which + `slices::drains` tests against native (recommended); plan a pointer model where a + pointer into an array of objects is an `rs.AtIndex`, plus a room that keeps the slots + past the length in the array itself, and block this quest on both; or translate it only + for elements JS copies, which keeps the port for the rest (not recommended: two + implementations, one still tracking std by hand). Check: this item is resolved here. From 291ea6f265e7f9e9b1be1329454708721ebe4b7d Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Sat, 7 Nov 2026 06:39:19 -0800 Subject: [PATCH 3/3] quest(m3): delete Vec::drain from std's MIR, keeping the runtime's port std's Drain needs std structs and writing std functions translated from MIR, which the translator refuses, and pointer arithmetic into arrays of objects, which the epic's 2026-11-01 decision refuses. Even for elements JS copies it ran 3 to 12x slower than the port, which follows std line for line and is tested against native on every `just ci`. Co-Authored-By: Claude Opus 5.5 --- quest/m3/ts-unsafe/README.md | 1 - quest/m3/ts-unsafe/vec-drain-mir.md | 44 ----------------------------- 2 files changed, 45 deletions(-) delete mode 100644 quest/m3/ts-unsafe/vec-drain-mir.md diff --git a/quest/m3/ts-unsafe/README.md b/quest/m3/ts-unsafe/README.md index e54d29d86..2adf7741a 100644 --- a/quest/m3/ts-unsafe/README.md +++ b/quest/m3/ts-unsafe/README.md @@ -74,7 +74,6 @@ Public API: the translator's output. - [A raw pointer behind a reference](/quest/m3/ts-unsafe/raw-behind-ref.md) - `&raw const *r` of a value JS copies points where the reference came from - [Vec::from_raw_parts of a typed allocation](/quest/m3/ts-unsafe/vec-from-raw-parts.md) - a `Vec` adopts an `alloc`ed array of `T`s, with its length, capacity, and drops -- [Vec::drain from std's MIR](/quest/m3/ts-unsafe/vec-drain-mir.md) - std's `Drain` translates, replacing the runtime's port - [BinaryHeap from std's MIR](/quest/m3/ts-unsafe/binary-heap-mir.md) - std's `BinaryHeap` and `PeekMut` translate, replacing the runtime's port - [Unchecked integer operations](/quest/m3/ts-unsafe/unchecked-ops.md) - `unchecked_*` and `NonZero::new_unchecked` translate, aborting on a violated precondition - [NonZero's unchecked arithmetic](/quest/m3/ts-unsafe/nonzero-unchecked-ops.md) - `NonZero::unchecked_add` and `unchecked_mul` translate, aborting at std's site diff --git a/quest/m3/ts-unsafe/vec-drain-mir.md b/quest/m3/ts-unsafe/vec-drain-mir.md deleted file mode 100644 index 8c7b709c0..000000000 --- a/quest/m3/ts-unsafe/vec-drain-mir.md +++ /dev/null @@ -1,44 +0,0 @@ -# [M] Vec::drain from std's MIR - -## Goal - -[rust2-ts](/ts/README.md) translates `Vec::drain` from std's MIR, whose `Drain` reads its -range out and moves the tail back through raw pointers into the `Vec`'s storage, -replacing `rs.vecDrain` and `rs.byteVecDrain`, the runtime port that -[the slice gaps' PR](https://github.com/moq-dev/rust2/pull/259) mapped it to -(`ts/src/lower/library.rs`). The lang fixture's `slices::drains` differential case proves -it still matches std's items, drops, and what a forgotten drain leaves. - -## Plan - -moq calls it (`priority.rs:216`, a `Vec`'s full drain; `client.rs:821` drains a -`VecDeque`) and the port works, so this is fidelity to std rather than a blocker: the -port must track std by hand. The B-tree port of -[#577](https://github.com/moq-dev/rust2/pull/577) is the precedent. - -A spike in [#636](https://github.com/moq-dev/rust2/pull/636), on branch -`spike/vec-drain-mir`, translated `alloc::vec::drain` and `Vec::drain` as the crate's own -code. Over elements JS copies (`u8`, `u16`, `u32`), it passes `slices::drains` against -native once [#621](https://github.com/moq-dev/rust2/pull/621) lands. It also needed: -`Global` as nothing, a mapping of `slice::range`, `slice::Iter`'s `as_slice` and `Default`, -`<*mut T>::cast_slice`, `NonNull>::as_mut`, and an own iterator's `is_empty`. -It ran 3-12x slower than the port by CPU time per `slices::drains` call in Node: `set_len` -moves the range and the tail into the `Vec`'s room, which std's code then reads back -through a `Proxy` view and copies back one element at a time. - -Over elements JS keeps as objects, such as the fixture's `Item` or a `Waker`, -`as_ptr().add(start)`, `offset_from`, and `slice::from_raw_parts` are refused: a pointer -to such an element is that object, which knows no array it is in -([the epic](/quest/m3/ts-unsafe/README.md), decided 2026-11-01). - -Public API: the translator's output. - -## Waiting - -- Maintainer: whether std's `Drain` is still wanted, given it needs pointers into an array - of objects and runs 3-12x slower. Options: drop this quest and keep the port, which - `slices::drains` tests against native (recommended); plan a pointer model where a - pointer into an array of objects is an `rs.AtIndex`, plus a room that keeps the slots - past the length in the array itself, and block this quest on both; or translate it only - for elements JS copies, which keeps the port for the rest (not recommended: two - implementations, one still tracking std by hand). Check: this item is resolved here.