From f85f43df0aea642bf1cd63bd07154e942027d0e3 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 17:17:04 -0800 Subject: [PATCH 1/5] chore(quest): claim quest/m0/nightly-red.md Quest-Claim: a6d55544cd8d2c89 From 07b41b641f78f0205ad4115d7776327b252bb785 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 17:26:10 -0800 Subject: [PATCH 2/5] fix(ffi): moq.swift's launched tasks fail the script when they throw Co-Authored-By: Claude Opus 5.5 --- ffi/moq/moq.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ffi/moq/moq.swift b/ffi/moq/moq.swift index 532010f9b..b5735e21b 100644 --- a/ffi/moq/moq.swift +++ b/ffi/moq/moq.swift @@ -109,8 +109,15 @@ final class Queue: TaskExecutor, @unchecked Sendable { } } + /// Run `body` as a task that prefers this queue, counting an error it throws as a failure. func launch(_ body: @escaping @Sendable () async throws -> Void) { - Task(executorPreference: self, operation: body) + Task(executorPreference: self) { + do { + try await body() + } catch { + expect(false, "a launched task threw \(error)") + } + } } } From 4f55a23c5e29b4cb49acc05159b4c4e0cde4c606 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 18:10:33 -0800 Subject: [PATCH 3/5] fix(ffi): keep every frame-isolating Kotlin helper from R8's inlining ART's interpreter roots every register a frame last wrote until it returns, so a helper R8 inlines leaves what it held reachable from its caller. Mark each with OwnFrame, which the Android test's R8 rule keeps, rather than naming a few. Co-Authored-By: Claude Opus 5.5 --- ffi/tests/api.kt | 51 +++++++++++++++++++++++++++++++------------ ffi/tests/fixtures.rs | 6 ++--- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/ffi/tests/api.kt b/ffi/tests/api.kt index df02a065f..647fd2f06 100644 --- a/ffi/tests/api.kt +++ b/ffi/tests/api.kt @@ -19,6 +19,11 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout +// What a function marked so holds lives in its own frame: the Android test keeps it from +// R8's inlining, since ART's interpreter keeps every reference a frame's registers last +// held reachable until the frame returns, which would keep it from the GC checks after. +annotation class OwnFrame + // The Log callback: keeps even levels. class PrintLog : Log, AutoCloseable { override fun log(level: UByte, line: String): Boolean { @@ -866,7 +871,7 @@ fun futures() { run { val (job, weak) = idle(scope) q.drain() - check(weak.get() != null, "a closure a pending future keeps stays held") + check(held(weak), "a closure a pending future keeps stays held") job.cancel() q.drain() released(weak, "a closure a cancelled future kept is released") @@ -875,6 +880,7 @@ fun futures() { } // A closure Spawned keeps, which returns [n], once Spawned ran it. +@OwnFrame fun spawned(n: UInt): java.lang.ref.WeakReference { val task = { n } check(Spawned.new(task).join() == n, "a kept closure runs on Rust's thread") @@ -882,6 +888,7 @@ fun spawned(n: UInt): java.lang.ref.WeakReference { } // A drive whose closure waits for a wake that never comes, launched on [scope]. +@OwnFrame fun idle(scope: CoroutineScope): Pair> { val start = now() val poll = { _: Instant, _: Waiter -> start.let { null } } @@ -889,6 +896,10 @@ fun idle(scope: CoroutineScope): Pair): Boolean = weak.get() != null + // Collect until [weak] is gone, as once Rust lets go of the closure it held. fun released(weak: java.lang.ref.WeakReference<*>, what: String) { val deadline = System.nanoTime() + 10.seconds.inWholeNanoseconds @@ -1039,21 +1050,23 @@ fun reads(bytes: Bytes, value: Byte, what: String) { } } -// In its own frame, so nothing on the caller's keeps them reachable. The bytes are long -// enough to be lent. +// Never closed, and long enough to be lent. +@OwnFrame fun unclosed() { Token.new(3u) tokenBytes(4u, 1025u) } -// A slice of Rust's bytes, made in its own frame so nothing keeps the Bytes it came from, -// which keeps Rust's buffer while it reads. +// A slice of Rust's bytes, made in a frame of its own so nothing keeps the Bytes it came +// from, which keeps Rust's buffer while it reads. +@OwnFrame fun keptBySlice(freed: UInt) { val view = sliced(5u) uncollected(freed, "a slice keeps Rust's bytes") check(view.size == 10 && view.toByteArray().all { it == 5.toByte() }, "a slice reads Rust's bytes once the Bytes it came from are gone") } +@OwnFrame fun sliced(id: UInt): Bytes = tokenBytes(id, 1025u).slice(1015) // Frees racing calls: a close racing calls on other threads, and the GC freeing what a @@ -1098,10 +1111,7 @@ fun raced() { } var rounds = 0u while (cycles.get() < 50) { - val id = rounds % 100u + 1u - check(tokenBytes(id, 2048u)[2047] == id.toByte(), "a read by index races the GC") - check(tokenBytes(id, 2048u).slice(1024).toByteArray().all { it == id.toByte() }, "a slice's copy races the GC") - check(Token.new(id).idGet == id, "a call on an object races the GC") + racedRound(rounds % 100u + 1u) rounds++ } collecting.set(false) @@ -1109,6 +1119,14 @@ fun raced() { collected(before + 3u * rounds, "the GC frees what each call raced") } +// Calls on values nothing else reaches once it returns, holding [id], racing the GC. +@OwnFrame +fun racedRound(id: UInt) { + check(tokenBytes(id, 2048u)[2047] == id.toByte(), "a read by index races the GC") + check(tokenBytes(id, 2048u).slice(1024).toByteArray().all { it == id.toByte() }, "a slice's copy races the GC") + check(Token.new(id).idGet == id, "a call on an object races the GC") +} + // At most 64 MiB of Rust's bytes are lent at once, freed or not, since the GC sees none of // them: past that, bytes cross copied, freed at the call, until the GC frees what was lent. // First, so no bytes an earlier step lent count against it. @@ -1116,13 +1134,19 @@ fun budgeted() { val before = dropped() lentToBudget(before) collected(before + 65u, "the GC frees bytes lent up to the budget") - check(tokenBytes(3u, 2048u)[2047] == 3.toByte() && dropped() == before + 65u, "bytes cross lent again once the GC frees them") + lentAgain(before + 65u) collected(before + 66u, "the GC frees bytes lent once the budget is free") } +// Bytes lent once the GC freed those that filled the budget, with Rust's drops still [freed]. +@OwnFrame +fun lentAgain(freed: UInt) { + check(tokenBytes(3u, 2048u)[2047] == 3.toByte() && dropped() == freed, "bytes cross lent again once the GC frees them") +} + // Rust's bytes either side of the copy limit, returning the drops once the call has freed -// those it copied. In its own frame, which the Android test keeps from R8's inlining, as -// ART's interpreter keeps the last ones reachable from the caller's until it returns. +// those it copied. +@OwnFrame fun lentAround(): UInt { var freed = dropped() for (n in 1023..1025) { @@ -1134,8 +1158,7 @@ fun lentAround(): UInt { return freed } -// In its own frame, which the Android test keeps from R8's inlining, so nothing on the -// caller's keeps them reachable. +@OwnFrame fun lentToBudget(before: UInt) { val mib = 1 shl 20 val held = List(64) { tokenBytes(1u, mib.toUInt()) } diff --git a/ffi/tests/fixtures.rs b/ffi/tests/fixtures.rs index a348ea731..5ead03cb0 100644 --- a/ffi/tests/fixtures.rs +++ b/ffi/tests/fixtures.rs @@ -474,8 +474,8 @@ fn api_android() { // reaches, which R8 shrinks and renames, keeping only what the rules keep: the // generated ones, and those kotlinx-coroutines' jar holds, which an app's build reads // from it. Kotlin's annotations are on an app's classpath, not in its dex. The - // script's functions that hold lent bytes in their own frame are kept too, as R8 would - // inline them into their caller, whose frame ART's interpreter keeps reaching the bytes. + // script's functions marked `OwnFrame` are kept too, as R8 would inline them into their + // caller, whose frame ART's interpreter keeps reaching what they held. let jar = dir.join("app.jar"); run(kotlinc(&out, &jar).arg("-include-runtime")); run(Command::new("jar") @@ -487,7 +487,7 @@ fn api_android() { std::fs::write( &app, format!( - "-keep class ApiKt {{ public static void main(java.lang.String[]); static *** lentAround(); static *** lentToBudget*(...); }}\n-dontwarn org.jetbrains.annotations.**\n-printusage {}\n", + "-keep class ApiKt {{ public static void main(java.lang.String[]); @OwnFrame static ; }}\n-dontwarn org.jetbrains.annotations.**\n-printusage {}\n", dir.join("usage.txt").display() ), ) From 2e5d372b8ad61e6718defad5d01d20b3fff573ef Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 18:17:16 -0800 Subject: [PATCH 4/5] chore(quest): finish m0/nightly-red Co-Authored-By: Claude Opus 5.5 --- quest/m0/ffi-moq-gate.md | 8 ++------ quest/m0/nightly-red.md | 33 --------------------------------- 2 files changed, 2 insertions(+), 39 deletions(-) delete mode 100644 quest/m0/nightly-red.md diff --git a/quest/m0/ffi-moq-gate.md b/quest/m0/ffi-moq-gate.md index c4ecdd86a..3b2e6f55c 100644 --- a/quest/m0/ffi-moq-gate.md +++ b/quest/m0/ffi-moq-gate.md @@ -10,8 +10,8 @@ adds to the gate, warm and cold. ## Plan Decided with the maintainer on 2026-11-12, in the quest audit: ✅ in m0. Today the -exporter's check on its first consumer runs only nightly, where it was red on 2026-11-12 -([the nightly](/quest/m0/nightly-red.md)), while the experiment's runs on every merge. +exporter's check on its first consumer runs only nightly, where it was red on 2026-11-12, +while the experiment's runs on every merge. - The nightly's full export step takes about 13m40s, too slow for the gate. Find the cheapest step that still fails on a real break. Recommended: export the stand-in facade @@ -22,7 +22,3 @@ exporter's check on its first consumer runs only nightly, where it was red on 20 without it. Public API: none. - -## Required - -- [The nightly passes again](/quest/m0/nightly-red.md) - a gate added while the export is red would block every exporter merge diff --git a/quest/m0/nightly-red.md b/quest/m0/nightly-red.md deleted file mode 100644 index e9c0a4610..000000000 --- a/quest/m0/nightly-red.md +++ /dev/null @@ -1,33 +0,0 @@ -# [M] The nightly passes again - -## Goal - -The nightly passes on `main`: its "Export moq-net to C" and "Export to Kotlin on Android" -jobs, which failed in -[run 43246857664](https://github.com/moq-dev/rust2/actions/runs/43246857664) at `53d822ed` -on 2026-11-12, after -[run 43038758163](https://github.com/moq-dev/rust2/actions/runs/43038758163) passed at -`936ce441` the day before. - -## Plan - -Found by the 2026-11-12 audit: m0's Goal names a red nightly, and no quest owned this one. -Reproduce each before fixing it, at its root. - -- "Export moq-net to C" fails compiling `ffi/moq/moq.swift` under warnings as errors: - the `Task(executorPreference: self, operation: body)` in `launch` is an unstructured - throwing task whose result is unused. The job runs on arm64 Linux, where - [#711](https://github.com/moq-dev/rust2/pull/711) first ran the Swift, so name #711 - under `## Caused by`. -- "Export to Kotlin on Android" fails `api_android` at `ffi/tests/api.kt`'s `budgeted`: - "the GC frees bytes lent once the budget is free". The ten commits between the two runs - include [#700](https://github.com/moq-dev/rust2/pull/700) and - [#708](https://github.com/moq-dev/rust2/pull/708); bisect on the emulator, and check - whether it fails every run before calling it a regression, since - [#693](https://github.com/moq-dev/rust2/pull/693) last fixed this test's lent bytes on - ART. A test that depends on when the GC runs is fixed by making the collection - deterministic, not by a retry. - -## Closes - -- [#716](https://github.com/moq-dev/rust2/issues/716) - the nightly's failure issue From b68c3756311472cf5e13ed197e95f641697e1003 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 13 Nov 2026 15:24:16 -0800 Subject: [PATCH 5/5] fix(ffi): released checks its weak reference out of the frame that calls gc() Co-Authored-By: Claude Opus 5.5 --- ffi/tests/api.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ffi/tests/api.kt b/ffi/tests/api.kt index 2568b84b6..4098b0514 100644 --- a/ffi/tests/api.kt +++ b/ffi/tests/api.kt @@ -951,7 +951,7 @@ fun held(weak: java.lang.ref.WeakReference<*>): Boolean = weak.get() != null // Collect until [weak] is gone, as once Rust lets go of the closure it held. fun released(weak: java.lang.ref.WeakReference<*>, what: String) { val deadline = System.nanoTime() + 10.seconds.inWholeNanoseconds - while (weak.get() != null) { + while (held(weak)) { check(System.nanoTime() < deadline, what) Runtime.getRuntime().gc() Thread.sleep(1)