diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 835fd02a1..cc3ffdc3a 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -364,8 +364,8 @@ jobs: if: runner.os == 'macOS' run: just ffi test swift && just ffi moq-swift - # The Kotlin on ART, shrunk by R8 as an app shrinks it, and the library's abort messages - # and 16 KB alignment. x86_64, as moq's Android build: + # The Kotlin on ART under CheckJNI, shrunk by R8 as an app shrinks it, and the library's + # abort messages and 16 KB alignment. x86_64, as moq's Android build: # this image ships the Android SDK and NDK, and its KVM runs an x86_64 emulator at speed. ffi-android: name: Export to Kotlin on Android @@ -402,6 +402,15 @@ jobs: arch: x86_64 script: nix develop .#android --command just ffi android + # A 32-bit ABI, as moq's armv7 build is, whose pointers and usize are half a long: + # x86, which this runner's KVM runs at speed. + - name: API 24, 32-bit + uses: reactivecircus/android-emulator-runner@a421e43855164a8197daf9d8d40fe71c6996bb0d # v2.38.0 + with: + api-level: 24 + arch: x86 + script: nix develop .#android --command just ffi android + # An image whose kernel pages by 16 KB, as Google Play requires of 64-bit libraries from # 2027-02-01: the library must load there, and its segments must align to that. - name: API 35, 16 KB pages diff --git a/ffi/README.md b/ffi/README.md index a5462979f..c43815d77 100644 --- a/ffi/README.md +++ b/ffi/README.md @@ -1517,7 +1517,7 @@ packs the api fixture's with npm, installs it into a project of its own, type-ch ## Tests ```bash -just ffi test # export the fixtures, build them, and drive api from C, C++, Kotlin, Python, Swift, Go, Dart, and TypeScript on Node and Deno +just ffi test # export the fixtures, build them, and drive api from C, C++, Kotlin, Python, Swift, Go, Dart, and TypeScript on Node, Deno, and Bun just ffi moq # export moq's crates at the pinned revision, build them, and run moq/moq.c, moq/moq.cpp, moq/moq.kt, moq/moq.py, moq/moq.swift, moq/moq.go, and moq/moq.dart just ffi moq-c # the same export, built in debug, running only moq/moq.c: `just ci`'s check on moq just ffi moq-cpp # the same export, running only moq/moq.cpp @@ -1529,10 +1529,10 @@ just ffi corpus # census, export, and bind each crate of corpus/crates.txt thr just ffi corpus-update # take corpus/crates.txt afresh from crates.io's top crates, and resolve corpus/Cargo.lock just ffi protocol # run longer protocol scripts from more seeds through the C ABI and every binding, as the nightly does nix develop .#bench --command just ffi browsers # api's TypeScript in headless Chromium, Firefox, and on Linux WebKit, lowering `using` three ways for WebKit, as the nightly runs it -nix develop .#android --command just ffi android # the Kotlin test, shrunk by R8, on the Android device adb reaches +nix develop .#android --command just ffi android # the Kotlin test, shrunk by R8, under CheckJNI on the Android device adb reaches nix develop .#bench --command just ffi bench # the binding benchmark: bench/ffi/README.md's cases from Rust, and through the export from C, C++, Kotlin, Python, Swift, Go, and Dart nix develop .#bench --command just ffi codspeed # after bench-build, each single-threaded case once under CodSpeed's CPU simulation, as the CodSpeed workflow runs it -nix develop .#sanitize --command just ffi sanitize # api's C and C++ scripts under ASan and TSan, its Go under the race detector, and its C ABI under Miri +nix develop .#sanitize --command just ffi sanitize # api's C and C++ scripts under ASan with UBSan, TSan, and Valgrind, its Swift under TSan, its Go under the race detector and cgocheck2, its Python looped on a debug CPython, and its C ABI under Miri ``` The `api` fixture covers each rule once, and re-exports the `dep` fixture's types, which @@ -1551,7 +1551,7 @@ runs the script through the C++ header at C++17, 20, and 23, with exceptions and at 17 and 23, builds it under Clang's `-Wconsumed -Wdangling -Werror`, each case of `tests/api_strict.cpp` failing there, then checks its futures: a wake that lands during a poll, a cancel between a wake and its poll that loses nothing, and a coroutine resumed or destroyed. `tests/api.kt` -runs the script through the Kotlin on the JVM, checks its futures the same way, that a call +runs the script through the Kotlin on the JVM under CheckJNI, where a warning fails it, checks its futures the same way, that a call after `close()` throws, that `Bytes` and their slices keep Rust's buffer, past the object or record they came from, until the GC frees it, that calls racing `close()` or the GC read live values, that the GC frees an object never closed left in an idle nursery or @@ -1559,11 +1559,12 @@ pushed out of one, and that each object of many threads' returns, closes, and dr freed once, and breaks each runtime check, which must throw or abort with its message. `just ffi android` runs the same on ART: the Kotlin and `tests/api.kt`, shrunk by R8 into an app's dex with only the generated rules keeping what JNI looks up, against the library built by the NDK for the -device's ABI, which ANDROID_HOME and ANDROID_NDK_HOME locate. It also reads the library's -segment alignment with `readelf`, which must be 16 KB, and checks that a failed check and a -panic reach logcat and bionic's abort message, which the tombstone shows. Nightly runs it on an -x86_64 emulator at API 24, the oldest moq's Android library supports, at API 35, and at -API 35 on an image whose kernel pages by 16 KB. +device's ABI, which ANDROID_HOME and ANDROID_NDK_HOME locate, under ART's CheckJNI. It also +reads the library's segment alignment with `readelf`, which must be 16 KB, and checks that a +failed check and a panic reach logcat and bionic's abort message, which the tombstone shows. +Nightly runs it on an x86_64 emulator at API 24, the oldest moq's Android library supports, at +API 35, and at API 35 on an image whose kernel pages by 16 KB, and on a 32-bit x86 one at API +24, as moq's armv7 build is 32-bit. `tests/api.py` runs the script through the Python, in CPython's development mode with warnings as errors, checks its futures the same way, what frees an object or bytes nobody closed, and the values Python's types bound, and breaks each runtime check, which must raise or @@ -1576,7 +1577,8 @@ language mode and type-checked in Swift 5's, checks its futures the same way and releasing frees, and breaks each runtime check, which must trap or abort with its message, and each move or borrow the compiler checks, which must fail to compile. It runs with nixpkgs' Swift on Linux, and nightly with Apple's on macOS. -`tests/api.go` runs the script through the Go after `go vet`, checks its futures the same +`tests/api.go` runs the script through the Go after `go vet`, failing any run that leaves a +goroutine Go's `goroutineleak` profile finds, checks its futures the same way, plus a context done before the call, a deadline, and a handle closed during a call, checks that bytes cross both ways, that a `Bytes` keeps Rust's buffer while only a sub-view or a reader reaches it and that the GC frees it once none does, that the GC frees an object @@ -1647,10 +1649,15 @@ against that export's `api.json`: its `added` feature only adds and must pass, a feature breaks the API twice for each kind of break, once in an item only wasm32 has, each error matching `fixtures/lock/expected.txt`. `just ffi sanitize`, run nightly, rebuilds the `api` export with std under AddressSanitizer -and then ThreadSanitizer, runs `tests/api.c` and `tests/api.cpp` against it, and matches -their output to the native transcript; it runs `tests/api.go` under Go's race detector; -and it drives the C ABI from `tests/miri/api.rs` and the protocol scripts from -`tests/miri/protocol.rs` under Miri with strict provenance. +and then ThreadSanitizer, runs `tests/api.c` and `tests/api.cpp` against it, the first time +with UndefinedBehaviorSanitizer too, and `tests/api.swift` against the second, and matches +their output to the native transcript; it runs `tests/api.c` and `tests/api.cpp` against the +uninstrumented library under Valgrind's memcheck, `tests/api.go` under Go's race detector +and cgocheck2, and `tests/api.py`'s checks on a debug build of the newest CPython, then its +`leaks` case, which loops them and fails unless the interpreter's references and memory +blocks end where they began; and it drives the C ABI from `tests/miri/api.rs` and the +protocol scripts from `tests/miri/protocol.rs` under Miri with strict provenance. The +protocol scripts' C driver runs under each sanitizer too. moq's crates export through `target/moq-ffi`, an empty library on each that `just ffi moq` writes in place of moq-ffi's remainder. The export serves the host and each target `just ffi moq-api` staged in `target/moq-api` from the same moq sources, and fails on a diff --git a/ffi/justfile b/ffi/justfile index eba33772f..e5aaecd5c 100644 --- a/ffi/justfile +++ b/ffi/justfile @@ -57,13 +57,13 @@ protocol: browsers: cargo test --locked --test fixtures -- --ignored --exact api_browsers -# Shrink the api fixture's Kotlin with R8 and its generated rules, and run its test on the Android device adb reaches, in the Android shell (nix develop .#android) with ANDROID_HOME and ANDROID_NDK_HOME set. +# Shrink the api fixture's Kotlin with R8 and its generated rules, and run its test under CheckJNI on the Android device adb reaches, in the Android shell (nix develop .#android) with ANDROID_HOME and ANDROID_NDK_HOME set. android: cargo test --locked --test fixtures -- --ignored --exact api_android -# Run the api fixture's C and C++ scripts under AddressSanitizer and ThreadSanitizer, its Go script under Go's race detector, and its glue's C ABI under Miri, in the sanitize shell: nix develop .#sanitize. +# Run the api fixture's C and C++ scripts under AddressSanitizer with UndefinedBehaviorSanitizer, ThreadSanitizer, and Valgrind, its Swift script under ThreadSanitizer, its Go script under Go's race detector and cgocheck2, its Python script looped on a debug CPython, and its glue's C ABI under Miri, in the sanitize shell: nix develop .#sanitize. sanitize: - cargo test --locked --test fixtures -- --ignored --exact api_asan api_tsan api_go_race api_miri + cargo test --locked --test fixtures -- --ignored --exact api_asan api_tsan api_valgrind api_swift_tsan api_go_checked api_python_debug api_miri # Apply formatters without changing program behavior. fix: diff --git a/ffi/runtime/jni.rs b/ffi/runtime/jni.rs index ccd8752e9..0aed586e7 100644 --- a/ffi/runtime/jni.rs +++ b/ffi/runtime/jni.rs @@ -180,14 +180,21 @@ pub fn upcall(what: &str, f: impl FnOnce(*mut JNIEnv) -> R) -> R { fail(env, what, "a call into Kotlin is out of memory"); } let result = f(env); - if ((**env).v1_2.ExceptionCheck)(env) { - fail(env, what, "a call into Kotlin threw"); - } + threw(env, what); ((**env).v1_2.PopLocalFrame)(env, std::ptr::null_mut()); result } } +/// Abort if the call into Kotlin `f` just made threw: JNI allows no other call while an +/// exception is pending, so a call whose result is read checks this first. +pub fn threw(env: *mut JNIEnv, what: &str) { + // SAFETY: `env` is this thread's. + if unsafe { ((**env).v1_2.ExceptionCheck)(env) } { + fail(env, what, "a call into Kotlin threw"); + } +} + /// The static method `name` of the native class, whose type is `sig`, cached in `cache`. pub fn method(env: *mut JNIEnv, cache: &OnceLock, name: &CStr, sig: &CStr) -> jmethodID { *cache.get_or_init(|| { diff --git a/ffi/src/kotlin.rs b/ffi/src/kotlin.rs index edbedfd49..d184403d1 100644 --- a/ffi/src/kotlin.rs +++ b/ffi/src/kotlin.rs @@ -2258,7 +2258,7 @@ impl<'a> Gen<'a> { _ => unreachable!("a callback or closure returns no {c_ok:?}"), }; let back = match thrown { - None => back, + None => format!("rt::threw(env, \"{what}\");\n\t\t{back}"), Some(_) => { let err = outs.len() - 1; let ok = match c_ok { diff --git a/ffi/tests/api.go b/ffi/tests/api.go index 976081c6e..6ea328d0a 100644 --- a/ffi/tests/api.go +++ b/ffi/tests/api.go @@ -20,6 +20,7 @@ import ( "net/netip" "os" "runtime" + "runtime/pprof" "slices" "strings" "sync" @@ -1435,4 +1436,18 @@ func main() { default: broken(os.Args[1]) } + unleaked() +} + +// unleaked fails if a goroutine is blocked forever on what nothing else can reach, such +// as a future's wake channel a cancelled call dropped. +func unleaked() { + leaks := pprof.Lookup("goroutineleak") + var stacks strings.Builder + // Writing it runs the collection that finds them. + ok(leaks.WriteTo(&stacks, 1)) + if leaks.Count() != 0 { + fmt.Fprint(os.Stderr, stacks.String()) + os.Exit(1) + } } diff --git a/ffi/tests/api.kt b/ffi/tests/api.kt index 6c89f5181..cdcebb636 100644 --- a/ffi/tests/api.kt +++ b/ffi/tests/api.kt @@ -117,6 +117,12 @@ fun check(ok: Boolean, what: String) { /** Whether [f] throws `IllegalArgumentException`, as a value its Rust type cannot hold does. */ fun rejects(f: () -> Any?): Boolean = runCatching(f).exceptionOrNull() is IllegalArgumentException +/** The library's `usize::MAX`, which its target's pointer width sets: 32 bits on armv7 and x86 Android. */ +fun usizeMax(): ULong = if (pointerBits(platform()) == 64u) ULong.MAX_VALUE else UInt.MAX_VALUE.toULong() + +/** The library's `isize::MIN` and `isize::MAX`. */ +fun isizeRange(): LongRange = if (pointerBits(platform()) == 64u) Long.MIN_VALUE..Long.MAX_VALUE else Int.MIN_VALUE.toLong()..Int.MAX_VALUE.toLong() + fun script() = transcript() // A channel's futures, on a dispatcher the script drains, so it sees the receive pend and @@ -789,7 +795,7 @@ fun readings() { for (n in listOf(1u, 2u, 3u, 127u)) { val r = reading(n)!! check(r.debug() == readingDebug(n), "reading $n crosses as Rust holds it: ${r.debug()}") - check(r.count == ULong.MAX_VALUE - n && r.len == ULong.MAX_VALUE - n && r.tag == (UShort.MAX_VALUE - n.toUShort()).toUShort(), "reading $n's unsigned scalars") + check(r.count == ULong.MAX_VALUE - n && r.len == usizeMax() - n && r.tag == (UShort.MAX_VALUE - n.toUShort()).toUShort(), "reading $n's unsigned scalars") check(r.at.x == Int.MIN_VALUE + n.toInt() && r.offset == (Byte.MIN_VALUE + n.toInt()).toByte(), "reading $n's signed scalars") check(r.level == -n.toFloat() / 2 && r.ratio == Double.MAX_VALUE / n.toDouble() && r.mark == 0x10FFFF - n.toInt(), "reading $n's floats and char") check(r.ok == (n % 2u == 1u) && r.shape == (if (n % 2u == 1u) Shape.CIRCLE else Shape.SQUARE) && r.note == "reading $n", "reading $n's bool, enum, and text") @@ -840,7 +846,7 @@ fun owned() { check(runCatching { token.idGet }.exceptionOrNull()?.message == "Token is closed", "a call after close throws") // The file serves wasm32 too: what only wasm32 has throws on the host's library. - check(pointerBits(platform()) == 64u && pointerBits(Platform.Native(64u)) == 64u, "the host is native") + check(platform() is Platform.Native && pointerBits(Platform.Native(64u)) == 64u, "the host is native") check(isFamily(Family.NATIVE), "and of the native family") for ((what, call) in listOf Unit>>( "api_wasm_only" to { wasmOnly() }, diff --git a/ffi/tests/api.py b/ffi/tests/api.py index 716e201cc..1fdc6dc14 100644 --- a/ffi/tests/api.py +++ b/ffi/tests/api.py @@ -4,10 +4,12 @@ # # With an argument, it instead checks the futures' semantics, what frees what nobody # closed, the values only Python's types bound, how Python calls into the extension, or -# what Python code expects of a package, or breaks a contract, which must fail. +# what Python code expects of a package, under a debug CPython that all of those leak +# nothing, or breaks a contract, which must fail. import array import asyncio +import contextlib import copy import dataclasses import datetime @@ -1378,9 +1380,41 @@ def readinto(self, buffer, /): raise ValueError(f"no case {which}") +def leaks(): + """The other runs' checks, looped under a debug CPython: once two rounds warm the + interpreter, five more leave its references and memory blocks exactly as they were.""" + check(hasattr(sys, "gettotalrefcount"), "leaks runs under a debug CPython") + + def counts(): + # Printed lines wait in the stream's buffer, and attribute lookups in the + # interpreter's caches, until they fill. + sys.stdout.flush() + sys._clear_internal_caches() + gc.collect() + return sys.gettotalrefcount(), sys.getallocatedblocks() + + def rounds(n): + for _ in range(n): + for run in (script, checks, futures, owned, values, calls, idioms): + run() + + with open(os.devnull, "w") as null, contextlib.redirect_stdout(null): + rounds(2) + first = counts() + # Each measurement held is counted by the next one. + before = counts() + rounds(5) + after = counts() + held = [b - f for b, f in zip(before, first)] + grown = [a - b for a, b in zip(after, before)] + check(grown == held, f"five rounds left the references and blocks {before} as {after}") + + match sys.argv[1:]: case []: script() + case ["leaks"]: + leaks() case ["futures"]: futures() case ["owned"]: diff --git a/ffi/tests/api.ts b/ffi/tests/api.ts index ce29de773..09df6be8c 100644 --- a/ffi/tests/api.ts +++ b/ffi/tests/api.ts @@ -1,7 +1,7 @@ // The api fixture's web test: the script fixtures/api/examples/transcript.rs runs as // native Rust does on wasm32-wasip1, through the TypeScript tests/fixtures/transcript // writes from it, transcript.ts, which calls the functions exported here that -// transcript.rs defines. It runs on Node or Deno, from beside the binding's `web` +// transcript.rs defines. It runs on Node, Deno, or Bun, from beside the binding's `web` // directory, or in a browser, through tests/browser.ts's `process`. RUST2_WASM is the path // of the module, built with the crate's `web` feature; without it, the script loads the // module its package holds, as `load` does by default. tests/fixtures.rs compares the @@ -601,14 +601,19 @@ async function futures(): Promise { print("futures ok"); } -/** Node's garbage collector, which a flag exposes. */ +/** The garbage collector: Bun's own, else V8's, which a flag exposes. */ let gc: (() => void) | undefined; /** Run the garbage collector until `done()`, failing past a deadline. */ async function collect(done: () => boolean, what: string): Promise { if (gc === undefined) { - process.getBuiltinModule("node:v8").setFlagsFromString("--expose-gc"); - gc = process.getBuiltinModule("node:vm").runInNewContext("gc"); + const bun = (globalThis as { Bun?: { gc(force: boolean): void } }).Bun; + if (bun !== undefined) { + gc = () => bun.gc(true); + } else { + process.getBuiltinModule("node:v8").setFlagsFromString("--expose-gc"); + gc = process.getBuiltinModule("node:vm").runInNewContext("gc"); + } } const deadline = Date.now() + 10000; while (!done()) { diff --git a/ffi/tests/fixtures.rs b/ffi/tests/fixtures.rs index 1c9f270e6..6c1a1d903 100644 --- a/ffi/tests/fixtures.rs +++ b/ffi/tests/fixtures.rs @@ -83,7 +83,8 @@ fn output(cmd: &mut Command) -> Output { fn check(cmd: &Command, output: &Output) { assert!( output.status.success(), - "{cmd:?} failed:\n{}{}", + "{cmd:?} failed with {}:\n{}{}", + output.status, String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr) ); @@ -268,9 +269,8 @@ fn c_transcript() -> PathBuf { generated("c", "transcript.c", &transcript::c::emit(transcript(), &header)) } -#[test] -fn api_c() { - let api = api(); +/// `tests/api.c` built by `CC` against the api fixture's static library. +fn api_c_exe(api: &Api) -> PathBuf { let exe = scratch().join("api").join("api-test"); let cc = std::env::var_os("CC").unwrap_or_else(|| "cc".into()); let src = manifest_dir().join("tests").join("api.c"); @@ -283,7 +283,7 @@ fn api_c() { } .run( Command::new(cc) - .args(["-std=c11", "-pedantic", "-Wall", "-Wextra", "-Werror", "-I"]) + .args(["-std=c11", "-pedantic", "-Wall", "-Wextra", "-Werror", "-g", "-I"]) .arg(&include) .arg("-I") .arg(&script) @@ -293,6 +293,13 @@ fn api_c() { .arg("-o") .arg(&exe), ); + exe +} + +#[test] +fn api_c() { + let api = api(); + let exe = api_c_exe(api); let c = run(&mut Command::new(&exe)); assert_eq!( String::from_utf8_lossy(&c.stdout), @@ -444,12 +451,13 @@ fn api_tsan() { } /// The Go script under Go's race detector, which catches a race between an object's -/// `Close` and the nursery that pushes it out on another goroutine. +/// `Close` and the nursery that pushes it out on another goroutine, and with cgocheck2, +/// which catches a Go pointer stored in memory Rust owns. #[test] #[ignore = "slow: just ffi sanitize"] -fn api_go_race() { +fn api_go_checked() { let api = api(); - let dir = scratch().join("api").join("go-race"); + let dir = scratch().join("api").join("go-checked"); let module = dir.join("module"); go_layout( api, @@ -459,24 +467,67 @@ fn api_go_race() { // The transcript's script, generated beside it in its package. step::write(&module.join("transcript.go"), transcript::go::emit(transcript())); let exe = dir.join(format!("api-test{EXE_SUFFIX}")); - run(go(&module, &["build", "-race", "-o"]).arg(&exe)); + run(go(&module, &["build", "-race", "-o"]) + .arg(&exe) + .env("GOEXPERIMENT", "cgocheck2")); // Every report fails the run. let env = [("GORACE", "halt_on_error=1")]; let output = run(Command::new(&exe).envs(env)); assert_eq!( String::from_utf8_lossy(&output.stdout), api.transcript, - "the Go transcript under the race detector differs from the native one" + "the Go transcript under the race detector and cgocheck2 differs from the native one" ); for case in ["futures", "owned", "closed", "bytes", "closures", "checks"] { run(Command::new(&exe).arg(case).envs(env)); } } -/// Build the api fixture's glue, std included, under the `sanitizer`, and run the C and -/// C++ scripts and the protocol scripts' C driver against it, built by clang under the -/// same one. -fn sanitized(sanitizer: &str) { +/// The C and C++ scripts under Valgrind's memcheck, against the library as the gate builds +/// it: uninstrumented, so it also sees what a sanitizer's own build of std would hide, such +/// as a read of memory nothing wrote. A definite or indirect leak fails the run too. +#[test] +#[ignore = "needs Valgrind: just ffi sanitize"] +fn api_valgrind() { + let api = api(); + let c = api_c_exe(api); + let cpp = scratch().join("api").join(format!("api-c++17{EXE_SUFFIX}")); + let link = Link { + generated: Some(cpp_transcript()), + ..api.link() + }; + cxx(&link, 17, true, &manifest_dir().join("tests").join("api.cpp"), &cpp); + for (exe, cases) in [ + (&c, &["statuses", "threads"][..]), + (&cpp, &["futures", "lifetimes", "checks"]), + ] { + for case in std::iter::once(None).chain(cases.iter().copied().map(Some)) { + let output = run(Command::new("valgrind") + .args([ + "--quiet", + "--error-exitcode=99", + "--exit-on-first-error=yes", + "--track-origins=yes", + "--leak-check=full", + "--errors-for-leak-kinds=definite,indirect", + ]) + .arg(exe) + .args(case)); + if case.is_none() { + assert_eq!( + String::from_utf8_lossy(&output.stdout), + api.transcript, + "{} under Valgrind differs from the native transcript", + exe.display() + ); + } + } + } +} + +/// The api fixture's glue built, std included, under the `sanitizer`: its static library, +/// and what a program linking it links besides. +fn sanitized_glue(sanitizer: &str) -> (PathBuf, Vec) { let api = api(); let dir = scratch().join("api").join(sanitizer); let built = run(cargo() @@ -496,14 +547,35 @@ fn sanitized(sanitizer: &str) { .split_whitespace() .map(str::to_string) .collect(); - let lib = dir.join("glue").join(host()).join("debug").join("libapi.a"); + (dir.join("glue").join(host()).join("debug").join("libapi.a"), native) +} + +/// Every report fails the run, rather than only those the sanitizer deems fatal. +const SANITIZER_ENV: [(&str, &str); 3] = [ + ("ASAN_OPTIONS", "detect_leaks=1:abort_on_error=1"), + ("TSAN_OPTIONS", "halt_on_error=1"), + ("UBSAN_OPTIONS", "halt_on_error=1:print_stacktrace=1"), +]; + +/// Build the api fixture's glue under the `sanitizer`, and run the C and C++ scripts and +/// the protocol scripts' C driver against it, built by clang under the same one. +fn sanitized(sanitizer: &str) { + let api = api(); + let dir = scratch().join("api").join(sanitizer); + let (lib, native) = sanitized_glue(sanitizer); let tests = manifest_dir().join("tests"); - let sanitize = format!("-fsanitize={sanitizer}"); - // Every report fails the run, rather than only those the sanitizer deems fatal. - let env = [ - ("ASAN_OPTIONS", "detect_leaks=1:abort_on_error=1"), - ("TSAN_OPTIONS", "halt_on_error=1"), - ]; + // UndefinedBehaviorSanitizer rides with AddressSanitizer on the C and C++ side, whose + // undefined behavior Rust's checks cannot see. `-fno-wrapv` overrides a hardened + // compiler's, such as Nix's, which would define signed overflow and so hide it. + let sanitize: &[&str] = match sanitizer { + "address" => &[ + "-fsanitize=address,undefined", + "-fno-sanitize-recover=all", + "-fno-wrapv", + ], + "thread" => &["-fsanitize=thread"], + other => panic!("no C flags for the {other} sanitizer"), + }; // Each language's generated script, which its test includes. let scripts = [c_transcript(), cpp_transcript()]; for (compiler, std, src, args) in [ @@ -517,7 +589,9 @@ fn sanitized(sanitizer: &str) { ] { let exe = dir.join(src.replace('.', "-")); run(Command::new(compiler) - .args([std, "-g", "-Wall", "-Wextra", "-Werror", &sanitize, "-I"]) + .args([std, "-g", "-Wall", "-Wextra", "-Werror"]) + .args(sanitize) + .arg("-I") .arg(api.out.join("include")) .args( scripts @@ -529,24 +603,24 @@ fn sanitized(sanitizer: &str) { .args(&native) .arg("-o") .arg(&exe)); - let output = run(Command::new(&exe).envs(env)); + let output = run(Command::new(&exe).envs(SANITIZER_ENV)); assert_eq!( String::from_utf8_lossy(&output.stdout), api.transcript, "{src} under {sanitizer} differs from the native transcript" ); for arg in args { - run(Command::new(&exe).arg(arg).envs(env)); + run(Command::new(&exe).arg(arg).envs(SANITIZER_ENV)); } } // The protocol scripts, whose steps on two threads free and drop what the other made. - let exe = protocol_c(api, &dir.join("protocol"), &[&sanitize], &lib, &native); + let exe = protocol_c(api, &dir.join("protocol"), sanitize, &lib, &native); protocol::check( &dir.join("protocol").join("scripts"), &protocol::scripts(0, PROTOCOL_SEEDS, 200, protocol::Profile::C), |_| { let mut cmd = Command::new(&exe); - cmd.envs(env); + cmd.envs(SANITIZER_ENV); cmd }, ); @@ -919,7 +993,8 @@ fn api_kotlin() { let jar = PathBuf::from(coroutines()); let java = |classpath: &[&Path], args: &[&str]| { let mut cmd = Command::new("kotlin"); - cmd.arg(format!("-Djava.library.path={}", api.lib.display())) + cmd.arg("-J-Xcheck:jni") + .arg(format!("-Djava.library.path={}", api.lib.display())) .arg("-cp") .arg(std::env::join_paths(classpath.iter().copied().chain([jar.as_path()])).unwrap()) .arg("ApiKt") @@ -1010,14 +1085,13 @@ fn api_kotlin() { } /// The same script on Android: the classes, shrunk by R8 into an app's dex with only the -/// generated rules keeping what JNI looks up, run on ART on the device adb reaches against -/// the library the NDK builds for its ABI, both for API 24, the oldest moq's Android library -/// supports. +/// generated rules keeping what JNI looks up, run on ART under CheckJNI on the device adb +/// reaches against the library the NDK builds for its ABI, both for API 24, the oldest moq's +/// Android library supports, and matched to the script run natively there. #[test] #[ignore = "needs the Android SDK and NDK, cargo-ndk, and a device: just ffi android"] fn api_android() { const DEVICE: &str = "/data/local/tmp/rust2-ffi"; - let api = api(); let sdk = PathBuf::from(std::env::var_os("ANDROID_HOME").expect("ANDROID_HOME names the Android SDK")); let adb = sdk.join("platform-tools").join("adb"); let dir = scratch().join("api").join("android"); @@ -1030,6 +1104,7 @@ fn api_android() { let target = match abi.as_str() { "arm64-v8a" => "aarch64-linux-android", "x86_64" => "x86_64-linux-android", + "x86" => "i686-linux-android", abi => panic!("the android shell's toolchain has no target for the device's ABI {abi}"), }; let out = dir.join("out"); @@ -1050,6 +1125,32 @@ fn api_android() { .args(["--features", "kotlin"]) .env("RUSTFLAGS", "-D warnings")); + // The fixture's script, built for the device as the library is, whose run there is what + // the Kotlin must print: a 32-bit ABI's `usize` differs from the host's. + let transcript = dir.join("transcript"); + run(cargo() + .args([ + "ndk", + "--target", + &abi, + "--platform", + "24", + "build", + "--quiet", + "--locked", + ]) + .args([ + "--package", + "api-fixture", + "--example", + "transcript", + "--features", + "doubled", + ]) + .arg("--target-dir") + .arg(&transcript) + .current_dir(manifest_dir())); + // Every segment aligns to the 16 KB pages Google Play requires of a 64-bit library from // 2027-02-01, whichever NDK built it: r27 and older align to 4 KB unless told otherwise. let lib = dir.join("lib").join(&abi).join("libapi.so"); @@ -1123,16 +1224,25 @@ fn api_android() { .arg("push") .arg(dex.join("classes.dex")) .arg(dir.join("lib").join(&abi).join("libapi.so")) + .arg( + transcript + .join(target) + .join("debug") + .join("examples") + .join("transcript"), + ) .arg(DEVICE)); + let native = run(Command::new(&adb).args(["shell", &format!("{DEVICE}/transcript")])); + let native = String::from_utf8_lossy(&native.stdout); let art = |args: &[&str]| { let args: String = args.iter().map(|arg| format!(" '{arg}'")).collect(); let mut cmd = Command::new(&adb); cmd.arg("shell").arg(format!( - "ANDROID_DATA={DEVICE} dalvikvm -Djava.library.path={DEVICE} -cp {DEVICE}/classes.dex ApiKt{args}" + "ANDROID_DATA={DEVICE} dalvikvm -Xcheck:jni -Djava.library.path={DEVICE} -cp {DEVICE}/classes.dex ApiKt{args}" )); cmd }; - kotlin(&api.transcript, &art); + kotlin(&native, &art); // An abort or a panic must reach logcat and bionic's abort message, which the tombstone // shows: an app's stderr goes nowhere. The tombstone is logged as the crash dump @@ -1304,15 +1414,15 @@ fn newest(dir: &Path) -> PathBuf { /// contract it fails loud on. fn kotlin(native: &str, vm: &dyn Fn(&[&str]) -> Command) { let kt = run(&mut vm(&[])); + jni_checked(&kt, "the Kotlin transcript"); assert_eq!( String::from_utf8_lossy(&kt.stdout), native, "the Kotlin transcript differs from the native one" ); - run(&mut vm(&["futures"])); - run(&mut vm(&["owned"])); - run(&mut vm(&["clash"])); - run(&mut vm(&["checks"])); + for case in ["futures", "owned", "clash", "checks"] { + jni_checked(&run(&mut vm(&[case])), case); + } for (case, message) in [ ("moved", "IllegalStateException: Counter is closed"), ("boxed moved", "IllegalStateException: Node is closed"), @@ -1332,11 +1442,26 @@ fn kotlin(native: &str, vm: &dyn Fn(&[&str]) -> Command) { // status reports a core though none is written. let output = no_core(&mut vm(&[case])).output().unwrap(); assert!(!output.status.success(), "Kotlin {case} did not fail"); + // A throwing closure is where a JNI call may follow a pending exception. + jni_checked(&output, case); let stderr = String::from_utf8_lossy(&output.stderr); assert!(stderr.contains(message), "Kotlin {case} printed {stderr}"); } } +/// Asserts the run of `what` drew no warning from HotSpot's CheckJNI, which only warns of +/// a JNI call while an exception may be pending or of a local reference past its frame's +/// capacity, and on stdout. ART's CheckJNI aborts instead. +fn jni_checked(output: &Output, what: &str) { + for printed in [&output.stdout, &output.stderr] { + let printed = String::from_utf8_lossy(printed); + assert!( + !printed.contains("WARNING in native method") && !printed.contains("WARNING: JNI"), + "CheckJNI warned in {what}:\n{printed}" + ); + } +} + /// Asserts the run of `what` failed, as a broken contract must, and on Linux, where the test /// programs make themselves non-dumpable, without dumping core: each core costs the host a /// write and a run of its crash handler. Elsewhere the host's own core limit decides. @@ -1393,10 +1518,45 @@ const PYTHON_LIB: &str = match (cfg!(windows), cfg!(target_os = "macos")) { /// contract it fails loud on. #[test] fn api_python() { + python_checks(&std::env::var_os("PYTHON").unwrap_or_else(|| "python3".into())); +} + +/// `api_python`'s checks on a debug build of the newest CPython, which asserts what a +/// release build trusts of the runtime's reference counting, then each of them looped, +/// leaving the interpreter's references and memory blocks as they were. +#[test] +#[ignore = "needs a debug CPython, which builds from source: just ffi sanitize"] +fn api_python_debug() { + let interpreter = std::env::var_os("RUST2_PYTHON_DEBUG") + .expect("RUST2_PYTHON_DEBUG names a debug CPython: run this in the sanitize shell"); + python_checks(&interpreter); + let output = run(Command::new(&interpreter) + .args(["-P", "-X", "dev", "-W", "error"]) + .arg(manifest_dir().join("tests").join("api.py")) + .arg("leaks") + .env( + "PYTHONPATH", + std::env::join_paths([api().out.join("python"), python_transcript()]).unwrap(), + )); + assert!( + output.stdout.is_empty(), + "leaks printed {}", + String::from_utf8_lossy(&output.stdout) + ); +} + +/// The directory of the Python script generated from the transcript, which `tests/api.py` +/// imports. +fn python_transcript() -> PathBuf { + generated("python", "transcript.py", &transcript::python::emit(transcript())) +} + +/// `api_python`'s checks, run by `interpreter`. +fn python_checks(interpreter: &std::ffi::OsStr) { let api = api(); - let scripts = generated("python", "transcript.py", &transcript::python::emit(transcript())); + let scripts = python_transcript(); let python = |dir: &Path, args: &[&str]| { - let mut cmd = Command::new(std::env::var_os("PYTHON").unwrap_or_else(|| "python3".into())); + let mut cmd = Command::new(interpreter); // `-P` keeps `tests/` off the path, where `api.py` is this script; dev mode and // warnings as errors fail on what the runtime only warns of. cmd.args(["-P", "-X", "dev", "-W", "error"]) @@ -1654,8 +1814,7 @@ fn api_swift() { // The test's executor preference is macOS 15's. let exe = dir.join("api-test"); let test = manifest_dir().join("tests").join("api.swift"); - let script = - generated("swift", "transcript.swift", &transcript::swift::emit(transcript())).join("transcript.swift"); + let script = swift_transcript(); // The Clang module the test and the contract program import on Linux. let nodump = manifest_dir().join("tests").join("nodump"); let step = Step { @@ -1781,6 +1940,65 @@ fn api_swift() { ); } +/// `tests/api.swift`'s script, its futures, and what releasing frees, under +/// ThreadSanitizer, against the glue built under it: it catches a race between a wake on +/// Rust's thread and the task it resumes, or an executor's job and a release. +#[test] +#[ignore = "needs the nightly's rust-src and Swift's ThreadSanitizer: just ffi sanitize"] +fn api_swift_tsan() { + let api = api(); + let (glue, native) = sanitized_glue("thread"); + let dir = scratch().join("api").join("swift-thread"); + let module = api.out.join("swift"); + let collections = swift_collections(); + let (swiftmodule, lib) = (dir.join("Api.swiftmodule"), dir.join("libApi.a")); + std::fs::create_dir_all(&dir).unwrap(); + run(swiftc(&module, 13) + .args([ + "-sanitize=thread", + "-swift-version", + "6", + "-parse-as-library", + "-module-name", + "Api", + ]) + .args(["-emit-module", "-emit-module-path"]) + .arg(&swiftmodule) + .args(["-emit-library", "-static", "-o"]) + .arg(&lib) + .arg(module.join("api.swift"))); + let exe = dir.join("api-test"); + run(swiftc(&module, 15) + .args(["-sanitize=thread", "-parse-as-library", "-I"]) + .arg(&dir) + .arg(manifest_dir().join("tests").join("api.swift")) + .arg(swift_transcript()) + .arg(&lib) + .args(&collections) + .arg(&glue) + .args(&native) + .arg("-o") + .arg(&exe)); + // What Swift's own runtime and Dispatch do goes unchecked, as Darwin's default has it: + // they are uninstrumented, so TSan would miss the atomics that order a task's frame + // before its runtime frees it, and report that free as a race. + let env = [("TSAN_OPTIONS", "halt_on_error=1:ignore_noninstrumented_modules=1")]; + let output = run(Command::new(&exe).envs(env)); + assert_eq!( + String::from_utf8_lossy(&output.stdout), + api.transcript, + "the Swift transcript under ThreadSanitizer differs from the native one" + ); + for case in ["checks", "futures", "owned", "shared"] { + run(Command::new(&exe).arg(case).envs(env)); + } +} + +/// The Swift script generated from the transcript, which `tests/api.swift` calls. +fn swift_transcript() -> PathBuf { + generated("swift", "transcript.swift", &transcript::swift::emit(transcript())).join("transcript.swift") +} + /// The api fixture's Swift, built as the module `Api` in Swift 6's language mode. struct SwiftApi { dir: PathBuf, @@ -2061,7 +2279,8 @@ fn web_checks(runtime: &str, cases: &[&str], ran: &mut dyn FnMut(Option<&str>) - } } -/// `tests/api.ts`'s script on `runtime`, Node or Deno, with `case`, from beside the binding. +/// `tests/api.ts`'s script on `runtime`, Node, Deno, or Bun, with `case`, from beside the +/// binding. fn web_script(runtime: &str, case: Option<&str>) -> Command { let web = web(); let mut cmd = Command::new(runtime); @@ -2120,15 +2339,15 @@ fn web_protocol(runtime: &str, name: &str, first: u64, count: u64, steps: usize) protocol::check_all(&dir, &scripts, driver); } -/// The generated TypeScript runs `tests/api.ts`'s script on Node and on Deno, over the module -/// the crate's `web` feature builds for wasm32-wasip1: it prints what native Rust prints on -/// that target, then checks its futures, what disposing and the garbage collector free, what -/// a closed object refuses, how bytes cross, and what a call lent bytes reads once memory -/// grows, and fails loud on each contract it breaks; a binding of another contract refuses -/// the module. +/// The generated TypeScript runs `tests/api.ts`'s script on Node, Deno, and Bun, over the +/// module the crate's `web` feature builds for wasm32-wasip1: it prints what native Rust +/// prints on that target, then checks its futures, what disposing and the garbage collector +/// free, what a closed object refuses, how bytes cross, and what a call lent bytes reads once +/// memory grows, and fails loud on each contract it breaks; a binding of another contract +/// refuses the module. #[test] fn api_web() { - for runtime in ["node", "deno"] { + for runtime in ["node", "deno", "bun"] { web_checks(runtime, &WEB_CASES, &mut |case| { output(&mut web_script(runtime, case)).into() }); diff --git a/ffi/tests/fixtures/transcript/kotlin.rs b/ffi/tests/fixtures/transcript/kotlin.rs index 6766c333d..4a3b07118 100644 --- a/ffi/tests/fixtures/transcript/kotlin.rs +++ b/ffi/tests/fixtures/transcript/kotlin.rs @@ -971,6 +971,11 @@ fn int(n: Num, ty: &Type) -> String { Int::U8 => format!("{n}.toUByte()"), Int::U16 => format!("{n}.toUShort()"), Int::U32 => format!("{n}u"), + // One Kotlin binding serves every target, so a pointer-sized bound, which a 64-bit + // host folds to its own, is the library's, which api.kt reads from its pointer width. + Int::Usize if n == Num::new(u64::MAX.into()) => "usizeMax()".to_string(), + Int::Isize if n == Num::new(i64::MAX.into()) => "isizeRange().last".to_string(), + Int::Isize if n == Num::new(i64::MIN.into()) => "isizeRange().first".to_string(), Int::U64 | Int::Usize => format!("{n}uL"), Int::I8 => format!("({n}).toByte()"), Int::I16 => format!("({n}).toShort()"), diff --git a/flake.nix b/flake.nix index 28127d0c0..a538dd878 100644 --- a/flake.nix +++ b/flake.nix @@ -338,10 +338,15 @@ devShells.clang = self.devShells.${system}.default.overrideAttrs (old: { nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.clang ]; }); - # `just ffi sanitize` builds the glue with the nightly's sanitizers, linked by clang, and - # runs it under the nightly's Miri. llvm-symbolizer names the frames of a report. + # `just ffi sanitize` builds the glue with the nightly's sanitizers, linked by clang, + # runs it under the nightly's Miri and Valgrind, and runs the Python on a debug build of + # the newest CPython, which nothing caches. llvm-symbolizer names a report's frames. devShells.sanitize = self.devShells.${system}.clang.overrideAttrs (old: { - nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.llvm ]; + nativeBuildInputs = old.nativeBuildInputs ++ [ + pkgs.llvm + pkgs.valgrind + ]; + RUST2_PYTHON_DEBUG = "${pkgs.python315.override { enableDebug = true; }}/bin/python3"; RUST2_TS_TOOLCHAIN = tsToolchain.override { extensions = (builtins.fromTOML (builtins.readFile ./ts/rust-toolchain.toml)).toolchain.components @@ -352,14 +357,15 @@ }); # `just ffi android` builds the Kotlin's library for an Android device, with the NDK # cargo-ndk finds through ANDROID_NDK_HOME, and `just ffi moq-api` stages moq's API on - # each Android ABI moq ships: the SDK and NDK are the caller's, as moq's Android build - # takes the GitHub runner image's. + # each Android ABI moq ships, and the x86 emulator runs the 32-bit test: the SDK and + # NDK are the caller's, as moq's Android build takes the GitHub runner image's. devShells.android = self.devShells.${system}.default.overrideAttrs (old: { nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.cargo-ndk ]; RUST2_TS_TOOLCHAIN = tsToolchain.override { targets = (builtins.fromTOML (builtins.readFile ./ts/rust-toolchain.toml)).toolchain.targets ++ [ "aarch64-linux-android" "armv7-linux-androideabi" + "i686-linux-android" "x86_64-linux-android" ]; }; diff --git a/quest/m1/ffi-export/kotlin-narrow.md b/quest/m1/ffi-export/kotlin-narrow.md new file mode 100644 index 000000000..500481c8d --- /dev/null +++ b/quest/m1/ffi-export/kotlin-narrow.md @@ -0,0 +1,40 @@ +# [M] Kotlin: a closure's usize too wide for a 32-bit target throws + +## Goal + +On a 32-bit Android ABI (armv7, x86), a Kotlin closure or callback that returns a `ULong` +past `usize::MAX`, or a `Long` outside `isize`'s range, raises `IllegalArgumentException` +at the Kotlin call that reached the closure, as an out-of-range argument does, instead of +aborting the process. The binding checks the width in Kotlin, against the library's +pointer width read once at load, never in the Rust glue. `tests/api.kt`'s `lossless()` +checks it on the 32-bit emulator that the nightly runs. + +## Plan + +Decided with the maintainer on 2026-11-19, in the pick of [#891](https://github.com/kixel-ai/rust2/pull/891): ✅ kept, and the binding checks the width in Kotlin against the library's pointer width, read once at load (rejected: checking it in the Rust glue; dropping the quest). + +Found by the checkers quest's review +([kixel-ai/rust2#891](https://github.com/kixel-ai/rust2/pull/891)). Kotlin crosses +`usize` as a 64-bit `Long` on every target, since one binding serves them all. + +The check itself is in place: `to_signed` (`ffi/src/kotlin.rs`) wraps every `usize` and +`isize` that Kotlin hands over, whether a parameter, a record field, an encoded value, or +a closure's return, in `_Native.__usize` or `__isize` (`ffi/runtime/rt.kt`). Those helpers +check the value against the library's `usize::MAX`, read once at load through +`__usize_max`, and throw `__Invalid`, an `IllegalArgumentException`, before the value +crosses. So an argument or field out of range already throws and leaves the call unmade, +and `rt::narrow` (`ffi/runtime/jni.rs`) never fails for a value Kotlin passes. Keep it +that way: no width check moves into the Rust glue. + +Left: carrying a closure return's exception out. There `__usize` throws inside the upcall, +and `rt::upcall`'s `rt::threw` aborts on the pending exception, as it does for anything a +closure with no `Result` return throws. The exception has to cross the Rust frames between +the upcall and the outer Kotlin call. One way: the upcall leaves the exception pending, +returns a zeroed value, and marks the thread so that each Rust frame between it and the +outermost JNI entry returns at once; that entry then lets JNI rethrow. Without unwinding, +the Rust code in between would keep running on a value the closure never returned, which +breaks the source's semantics. Scope it to the width check's `__Invalid`: any other throw +from a closure keeps aborting, as the repository's rules allow where Rust has no error +path. Sized M, not S, for that unwinding. + +Public API: none. A behavior change: an abort becomes an exception. diff --git a/quest/m1/ffi-proofs/arm-sanitizers.md b/quest/m1/ffi-proofs/arm-sanitizers.md new file mode 100644 index 000000000..1a3e9d011 --- /dev/null +++ b/quest/m1/ffi-proofs/arm-sanitizers.md @@ -0,0 +1,28 @@ +# [S] The nightly sanitizers run on the arm runner + +## Goal + +The nightly's `ffi-sanitize` job passes on `ubuntu-24.04-arm`. Today `api_asan`, +`api_tsan`, and `api_swift_tsan` fail there on their first program run, which prints +nothing. Each one passes on x86_64 Linux. + +## Plan + +Decided with the maintainer on 2026-11-19, in the pick of [#891](https://github.com/kixel-ai/rust2/pull/891): ✅ kept (rejected: dropping it). + +Found by the checkers quest +([kixel-ai/rust2#891](https://github.com/kixel-ai/rust2/pull/891)). The job has failed on +every nightly since it was added on 2026-11-14, for example +[run 44339014570](https://github.com/kixel-ai/rust2/actions/runs/44339014570). Valgrind, +Miri, Go's race detector, and the debug CPython in the same job pass. + +A failed run now names its exit status (`check` in `ffi/tests/fixtures.rs`). Read that +first. The leading suspect is the runner kernel's ASLR entropy (`vm.mmap_rnd_bits`): it +breaks the sanitizer runtimes' shadow layouts, and the common fix lowers it with `sysctl` +in the job. The other suspect is a mismatch between nixpkgs clang's compiler-rt and the +nightly rustc's instrumentation on aarch64. Fix the cause, not the symptom. Running on +x86_64 instead would hide it. + +## Hosts + +- linux - the failure is on aarch64 Linux; reproduce on an arm64 Linux host or the runner diff --git a/quest/m1/ffi-proofs/checkers.md b/quest/m1/ffi-proofs/checkers.md deleted file mode 100644 index 6045c29bd..000000000 --- a/quest/m1/ffi-proofs/checkers.md +++ /dev/null @@ -1,28 +0,0 @@ -# [M] Run every language's own checkers - -## Goal - -The nightly sanitize job, or the gate where a check is fast, adds: - -- UBSan with ASan on the C and C++ tests, and Valgrind memcheck on both against the - uninstrumented library; -- Go's `GOEXPERIMENT=cgocheck2`, and an empty `goroutineleak` profile after the futures - and cancel cases; -- CheckJNI on HotSpot (`-Xcheck:jni`) and on ART; -- the Swift test under ThreadSanitizer; -- Bun as a runtime of the web binding's test, beside Node and Deno; -- a 32-bit ART run (x86 emulator at API 24), since moq stages armv7 and only 64-bit ABIs - run today; -- the Python test looped under a debug CPython, with `sys.gettotalrefcount()` and - `sys.getallocatedblocks()` flat across iterations, and a run on CPython 3.15. - -## Plan - -Found by the 2026-11-18 language audit. `just ffi sanitize` covers C, C++, Go's race -detector, and Miri; nothing runs the others. The Python runtime does about 3,000 lines of -manual reference counting. - -Each check that finds a bug gets the fix in this PR, or a quest. Say how much each added -gate check costs. - -Public API: none.