From a9cf738c2ddb649d4996dd61c53c852abb8c2ff4 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 17:17:11 -0800 Subject: [PATCH 01/17] chore(quest): claim quest/m1/ffi-refusals/stale-excludes.md Quest-Claim: 8b870963cacd9492 From 0c3e41c22dab5c9ee76247bd485f0af435cd0873 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 17:50:35 -0800 Subject: [PATCH 02/17] fix(ffi): exclude only what moq's export refuses, checked by the census Drops 26 stale excludes so just ffi moq builds them, and just ffi census fails on an exclude that names an item that exports. Co-Authored-By: Claude Opus 5.5 --- ffi/justfile | 7 +++- ffi/moq/ffi.toml | 52 ++++++------------------- ffi/moq/moq.swift | 2 +- quest/m1/ffi-refusals/README.md | 6 +-- quest/m1/ffi-refusals/no-config.md | 1 - quest/m1/ffi-refusals/stale-excludes.md | 31 --------------- 6 files changed, 22 insertions(+), 77 deletions(-) delete mode 100644 quest/m1/ffi-refusals/stale-excludes.md diff --git a/ffi/justfile b/ffi/justfile index fc4c72ddd..f37c0a642 100644 --- a/ffi/justfile +++ b/ffi/justfile @@ -46,9 +46,14 @@ fix: run *args: cargo run --locked --quiet -- {{ args }} -# Census the stand-in facade moq/ffi.toml exports into target/census/moq-ffi.md, from the pinned moq revision or a checkout. +# Census the stand-in facade moq/ffi.toml exports into target/census/moq-ffi.md, from the pinned moq revision or a checkout, failing when moq/ffi.toml excludes an item that exports. census checkout="": (standin checkout) + #!/usr/bin/env bash + set -euo pipefail cargo run --locked --quiet -- --config moq/ffi.toml --manifest-path target/moq-ffi/Cargo.toml --census target/census + # The exporter already rejects an exclude that names nothing exported; this rejects one that names what exports. + stale=$(comm -23 <(sed -n 's/^ "\(.*\)",$/\1/p' moq/ffi.toml | sort) <(sed -n '/^exclude = \[/,/^]/s/^ "\(.*\)",$/\1/p' target/census/moq-ffi.md | sort)) + [ -z "$stale" ] || { printf 'moq/ffi.toml excludes what now exports; drop:\n%s\n' "$stale" >&2; exit 1; } # Measure the binding benchmark (bench/ffi/README.md) from the pinned moq revision or a checkout, in the bench shell: nix develop .#bench. Its tables go to target/bench/report.md. bench checkout="": (bench-build checkout) bench-run diff --git a/ffi/moq/ffi.toml b/ffi/moq/ffi.toml index 495076140..235177e03 100644 --- a/ffi/moq/ffi.toml +++ b/ffi/moq/ffi.toml @@ -3,74 +3,52 @@ # still has to cover. `kio` is moq-net's re-export of all of kio, of which moq-ffi ships # only what the facade re-exports. exclude = [ - "bytes", "Client::connect", + "bytes", "clock::Deadlines::enter", "clock::Entered", - "clock::rng", "clock::Rng", + "clock::rng", "frame::Buffer::drain", - "frame::Producer::group", - "group::Consumer::poll_read_frames", - "hang::container::Frame::encode", "hang::moq_net", "kio", "mux::catalog::Guard", "mux::catalog::Producer::modify", "mux::catalog::Producer::modify", "mux::catalog::Producer::modify", - "mux::codec::aac::Config::parse", - "mux::codec::annexb::from_length_prefixed", - "mux::codec::annexb::length_prefixed_to_annexb", - "mux::codec::opus::Config::parse", - "mux::container::fmp4::mp4_atom", - "mux::container::fmp4::Wire::new", - "mux::container::fmp4::Wire::trak", - "mux::container::Producer::modify", "mux::container::Producer::modify", "mux::container::Producer::modify", "mux::container::Producer::modify", "mux::container::Producer::modify", "mux::container::Producer::modify", - "mux::container::Producer::set", - "mux::container::Producer::modify", + "mux::container::Producer::modify", "mux::container::Producer::modify", "mux::container::Producer::modify", "mux::container::Producer::modify", "mux::container::Producer::modify", "mux::container::Producer::modify", - "mux::container::Producer::set", - "mux::container::Producer::modify", + "mux::container::Producer::modify", "mux::container::Producer::modify", "mux::container::Producer::modify", "mux::container::Producer::modify", "mux::container::Producer::modify", "mux::container::Producer::modify", - "mux::container::Producer::set", - "mux::container::Producer::modify", + "mux::container::Producer::modify", "mux::container::Producer::modify", "mux::container::Producer::modify", "mux::container::Producer::modify", "mux::container::Producer::modify", "mux::container::Producer::modify", - "mux::container::Producer::set", - "mux::container::ts::Follower::export", - "mux::container::ts::Follower::export", - "mux::container::ts::Follower::export", - "mux::Source::bind", - "mux::Source::resolve", - "mux::Source::resolve_reference", - "mux::Source::subscribe_track", - "Path::from_static", - "Timestamp::as_micros", - "Timestamp::as_millis", - "Timestamp::as_nanos", - "Timestamp::as_scale", + "mux::container::Producer::modify", + "mux::container::fmp4::Wire::new", + "mux::container::fmp4::Wire::trak", + "mux::container::fmp4::mp4_atom", + "tokio::Server::accept_health", + "tokio::Server::tls_acceptor", "tokio::connect::Config::deprecated", "tokio::connect::Config::goaway", "tokio::connect::Config::resolve", "tokio::connect::Config::websocket", - "tokio::connection::Monitor::poll_presence", "tokio::connection::Monitor::snapshot", "tokio::connection::Monitor::state", "tokio::connection::Monitor::state_changed", @@ -84,23 +62,17 @@ exclude = [ "tokio::quic::Config::controller", "tokio::quic::Config::deprecated", "tokio::quic::Config::resolve", - "tokio::Server::accept_health", "tokio::server::Config::demux", "tokio::server::Config::websocket", "tokio::server::Listener::accept_health", "tokio::server::Request::quic", - "tokio::server::Request::within", "tokio::server::Request::with_quic_limits", - "tokio::Server::tls_acceptor", + "tokio::server::Request::within", "tokio::tls::Connect::build", "tokio::tls::Connect::deprecated", "tokio::tls::Listen::deprecated", "tokio::tls::Listen::load_roots", - "tokio::tls::Listen::server_config", "tokio::tls::PeerIdentity::chain", "tokio::tls::PeerIdentity::from_chain", - "tokio::tls::Serve::config", "tokio::tls::Serve::resolver", - "transport::poll::Ungrouped", - "varint::encode_quic", ] diff --git a/ffi/moq/moq.swift b/ffi/moq/moq.swift index 532010f9b..07d632d5e 100644 --- a/ffi/moq/moq.swift +++ b/ffi/moq/moq.swift @@ -110,7 +110,7 @@ final class Queue: TaskExecutor, @unchecked Sendable { } func launch(_ body: @escaping @Sendable () async throws -> Void) { - Task(executorPreference: self, operation: body) + _ = Task(executorPreference: self, operation: body) } } diff --git a/quest/m1/ffi-refusals/README.md b/quest/m1/ffi-refusals/README.md index cf3ebae85..af2b81625 100644 --- a/quest/m1/ffi-refusals/README.md +++ b/quest/m1/ffi-refusals/README.md @@ -77,9 +77,9 @@ Decided with the maintainer on 2026-11-12, in the quest audit: refuses 94 items and 5 types at the pin, behind `ffi/moq/ffi.toml`'s 100 excludes, and moq's `main` adds the 36 errors [the pin bump](/quest/m1/ffi-refusals/moq-pin.md) measured. So each construct left has a child again: - [`NonZero`](/quest/m1/ffi-refusals/nonzero.md), - [the rest at moq's main](/quest/m1/ffi-refusals/moq-main.md), and - [the excludes that hide what exports](/quest/m1/ffi-refusals/stale-excludes.md); the + [`NonZero`](/quest/m1/ffi-refusals/nonzero.md) and + [the rest at moq's main](/quest/m1/ffi-refusals/moq-main.md); `just ffi census` + fails on an exclude that names what exports. The bump is then only the bump. The types refused for not being `Send` (`clock::Entered`, `clock::Rng`, `catalog::Guard`) clear with [not-send](/quest/m1/ffi-export/not-send.md). - ✅ The closing work is a child, [no config](/quest/m1/ffi-refusals/no-config.md), as diff --git a/quest/m1/ffi-refusals/no-config.md b/quest/m1/ffi-refusals/no-config.md index d8ea045b9..5134f1bbe 100644 --- a/quest/m1/ffi-refusals/no-config.md +++ b/quest/m1/ffi-refusals/no-config.md @@ -30,5 +30,4 @@ that passes them). ## Required - [The moq pin bump](/quest/m1/ffi-refusals/moq-pin.md) - the pin is at moq's `main`, where the census is taken -- [No exclude hides what exports](/quest/m1/ffi-refusals/stale-excludes.md) - the list is down to what the export refuses - [Not Send](/quest/m1/ffi-export/not-send.md) - exports the three types the census still refuses for not being `Send` diff --git a/quest/m1/ffi-refusals/stale-excludes.md b/quest/m1/ffi-refusals/stale-excludes.md deleted file mode 100644 index 59ee22692..000000000 --- a/quest/m1/ffi-refusals/stale-excludes.md +++ /dev/null @@ -1,31 +0,0 @@ -# [S] No exclude hides what exports - -## Goal - -`ffi/moq/ffi.toml` excludes only what the export refuses: a new check fails the nightly -when an exclude names an item that now exports, so the list shrinks as the exporter grows -and `just ffi moq` builds everything that maps. - -## Plan - -Found by the 2026-11-12 audit, comparing the file against the 2026-11-11 nightly census's -"config that exports what maps" -([run 43038758163](https://github.com/moq-dev/rust2/actions/runs/43038758163)): 28 of the -100 excludes name items that export, such as `Path::from_static`, the -`Timestamp::as_*` conversions, `mux::Source`'s methods, and `varint::encode_quic`, so -`just ffi moq` never builds what -[#675](https://github.com/moq-dev/rust2/pull/675) and -[#678](https://github.com/moq-dev/rust2/pull/678) made exportable. At moq's `main`, 11 -more name nothing exported ([the pin bump](/quest/m1/ffi-refusals/moq-pin.md)). Measure -both again first. - -- Drop every exclude the census does not need. -- Nothing enforces this today. The exporter rejects only an exclude that names nothing - exported (`ffi/src/driver.rs`), and `nightly.yml` runs the census, summarizes it, and - uploads it without comparing. Add the comparison: the census already prints the config - that exports what maps, and the nightly's moq job fails when `ffi/moq/ffi.toml` differs - from it. -- The file goes with [the epic](/quest/m1/ffi-refusals/README.md); until then it is - exact. - -Public API: none. From 929c8dcc48668cf4fae2ea2f3513faccd8f30c38 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 18:21:48 -0800 Subject: [PATCH 03/17] fix(ffi): match stale excludes by the exporter's own keys, in the census The census records each item a config exclude names and lists those that export, treating generic and prefix keys as the export does; just ffi census fails on that list. Co-Authored-By: Claude Opus 5.5 --- ffi/justfile | 6 +----- ffi/src/census.rs | 20 ++++++++++++++++++++ ffi/src/collect.rs | 12 ++++++++++++ ffi/src/driver.rs | 5 +++++ ffi/tests/fixtures.rs | 6 ++++++ quest/m1/ffi-refusals/README.md | 2 +- 6 files changed, 45 insertions(+), 6 deletions(-) diff --git a/ffi/justfile b/ffi/justfile index f37c0a642..ba45c2bbb 100644 --- a/ffi/justfile +++ b/ffi/justfile @@ -48,12 +48,8 @@ run *args: # Census the stand-in facade moq/ffi.toml exports into target/census/moq-ffi.md, from the pinned moq revision or a checkout, failing when moq/ffi.toml excludes an item that exports. census checkout="": (standin checkout) - #!/usr/bin/env bash - set -euo pipefail cargo run --locked --quiet -- --config moq/ffi.toml --manifest-path target/moq-ffi/Cargo.toml --census target/census - # The exporter already rejects an exclude that names nothing exported; this rejects one that names what exports. - stale=$(comm -23 <(sed -n 's/^ "\(.*\)",$/\1/p' moq/ffi.toml | sort) <(sed -n '/^exclude = \[/,/^]/s/^ "\(.*\)",$/\1/p' target/census/moq-ffi.md | sort)) - [ -z "$stale" ] || { printf 'moq/ffi.toml excludes what now exports; drop:\n%s\n' "$stale" >&2; exit 1; } + @awk '/^## /{f = /though it exports$/} f {print; bad = 1} END {exit bad}' target/census/moq-ffi.md >&2 # Measure the binding benchmark (bench/ffi/README.md) from the pinned moq revision or a checkout, in the bench shell: nix develop .#bench. Its tables go to target/bench/report.md. bench checkout="": (bench-build checkout) bench-run diff --git a/ffi/src/census.rs b/ffi/src/census.rs index 23705edb5..76034d23d 100644 --- a/ffi/src/census.rs +++ b/ffi/src/census.rs @@ -184,6 +184,26 @@ pub fn render(api: &Api, collected: &Report, clashes: &[Clash], at: &dyn Fn(Span let _ = writeln!(out, "- `{path}`: {count} items"); } } + // An exclude that names what exports leaves out more than the export needs. A member + // of a refused type does not export either. + let refused: Vec<&str> = (collected.refusals.iter().map(|r| r.path.as_str())) + .chain(collected.unheld.iter().map(|(path, _)| path.as_str())) + .collect(); + let under = |path: &str| { + (refused.iter()).any(|r| path == *r || path.strip_prefix(r).is_some_and(|rest| rest.starts_with("::"))) + }; + let mut exporting = String::new(); + for (exclude, named) in &collected.audited { + let mut exported: Vec<&str> = named.iter().map(String::as_str).filter(|path| !under(path)).collect(); + exported.sort(); + exported.dedup(); + if !exported.is_empty() { + let _ = writeln!(exporting, "- `{exclude}`: `{}`", exported.join("`, `")); + } + } + if !exporting.is_empty() { + let _ = writeln!(out, "\n## Excluded by the config, though it exports\n\n{exporting}"); + } if !collected.hidden.is_empty() { let _ = writeln!(out, "\n## `#[doc(hidden)]`, left out\n"); for path in &collected.hidden { diff --git a/ffi/src/collect.rs b/ffi/src/collect.rs index e2a8b1b08..f49d44679 100644 --- a/ffi/src/collect.rs +++ b/ffi/src/collect.rs @@ -95,6 +95,9 @@ pub struct Facade<'a> { pub package: &'a str, /// Paths from its root the config leaves out. pub exclude: &'a [String], + /// Paths from its root a census checks, without leaving out what they name: each + /// item one names is recorded in [`Report::audited`]. + pub audit: &'a [String], } /// What collection found in the facade, by paths from its root. @@ -115,6 +118,8 @@ pub struct Report { pub unheld: Vec<(String, Why)>, /// Excluded paths, and how many items each left out. pub excluded: Vec<(String, usize)>, + /// A census's audited paths, and the path of each item one names. + pub audited: Vec<(String, Vec)>, /// Type aliases, which export nothing of their own. pub aliases: Vec, } @@ -302,6 +307,7 @@ pub fn collect<'tcx>(tcx: TyCtxt<'tcx>, facade: &Facade<'_>) -> Collected { hidden: Vec::new(), unheld: Vec::new(), excluded: facade.exclude.iter().map(|path| (path.clone(), 0)).collect(), + audited: facade.audit.iter().map(|path| (path.clone(), Vec::new())).collect(), aliases: Vec::new(), }, instances: Vec::new(), @@ -538,6 +544,12 @@ impl<'tcx> Collector<'tcx> { return true; } } + for (_, key) in config::keys(&path[1..]) { + if let Some((_, named)) = report.audited.iter_mut().find(|(audited, _)| *audited == key) { + named.push(path[1..].join("::")); + break; + } + } false } diff --git a/ffi/src/driver.rs b/ffi/src/driver.rs index 27c89442d..105d8447d 100644 --- a/ffi/src/driver.rs +++ b/ffi/src/driver.rs @@ -136,6 +136,11 @@ impl Callbacks for Export { Output::Census(_) => &[], Output::Dir(_) | Output::Api(_) => &self.config.exclude, }, + // It lists instead each item one names that exports. + audit: match self.output { + Output::Census(_) => &self.config.exclude, + Output::Dir(_) | Output::Api(_) => &[], + }, }; let collected = collect::collect(tcx, &facade); let report = &collected.report; diff --git a/ffi/tests/fixtures.rs b/ffi/tests/fixtures.rs index a348ea731..6802e7d2f 100644 --- a/ffi/tests/fixtures.rs +++ b/ffi/tests/fixtures.rs @@ -1301,6 +1301,12 @@ fn relative_target() { "- `Void`: object no export returns", "- `release`: type C never holds `Lease`", "- `Unnamed`: generic type no export instantiates", + // An exclude that names what exports, generic and instance keys alike, but not one + // that names only what is refused. + "## Excluded by the config, though it exports", + "- `Layer`: `Layer`", + "- `Timed`: `Timed`, `Timed`", + "- `Pair::swap`: `Pair::swap`", ] { assert!(text.contains(line), "the census lists no `{line}`:\n{text}"); } diff --git a/quest/m1/ffi-refusals/README.md b/quest/m1/ffi-refusals/README.md index af2b81625..c6b547a15 100644 --- a/quest/m1/ffi-refusals/README.md +++ b/quest/m1/ffi-refusals/README.md @@ -74,7 +74,7 @@ Decided with the maintainer on 2026-11-12, in the quest audit: [#710](https://github.com/moq-dev/rust2/pull/710), yet the Goal is not reached: the 2026-11-11 nightly census ([run 43038758163](https://github.com/moq-dev/rust2/actions/runs/43038758163)) still - refuses 94 items and 5 types at the pin, behind `ffi/moq/ffi.toml`'s 100 excludes, and + refuses 94 items and 5 types at the pin, behind `ffi/moq/ffi.toml`'s then 100 excludes, and moq's `main` adds the 36 errors [the pin bump](/quest/m1/ffi-refusals/moq-pin.md) measured. So each construct left has a child again: [`NonZero`](/quest/m1/ffi-refusals/nonzero.md) and From 77e0b4058412af2186f64a132c2fb8ec479e694e Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 18:31:21 -0800 Subject: [PATCH 04/17] fix(ffi): audit no module, and match field@ and every left-out list Co-Authored-By: Claude Opus 5.5 --- ffi/src/census.rs | 16 ++++++++++++---- ffi/src/collect.rs | 10 ++++++++-- ffi/tests/fixtures.rs | 5 +++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/ffi/src/census.rs b/ffi/src/census.rs index 76034d23d..99cc1b105 100644 --- a/ffi/src/census.rs +++ b/ffi/src/census.rs @@ -184,13 +184,21 @@ pub fn render(api: &Api, collected: &Report, clashes: &[Clash], at: &dyn Fn(Span let _ = writeln!(out, "- `{path}`: {count} items"); } } - // An exclude that names what exports leaves out more than the export needs. A member - // of a refused type does not export either. - let refused: Vec<&str> = (collected.refusals.iter().map(|r| r.path.as_str())) + // An exclude that names what exports leaves out more than the export needs. What the + // export leaves out otherwise does not export, nor does a member of it, and a field not + // shared with a method is refused without its `field@`. + let left_out: Vec<&str> = (collected.refusals.iter().map(|r| r.path.as_str())) .chain(collected.unheld.iter().map(|(path, _)| path.as_str())) + .chain(collected.traits.iter().map(|(path, _)| path.as_str())) + .chain(collected.twins.iter().map(String::as_str)) + .chain(collected.hidden.iter().map(String::as_str)) + .chain(collected.aliases.iter().map(String::as_str)) .collect(); let under = |path: &str| { - (refused.iter()).any(|r| path == *r || path.strip_prefix(r).is_some_and(|rest| rest.starts_with("::"))) + let bare = path.strip_prefix("field@").unwrap_or(path); + (left_out.iter()).any(|r| { + [path, bare].iter().any(|path| *path == *r || path.strip_prefix(r).is_some_and(|rest| rest.starts_with("::"))) + }) }; let mut exporting = String::new(); for (exclude, named) in &collected.audited { diff --git a/ffi/src/collect.rs b/ffi/src/collect.rs index f49d44679..3cf20263e 100644 --- a/ffi/src/collect.rs +++ b/ffi/src/collect.rs @@ -537,6 +537,12 @@ impl<'tcx> Collector<'tcx> { /// Whether the config excludes `path`, counting the exclusion. A member of an instance /// is left out by its instance's path or its type's, which leaves it out of each. fn exclude(&mut self, path: &[String]) -> bool { + self.exclude_audited(path, true) + } + + /// [`Self::exclude`], recording the item for a census's audit only if `audit`: a + /// module exports only through its items, each audited on its own. + fn exclude_audited(&mut self, path: &[String], audit: bool) -> bool { let report = &mut self.report; for (_, key) in config::keys(&path[1..]) { if let Some((_, count)) = report.excluded.iter_mut().find(|(excluded, _)| *excluded == key) { @@ -544,7 +550,7 @@ impl<'tcx> Collector<'tcx> { return true; } } - for (_, key) in config::keys(&path[1..]) { + for (_, key) in config::keys(&path[1..]).filter(|_| audit) { if let Some((_, named)) = report.audited.iter_mut().find(|(audited, _)| *audited == key) { named.push(path[1..].join("::")); break; @@ -1111,7 +1117,7 @@ impl<'tcx> Collector<'tcx> { } let mut modules = modules.clone(); modules.push(def_id); - if self.exclude(&path) { + if self.exclude_audited(&path, kind != DefKind::Mod) { self.left_out.insert(def_id, "excluded type"); continue; } diff --git a/ffi/tests/fixtures.rs b/ffi/tests/fixtures.rs index 6802e7d2f..65e086b3c 100644 --- a/ffi/tests/fixtures.rs +++ b/ffi/tests/fixtures.rs @@ -1310,6 +1310,11 @@ fn relative_target() { ] { assert!(text.contains(line), "the census lists no `{line}`:\n{text}"); } + let exporting = text.split("## Excluded by the config, though it exports").nth(1).unwrap(); + let exporting = exporting.split("\n## ").next().unwrap(); + for refused in ["- `Copied`", "- `Sample`", "- `Queued`"] { + assert!(!exporting.contains(refused), "the census lists `{refused}` as exporting:\n{exporting}"); + } assert!(dir.join("build").exists()); } From aa23d03fa8fa740b13d851c44e9ee2adf2d398f6 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 18:34:36 -0800 Subject: [PATCH 05/17] style(ffi): format the census test Co-Authored-By: Claude Opus 5.5 --- ffi/src/census.rs | 4 +++- ffi/src/collect.rs | 29 ++++++++++------------------- ffi/src/dart.rs | 6 ++---- ffi/tests/fixtures.rs | 10 ++++++++-- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/ffi/src/census.rs b/ffi/src/census.rs index 99cc1b105..5783fc386 100644 --- a/ffi/src/census.rs +++ b/ffi/src/census.rs @@ -197,7 +197,9 @@ pub fn render(api: &Api, collected: &Report, clashes: &[Clash], at: &dyn Fn(Span let under = |path: &str| { let bare = path.strip_prefix("field@").unwrap_or(path); (left_out.iter()).any(|r| { - [path, bare].iter().any(|path| *path == *r || path.strip_prefix(r).is_some_and(|rest| rest.starts_with("::"))) + [path, bare] + .iter() + .any(|path| *path == *r || path.strip_prefix(r).is_some_and(|rest| rest.starts_with("::"))) }) }; let mut exporting = String::new(); diff --git a/ffi/src/collect.rs b/ffi/src/collect.rs index 3cf20263e..7760ed15b 100644 --- a/ffi/src/collect.rs +++ b/ffi/src/collect.rs @@ -1876,8 +1876,7 @@ impl<'tcx> Collector<'tcx> { || (api.records.iter()).any(|r| args(&r.args) || fields(&r.fields) || r.methods.iter().any(signature)) || (api.enums.iter()).any(|e| { args(&e.args) || e.variants.iter().any(|v| fields(&v.fields)) || e.methods.iter().any(signature) - }) - || (api.objects.iter()).any(|o| args(&o.args) || o.methods.iter().any(signature)) + }) || (api.objects.iter()).any(|o| args(&o.args) || o.methods.iter().any(signature)) || (api.callbacks.iter()).any(|c| c.methods.iter().any(signature)); if !used { self.api.enums.pop(); @@ -1901,9 +1900,8 @@ impl<'tcx> Collector<'tcx> { || (api.records.iter()).any(|r| args(&r.args) || fields(&r.fields) || r.methods.iter().any(signature)) || (api.enums.iter()).any(|e| { args(&e.args) || e.variants.iter().any(|v| fields(&v.fields)) || e.methods.iter().any(signature) - }) - || (api.objects.iter().enumerate()) - .any(|(i, o)| i != gone && (args(&o.args) || o.methods.iter().any(signature))) + }) || (api.objects.iter().enumerate()) + .any(|(i, o)| i != gone && (args(&o.args) || o.methods.iter().any(signature))) || (api.callbacks.iter()).any(|c| c.methods.iter().any(signature)); if used { continue; @@ -2442,8 +2440,7 @@ impl<'tcx> Collector<'tcx> { // is, takes it from the future, as it would a parameter. ty::Ref(_, inner, _) if Some(*inner) == self_ty - && polled.is_some() - && let Some(kind) = self.task(ty, true) => + && polled.is_some() && let Some(kind) = self.task(ty, true) => { tasks.push(Task { at: 0, kind }); None @@ -3370,8 +3367,7 @@ impl<'tcx> Collector<'tcx> { .inputs() .iter() .filter(|&&input| input == param) - .count() - > 1 + .count() > 1 { return Some(Err(why("closure type taken twice", param.to_string()))); } @@ -3715,16 +3711,11 @@ impl<'tcx> Collector<'tcx> { let plain = matches!( ty.kind(), ty::Adt(..) - | ty::Bool - | ty::Char - | ty::Int(_) - | ty::Uint(_) - | ty::Float(_) - | ty::Str - | ty::Array(..) - | ty::Slice(_) - | ty::Ref(..) - | ty::Tuple(_) + | ty::Bool | ty::Char + | ty::Int(_) | ty::Uint(_) + | ty::Float(_) | ty::Str + | ty::Array(..) | ty::Slice(_) + | ty::Ref(..) | ty::Tuple(_) ); let (method, driven) = match (implements(iterator, ty), implements(into_iterator, ty)) { (true, _) => (next, item), diff --git a/ffi/src/dart.rs b/ffi/src/dart.rs index 78150bdef..fbb78deb7 100644 --- a/ffi/src/dart.rs +++ b/ffi/src/dart.rs @@ -590,12 +590,10 @@ impl<'a> Gen<'a> { !matches!( ty, Ty::Buf - | Ty::U128 - | Ty::Duration + | Ty::U128 | Ty::Duration | Ty::SocketAddr | Ty::Struct(_) - | Ty::Waker - | Ty::ForeignFuture + | Ty::Waker | Ty::ForeignFuture | Ty::ForeignReader ) } diff --git a/ffi/tests/fixtures.rs b/ffi/tests/fixtures.rs index 65e086b3c..c8480bc61 100644 --- a/ffi/tests/fixtures.rs +++ b/ffi/tests/fixtures.rs @@ -1310,10 +1310,16 @@ fn relative_target() { ] { assert!(text.contains(line), "the census lists no `{line}`:\n{text}"); } - let exporting = text.split("## Excluded by the config, though it exports").nth(1).unwrap(); + let exporting = text + .split("## Excluded by the config, though it exports") + .nth(1) + .unwrap(); let exporting = exporting.split("\n## ").next().unwrap(); for refused in ["- `Copied`", "- `Sample`", "- `Queued`"] { - assert!(!exporting.contains(refused), "the census lists `{refused}` as exporting:\n{exporting}"); + assert!( + !exporting.contains(refused), + "the census lists `{refused}` as exporting:\n{exporting}" + ); } assert!(dir.join("build").exists()); } From f92a5a10e1d62ea17542fbc0aeb3fe685ddea97c Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 18:36:36 -0800 Subject: [PATCH 06/17] style(ffi): format with the repo's formatter Co-Authored-By: Claude Opus 5.5 --- ffi/src/collect.rs | 29 +++++++++++++++++++---------- ffi/src/dart.rs | 6 ++++-- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/ffi/src/collect.rs b/ffi/src/collect.rs index 7760ed15b..3cf20263e 100644 --- a/ffi/src/collect.rs +++ b/ffi/src/collect.rs @@ -1876,7 +1876,8 @@ impl<'tcx> Collector<'tcx> { || (api.records.iter()).any(|r| args(&r.args) || fields(&r.fields) || r.methods.iter().any(signature)) || (api.enums.iter()).any(|e| { args(&e.args) || e.variants.iter().any(|v| fields(&v.fields)) || e.methods.iter().any(signature) - }) || (api.objects.iter()).any(|o| args(&o.args) || o.methods.iter().any(signature)) + }) + || (api.objects.iter()).any(|o| args(&o.args) || o.methods.iter().any(signature)) || (api.callbacks.iter()).any(|c| c.methods.iter().any(signature)); if !used { self.api.enums.pop(); @@ -1900,8 +1901,9 @@ impl<'tcx> Collector<'tcx> { || (api.records.iter()).any(|r| args(&r.args) || fields(&r.fields) || r.methods.iter().any(signature)) || (api.enums.iter()).any(|e| { args(&e.args) || e.variants.iter().any(|v| fields(&v.fields)) || e.methods.iter().any(signature) - }) || (api.objects.iter().enumerate()) - .any(|(i, o)| i != gone && (args(&o.args) || o.methods.iter().any(signature))) + }) + || (api.objects.iter().enumerate()) + .any(|(i, o)| i != gone && (args(&o.args) || o.methods.iter().any(signature))) || (api.callbacks.iter()).any(|c| c.methods.iter().any(signature)); if used { continue; @@ -2440,7 +2442,8 @@ impl<'tcx> Collector<'tcx> { // is, takes it from the future, as it would a parameter. ty::Ref(_, inner, _) if Some(*inner) == self_ty - && polled.is_some() && let Some(kind) = self.task(ty, true) => + && polled.is_some() + && let Some(kind) = self.task(ty, true) => { tasks.push(Task { at: 0, kind }); None @@ -3367,7 +3370,8 @@ impl<'tcx> Collector<'tcx> { .inputs() .iter() .filter(|&&input| input == param) - .count() > 1 + .count() + > 1 { return Some(Err(why("closure type taken twice", param.to_string()))); } @@ -3711,11 +3715,16 @@ impl<'tcx> Collector<'tcx> { let plain = matches!( ty.kind(), ty::Adt(..) - | ty::Bool | ty::Char - | ty::Int(_) | ty::Uint(_) - | ty::Float(_) | ty::Str - | ty::Array(..) | ty::Slice(_) - | ty::Ref(..) | ty::Tuple(_) + | ty::Bool + | ty::Char + | ty::Int(_) + | ty::Uint(_) + | ty::Float(_) + | ty::Str + | ty::Array(..) + | ty::Slice(_) + | ty::Ref(..) + | ty::Tuple(_) ); let (method, driven) = match (implements(iterator, ty), implements(into_iterator, ty)) { (true, _) => (next, item), diff --git a/ffi/src/dart.rs b/ffi/src/dart.rs index fbb78deb7..78150bdef 100644 --- a/ffi/src/dart.rs +++ b/ffi/src/dart.rs @@ -590,10 +590,12 @@ impl<'a> Gen<'a> { !matches!( ty, Ty::Buf - | Ty::U128 | Ty::Duration + | Ty::U128 + | Ty::Duration | Ty::SocketAddr | Ty::Struct(_) - | Ty::Waker | Ty::ForeignFuture + | Ty::Waker + | Ty::ForeignFuture | Ty::ForeignReader ) } From 53bfde499294438996d92012190cdbaeb5e2aa22 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 20:03:05 -0800 Subject: [PATCH 07/17] fix(ffi): census flags an exclude by what the export holds, not by inferring it Co-Authored-By: Claude Opus 5.5 --- ffi/fixtures/api/ffi.toml | 5 ++- ffi/fixtures/api/src/lib.rs | 14 ++++++++- ffi/src/census.rs | 43 ++++++++------------------ ffi/src/collect.rs | 19 +++++------- ffi/src/driver.rs | 61 +++++++++++++++++++++++++++++++++++-- ffi/tests/fixtures.rs | 13 +++++--- 6 files changed, 104 insertions(+), 51 deletions(-) diff --git a/ffi/fixtures/api/ffi.toml b/ffi/fixtures/api/ffi.toml index 6a277fe3d..d3ac9115a 100644 --- a/ffi/fixtures/api/ffi.toml +++ b/ffi/fixtures/api/ffi.toml @@ -3,7 +3,8 @@ # `Rooted`, `Copied`, `Stored`, and `Layer` only convert, so their parameters take what # converts into them, and # `field@` leaves out a field alone where a method takes its path, as `Retry`'s and -# `Slot`'s do. `Slot` has no such method, so its path alone names its field. A +# `Slot`'s do, and `Retry::jitter` and `field@Retry::jitter` leave out a refused method +# and its field. `Slot` has no such method, so its path alone names its field. A # function instance is left out by its path, as `depth_past` at `polar::Point` is. exclude = [ "Copied", @@ -15,7 +16,9 @@ exclude = [ "Sample", "Scoped", "Slot::value", + "Retry::jitter", "field@Retry::delay", + "field@Retry::jitter", "field@Slot::value", "Stack::depth_past", "Stored", diff --git a/ffi/fixtures/api/src/lib.rs b/ffi/fixtures/api/src/lib.rs index bc0211779..8fcb55941 100644 --- a/ffi/fixtures/api/src/lib.rs +++ b/ffi/fixtures/api/src/lib.rs @@ -1295,11 +1295,18 @@ pub fn next_packet(packet: Packet) -> Packet { pub struct Retry { pub limit: Option, pub delay: Option, + /// Its field exports, but the method of its name is refused, so the config excludes + /// both, and the census lists only `field@Retry::jitter` as excluding what exports. + pub jitter: u32, } impl Retry { pub fn new(limit: Option) -> Self { - Self { limit, delay: None } + Self { + limit, + delay: None, + jitter: 0, + } } pub fn limit(&self) -> u32 { @@ -1313,6 +1320,11 @@ impl Retry { pub fn set_limit(&mut self, limit: u32) { self.limit = Some(limit); } + + /// The jitter clamped to a range, a tuple, which C refuses. + pub fn jitter(&self, range: (u32, u32)) -> u32 { + self.jitter.clamp(range.0, range.1) + } } /// A digest, as moq's FLAC config holds its MD5: an object, whose array field C reads and diff --git a/ffi/src/census.rs b/ffi/src/census.rs index 5783fc386..498c8216d 100644 --- a/ffi/src/census.rs +++ b/ffi/src/census.rs @@ -10,8 +10,15 @@ use crate::abi::Clash; use crate::collect::{Refusal, Report}; use crate::ir::{Access, Api, Function}; -/// The census of the facade as Markdown; `at` locates a span. -pub fn render(api: &Api, collected: &Report, clashes: &[Clash], at: &dyn Fn(Span) -> String) -> String { +/// The census of the facade as Markdown, listing `exporting`, each exclude whose item +/// would export and its paths; `at` locates a span. +pub fn render( + api: &Api, + collected: &Report, + exporting: &[(String, Vec)], + clashes: &[Clash], + at: &dyn Fn(Span) -> String, +) -> String { let records = &api.records; let enums = &api.enums; let objects: Vec<_> = api.objects.iter().filter(|o| !o.foreign).collect(); @@ -184,35 +191,11 @@ pub fn render(api: &Api, collected: &Report, clashes: &[Clash], at: &dyn Fn(Span let _ = writeln!(out, "- `{path}`: {count} items"); } } - // An exclude that names what exports leaves out more than the export needs. What the - // export leaves out otherwise does not export, nor does a member of it, and a field not - // shared with a method is refused without its `field@`. - let left_out: Vec<&str> = (collected.refusals.iter().map(|r| r.path.as_str())) - .chain(collected.unheld.iter().map(|(path, _)| path.as_str())) - .chain(collected.traits.iter().map(|(path, _)| path.as_str())) - .chain(collected.twins.iter().map(String::as_str)) - .chain(collected.hidden.iter().map(String::as_str)) - .chain(collected.aliases.iter().map(String::as_str)) - .collect(); - let under = |path: &str| { - let bare = path.strip_prefix("field@").unwrap_or(path); - (left_out.iter()).any(|r| { - [path, bare] - .iter() - .any(|path| *path == *r || path.strip_prefix(r).is_some_and(|rest| rest.starts_with("::"))) - }) - }; - let mut exporting = String::new(); - for (exclude, named) in &collected.audited { - let mut exported: Vec<&str> = named.iter().map(String::as_str).filter(|path| !under(path)).collect(); - exported.sort(); - exported.dedup(); - if !exported.is_empty() { - let _ = writeln!(exporting, "- `{exclude}`: `{}`", exported.join("`, `")); - } - } if !exporting.is_empty() { - let _ = writeln!(out, "\n## Excluded by the config, though it exports\n\n{exporting}"); + let _ = writeln!(out, "\n## Excluded by the config, though it exports\n"); + for (exclude, exported) in exporting { + let _ = writeln!(out, "- `{exclude}`: `{}`", exported.join("`, `")); + } } if !collected.hidden.is_empty() { let _ = writeln!(out, "\n## `#[doc(hidden)]`, left out\n"); diff --git a/ffi/src/collect.rs b/ffi/src/collect.rs index 3cf20263e..cbad52a2f 100644 --- a/ffi/src/collect.rs +++ b/ffi/src/collect.rs @@ -96,7 +96,7 @@ pub struct Facade<'a> { /// Paths from its root the config leaves out. pub exclude: &'a [String], /// Paths from its root a census checks, without leaving out what they name: each - /// item one names is recorded in [`Report::audited`]. + /// path one names is recorded in [`Report::audited`], as the exclude would have checked it. pub audit: &'a [String], } @@ -118,7 +118,7 @@ pub struct Report { pub unheld: Vec<(String, Why)>, /// Excluded paths, and how many items each left out. pub excluded: Vec<(String, usize)>, - /// A census's audited paths, and the path of each item one names. + /// A census's audited paths, and each path one names, whether or not that item exports. pub audited: Vec<(String, Vec)>, /// Type aliases, which export nothing of their own. pub aliases: Vec, @@ -534,15 +534,10 @@ impl<'tcx> Collector<'tcx> { self.crates.contains(&krate) } - /// Whether the config excludes `path`, counting the exclusion. A member of an instance - /// is left out by its instance's path or its type's, which leaves it out of each. + /// Whether the config excludes `path`, counting the exclusion, or else recording it under + /// the audited path that names it. A member of an instance is left out by its instance's + /// path or its type's, which leaves it out of each. fn exclude(&mut self, path: &[String]) -> bool { - self.exclude_audited(path, true) - } - - /// [`Self::exclude`], recording the item for a census's audit only if `audit`: a - /// module exports only through its items, each audited on its own. - fn exclude_audited(&mut self, path: &[String], audit: bool) -> bool { let report = &mut self.report; for (_, key) in config::keys(&path[1..]) { if let Some((_, count)) = report.excluded.iter_mut().find(|(excluded, _)| *excluded == key) { @@ -550,7 +545,7 @@ impl<'tcx> Collector<'tcx> { return true; } } - for (_, key) in config::keys(&path[1..]).filter(|_| audit) { + for (_, key) in config::keys(&path[1..]) { if let Some((_, named)) = report.audited.iter_mut().find(|(audited, _)| *audited == key) { named.push(path[1..].join("::")); break; @@ -1117,7 +1112,7 @@ impl<'tcx> Collector<'tcx> { } let mut modules = modules.clone(); modules.push(def_id); - if self.exclude_audited(&path, kind != DefKind::Mod) { + if self.exclude(&path) { self.left_out.insert(def_id, "excluded type"); continue; } diff --git a/ffi/src/driver.rs b/ffi/src/driver.rs index 105d8447d..356c764fa 100644 --- a/ffi/src/driver.rs +++ b/ffi/src/driver.rs @@ -19,7 +19,7 @@ use rustc_span::{FileName, Span, sym}; use crate::abi::Abi; use crate::config::{self, Config}; -use crate::ir::Api; +use crate::ir::{self, Api}; use crate::{census, collect, glue, merge}; /// Run as rustc, with `args` as cargo passed them: the wrapped rustc's path first. @@ -146,7 +146,8 @@ impl Callbacks for Export { let report = &collected.report; if let Output::Census(dir) = &self.output { let abi = Abi::new(&collected.api, &self.facade.lib); - let text = census::render(&collected.api, report, &abi.clashes, &|span| at(tcx, span)); + let exporting = exporting(&collected.api, &report.audited); + let text = census::render(&collected.api, report, &exporting, &abi.clashes, &|span| at(tcx, span)); // A census reports what a crate uses, but a missed instance is the exporter's bug. for refusal in &report.refusals { if refusal.why.iter().any(|why| why.construct == collect::NOT_INFERRED) { @@ -191,6 +192,62 @@ impl Callbacks for Export { } } +/// Each exclude whose item would export without it, and that item's paths: what an +/// exclude checked, from [`collect::Report::audited`], that the census's API holds by the +/// same path. +fn exporting(api: &Api, audited: &[(String, Vec)]) -> Vec<(String, Vec)> { + // Every path an exported item is checked by, from the facade's root, as the walk checks it. + let mut paths = FxHashSet::default(); + let mut add = |path: &[String]| { + paths.insert(path[1..].join("::")); + }; + let mut methods = |methods: &[ir::Function], add: &mut dyn FnMut(&[String])| { + for f in methods { + match f.access { + // A field is checked by `field@` and, unless a method or constant takes its + // name, by its path, which then names that method or constant instead. + ir::Access::Field { shared, .. } => { + let mut key = f.shown.clone(); + key[1].insert_str(0, "field@"); + add(&key); + if !shared { + add(&f.shown); + } + } + _ => add(&f.shown), + } + } + }; + for r in &api.records { + add(&r.shown); + methods(&r.methods, &mut add); + } + for e in &api.enums { + add(&e.shown); + methods(&e.methods, &mut add); + } + for o in &api.objects { + add(&o.shown); + methods(&o.methods, &mut add); + } + for c in &api.callbacks { + add(&c.path); + methods(&c.methods, &mut add); + } + methods(&api.functions, &mut add); + for c in &api.constants { + add(&c.path); + } + (audited.iter()) + .filter_map(|(exclude, named)| { + let mut exported: Vec = named.iter().filter(|path| paths.contains(*path)).cloned().collect(); + exported.sort(); + exported.dedup(); + (!exported.is_empty()).then(|| (exclude.clone(), exported)) + }) + .collect() +} + impl Export { /// This target's API merged with the other targets', or none once a difference /// between two of them is an error. diff --git a/ffi/tests/fixtures.rs b/ffi/tests/fixtures.rs index c8480bc61..156bfe31f 100644 --- a/ffi/tests/fixtures.rs +++ b/ffi/tests/fixtures.rs @@ -1301,12 +1301,14 @@ fn relative_target() { "- `Void`: object no export returns", "- `release`: type C never holds `Lease`", "- `Unnamed`: generic type no export instantiates", - // An exclude that names what exports, generic and instance keys alike, but not one - // that names only what is refused. + // An exclude that names what exports, by its generic or instance path or as a field, + // even where a method of the field's name is refused. "## Excluded by the config, though it exports", - "- `Layer`: `Layer`", - "- `Timed`: `Timed`, `Timed`", + "- `Timed`: `Timed`", "- `Pair::swap`: `Pair::swap`", + "- `Slot::value`: `Slot::value`", + "- `field@Retry::jitter`: `field@Retry::jitter`", + "- `Stack::depth_past`: `Stack::depth_past`", ] { assert!(text.contains(line), "the census lists no `{line}`:\n{text}"); } @@ -1315,7 +1317,8 @@ fn relative_target() { .nth(1) .unwrap(); let exporting = exporting.split("\n## ").next().unwrap(); - for refused in ["- `Copied`", "- `Sample`", "- `Queued`"] { + // Not one that names only what is refused or no export returns. + for refused in ["- `Copied`", "- `Sample`", "- `Queued`", "- `Layer`", "- `Retry::jitter`"] { assert!( !exporting.contains(refused), "the census lists `{refused}` as exporting:\n{exporting}" From a3d3cca550ad1ca28731e472848d1aad63fa218b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 20:22:35 -0800 Subject: [PATCH 08/17] test(ffi): a refused method beside an exporting field of its name Co-Authored-By: Claude Opus 5.5 --- ffi/fixtures/api/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ffi/fixtures/api/src/lib.rs b/ffi/fixtures/api/src/lib.rs index 8fcb55941..18523efdc 100644 --- a/ffi/fixtures/api/src/lib.rs +++ b/ffi/fixtures/api/src/lib.rs @@ -1321,9 +1321,9 @@ impl Retry { self.limit = Some(limit); } - /// The jitter clamped to a range, a tuple, which C refuses. - pub fn jitter(&self, range: (u32, u32)) -> u32 { - self.jitter.clamp(range.0, range.1) + /// The jitter capped by `cap`, if any: a nested `Option`, which the export refuses. + pub fn jitter(&self, cap: Option>>) -> u32 { + cap.and_then(|cap| *cap).map_or(self.jitter, |cap| self.jitter.min(cap)) } } From 7f378b042f8241e176a3428c14c082c0ba68c9fc Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 21:33:47 -0800 Subject: [PATCH 09/17] style(ffi): drop a needless mut, format Co-Authored-By: Claude Opus 5.5 --- ffi/src/driver.rs | 2 +- ffi/tests/fixtures.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ffi/src/driver.rs b/ffi/src/driver.rs index 356c764fa..ac30e0a86 100644 --- a/ffi/src/driver.rs +++ b/ffi/src/driver.rs @@ -201,7 +201,7 @@ fn exporting(api: &Api, audited: &[(String, Vec)]) -> Vec<(String, Vec Date: Thu, 12 Nov 2026 22:21:21 -0800 Subject: [PATCH 10/17] fix(ffi): the census itself fails on an exclude that leaves out what exports Co-Authored-By: Claude Opus 5.5 --- ffi/README.md | 6 ++++-- ffi/justfile | 1 - ffi/src/driver.rs | 7 +++++++ ffi/tests/fixtures.rs | 19 ++++++++++++++++--- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/ffi/README.md b/ffi/README.md index 60386f2f6..29af1f464 100644 --- a/ffi/README.md +++ b/ffi/README.md @@ -885,8 +885,10 @@ runtime package and each crate's include [`runtime/rt.go`](runtime/rt.go) and `--census dir` exports nothing. It writes `.md` for the facade, which counts what exports and ranks every refusal by construct and by the type it names, lists each refused item at its span, then the `exclude` list that exports the rest, and what else it left out, such as what C can never hold and the traits C cannot implement, and why. -It ignores the config's `exclude`. It still fails on an `instance not inferred` -refusal, which is a bug in the exporter's inference rather than in the crate. +It ignores the config's `exclude`, but lists each exclude that leaves out an item that +would export, and fails on it, so the list holds only what the export refuses. It also +fails on an `instance not inferred` refusal, which is a bug in the exporter's inference +rather than in the crate. ## Tests diff --git a/ffi/justfile b/ffi/justfile index ba45c2bbb..561d54adf 100644 --- a/ffi/justfile +++ b/ffi/justfile @@ -49,7 +49,6 @@ run *args: # Census the stand-in facade moq/ffi.toml exports into target/census/moq-ffi.md, from the pinned moq revision or a checkout, failing when moq/ffi.toml excludes an item that exports. census checkout="": (standin checkout) cargo run --locked --quiet -- --config moq/ffi.toml --manifest-path target/moq-ffi/Cargo.toml --census target/census - @awk '/^## /{f = /though it exports$/} f {print; bad = 1} END {exit bad}' target/census/moq-ffi.md >&2 # Measure the binding benchmark (bench/ffi/README.md) from the pinned moq revision or a checkout, in the bench shell: nix develop .#bench. Its tables go to target/bench/report.md. bench checkout="": (bench-build checkout) bench-run diff --git a/ffi/src/driver.rs b/ffi/src/driver.rs index ac30e0a86..220db2172 100644 --- a/ffi/src/driver.rs +++ b/ffi/src/driver.rs @@ -157,6 +157,13 @@ impl Callbacks for Export { if let Err(err) = write(&dir.join(format!("{}.md", report.package)), &text) { tcx.dcx().err(format!("rust2-ffi: {err}")); } + // An exclude that leaves out what would export hides that much of the API. + for (exclude, exported) in &exporting { + tcx.dcx().err(format!( + "rust2-ffi: exclude `{exclude}` in the config leaves out `{}`, which exports", + exported.join("`, `") + )); + } return stop_on_errors(tcx); } for refusal in &report.refusals { diff --git a/ffi/tests/fixtures.rs b/ffi/tests/fixtures.rs index b4fac2009..cf5312ba6 100644 --- a/ffi/tests/fixtures.rs +++ b/ffi/tests/fixtures.rs @@ -1290,10 +1290,23 @@ fn relative_target() { .env("CARGO_TARGET_DIR", "build") .output() .expect("running rust2-ffi"); + // The fixture's config leaves out items that export, which the census fails on, after + // writing itself: only on those, and on a field whose method of its name is refused, + // not on that method. + let stderr = String::from_utf8_lossy(&output.stderr); + assert!(!output.status.success(), "the census passed:\n{stderr}"); + let errors: Vec<&str> = stderr.lines().filter(|line| line.starts_with("error: rust2-ffi:")).collect(); assert!( - output.status.success(), - "the census failed:\n{}", - String::from_utf8_lossy(&output.stderr) + errors.iter().all(|error| error.ends_with(", which exports")), + "the census failed otherwise:\n{stderr}" + ); + assert!( + errors.contains(&"error: rust2-ffi: exclude `field@Retry::jitter` in the config leaves out `field@Retry::jitter`, which exports"), + "the census does not fail on `field@Retry::jitter`:\n{stderr}" + ); + assert!( + !errors.iter().any(|error| error.contains("exclude `Retry::jitter`")), + "the census fails on `Retry::jitter`:\n{stderr}" ); let text = std::fs::read_to_string(census.join("api-fixture.md")).unwrap(); for line in [ From 017ee209ba335dbf9693e2295d5b1f509929a71b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 22:25:04 -0800 Subject: [PATCH 11/17] fix(ffi): record an audited path under every exclude that names it Co-Authored-By: Claude Opus 5.5 --- ffi/src/collect.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ffi/src/collect.rs b/ffi/src/collect.rs index cbad52a2f..d68460aa7 100644 --- a/ffi/src/collect.rs +++ b/ffi/src/collect.rs @@ -535,7 +535,7 @@ impl<'tcx> Collector<'tcx> { } /// Whether the config excludes `path`, counting the exclusion, or else recording it under - /// the audited path that names it. A member of an instance is left out by its instance's + /// each audited path that names it. A member of an instance is left out by its instance's /// path or its type's, which leaves it out of each. fn exclude(&mut self, path: &[String]) -> bool { let report = &mut self.report; @@ -545,10 +545,10 @@ impl<'tcx> Collector<'tcx> { return true; } } + // Under every key that names it, so one census lists a broad exclude beside a narrow one. for (_, key) in config::keys(&path[1..]) { if let Some((_, named)) = report.audited.iter_mut().find(|(audited, _)| *audited == key) { named.push(path[1..].join("::")); - break; } } false From e1464ab2311e0bdbba33c23a9511abaa80eadb3c Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 13 Nov 2026 00:05:54 -0800 Subject: [PATCH 12/17] style(ffi): format the census test Co-Authored-By: Claude Opus 5.5 --- ffi/tests/fixtures.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ffi/tests/fixtures.rs b/ffi/tests/fixtures.rs index cf5312ba6..3bc8309d3 100644 --- a/ffi/tests/fixtures.rs +++ b/ffi/tests/fixtures.rs @@ -1295,13 +1295,18 @@ fn relative_target() { // not on that method. let stderr = String::from_utf8_lossy(&output.stderr); assert!(!output.status.success(), "the census passed:\n{stderr}"); - let errors: Vec<&str> = stderr.lines().filter(|line| line.starts_with("error: rust2-ffi:")).collect(); + let errors: Vec<&str> = stderr + .lines() + .filter(|line| line.starts_with("error: rust2-ffi:")) + .collect(); assert!( errors.iter().all(|error| error.ends_with(", which exports")), "the census failed otherwise:\n{stderr}" ); assert!( - errors.contains(&"error: rust2-ffi: exclude `field@Retry::jitter` in the config leaves out `field@Retry::jitter`, which exports"), + errors.contains( + &"error: rust2-ffi: exclude `field@Retry::jitter` in the config leaves out `field@Retry::jitter`, which exports" + ), "the census does not fail on `field@Retry::jitter`:\n{stderr}" ); assert!( From 970efca3b0ed4eca59fef8248a262b2c0adf58ad Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 13 Nov 2026 10:36:26 -0800 Subject: [PATCH 13/17] fix(ffi): census takes an exclude Swift's refusal requires Co-Authored-By: Claude Opus 5.5 --- ffi/fixtures/api/ffi.toml | 4 +++- ffi/fixtures/api/src/lib.rs | 5 +++++ ffi/src/driver.rs | 14 ++++++++++---- ffi/tests/fixtures.rs | 4 ++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/ffi/fixtures/api/ffi.toml b/ffi/fixtures/api/ffi.toml index d3ac9115a..c446752df 100644 --- a/ffi/fixtures/api/ffi.toml +++ b/ffi/fixtures/api/ffi.toml @@ -5,8 +5,10 @@ # `field@` leaves out a field alone where a method takes its path, as `Retry`'s and # `Slot`'s do, and `Retry::jitter` and `field@Retry::jitter` leave out a refused method # and its field. `Slot` has no such method, so its path alone names its field. A -# function instance is left out by its path, as `depth_past` at `polar::Point` is. +# function instance is left out by its path, as `depth_past` at `polar::Point` is. Swift +# refuses `among`, so the census takes its exclude. exclude = [ + "among", "Copied", "Layer", "Node::next", diff --git a/ffi/fixtures/api/src/lib.rs b/ffi/fixtures/api/src/lib.rs index dcf1ff394..99e4d5a2b 100644 --- a/ffi/fixtures/api/src/lib.rs +++ b/ffi/fixtures/api/src/lib.rs @@ -2752,3 +2752,8 @@ pub fn next_hop(hop: Option>) -> Option> { pub fn farther_hop(hops: Pair>) -> Box> { Box::new(hops.left.max(hops.right)) } + +/// Three optional borrowed counters, past what Swift takes, so the config leaves it out. +pub fn among(first: Option<&Counter>, second: Option<&Counter>, third: Option<&Counter>) -> u64 { + [first, second, third].into_iter().flatten().map(|c| c.value).sum() +} diff --git a/ffi/src/driver.rs b/ffi/src/driver.rs index b5b712c31..04fcf35d9 100644 --- a/ffi/src/driver.rs +++ b/ffi/src/driver.rs @@ -155,7 +155,9 @@ impl Callbacks for Export { let report = &collected.report; if let Output::Census(dir) = &self.output { let abi = Abi::new(&collected.api, &self.facade.lib); - let exporting = exporting(&collected.api, &report.audited); + // What Swift refuses needs its exclude, as the export says, so it is not exporting. + let swift: FxHashSet<_> = crate::swift::refusals(&abi).into_iter().map(|(span, _)| span).collect(); + let exporting = exporting(&collected.api, &report.audited, &swift); let text = census::render(&collected.api, report, &exporting, &abi.clashes, &|span| at(tcx, span)); // A census reports what a crate uses, but a missed instance is the exporter's bug. for refusal in &report.refusals { @@ -210,15 +212,19 @@ impl Callbacks for Export { /// Each exclude whose item would export without it, and that item's paths: what an /// exclude checked, from [`collect::Report::audited`], that the census's API holds by the -/// same path. -fn exporting(api: &Api, audited: &[(String, Vec)]) -> Vec<(String, Vec)> { +/// same path, except a function at one of the `refused` spans. +fn exporting( + api: &Api, + audited: &[(String, Vec)], + refused: &FxHashSet, +) -> Vec<(String, Vec)> { // Every path an exported item is checked by, from the facade's root, as the walk checks it. let mut paths = FxHashSet::default(); let mut add = |path: &[String]| { paths.insert(path[1..].join("::")); }; let methods = |methods: &[ir::Function], add: &mut dyn FnMut(&[String])| { - for f in methods { + for f in methods.iter().filter(|f| !refused.contains(&f.span)) { match f.access { // A field is checked by `field@` and, unless a method or constant takes its // name, by its path, which then names that method or constant instead. diff --git a/ffi/tests/fixtures.rs b/ffi/tests/fixtures.rs index ad34b1dcd..9f18597df 100644 --- a/ffi/tests/fixtures.rs +++ b/ffi/tests/fixtures.rs @@ -1322,6 +1322,10 @@ fn relative_target() { !errors.iter().any(|error| error.contains("exclude `Retry::jitter`")), "the census fails on `Retry::jitter`:\n{stderr}" ); + assert!( + !errors.iter().any(|error| error.contains("exclude `among`")), + "the census fails on `among`, which Swift refuses:\n{stderr}" + ); let text = std::fs::read_to_string(census.join("api-fixture.md")).unwrap(); for line in [ "- `Lease`: object no export returns", From 3b251623b1e4fb3be6d499ec69a110823e6cd4eb Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 13 Nov 2026 10:39:17 -0800 Subject: [PATCH 14/17] style(ffi): format Co-Authored-By: Claude Opus 5.5 --- ffi/src/driver.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ffi/src/driver.rs b/ffi/src/driver.rs index 04fcf35d9..c588a300a 100644 --- a/ffi/src/driver.rs +++ b/ffi/src/driver.rs @@ -213,11 +213,7 @@ impl Callbacks for Export { /// Each exclude whose item would export without it, and that item's paths: what an /// exclude checked, from [`collect::Report::audited`], that the census's API holds by the /// same path, except a function at one of the `refused` spans. -fn exporting( - api: &Api, - audited: &[(String, Vec)], - refused: &FxHashSet, -) -> Vec<(String, Vec)> { +fn exporting(api: &Api, audited: &[(String, Vec)], refused: &FxHashSet) -> Vec<(String, Vec)> { // Every path an exported item is checked by, from the facade's root, as the walk checks it. let mut paths = FxHashSet::default(); let mut add = |path: &[String]| { From f42d5665226ca22ab92d0fdf76df9f135902fe8c Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 13 Nov 2026 10:55:30 -0800 Subject: [PATCH 15/17] fix(ffi): match Swift refusals by shown path, not span Co-Authored-By: Claude Opus 5.5 --- ffi/src/driver.rs | 20 ++++++++++++++------ ffi/src/swift.rs | 8 ++++---- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/ffi/src/driver.rs b/ffi/src/driver.rs index c588a300a..17891233b 100644 --- a/ffi/src/driver.rs +++ b/ffi/src/driver.rs @@ -156,7 +156,10 @@ impl Callbacks for Export { if let Output::Census(dir) = &self.output { let abi = Abi::new(&collected.api, &self.facade.lib); // What Swift refuses needs its exclude, as the export says, so it is not exporting. - let swift: FxHashSet<_> = crate::swift::refusals(&abi).into_iter().map(|(span, _)| span).collect(); + let swift: FxHashSet<_> = crate::swift::refusals(&abi) + .into_iter() + .map(|(f, _)| f.shown.clone()) + .collect(); let exporting = exporting(&collected.api, &report.audited, &swift); let text = census::render(&collected.api, report, &exporting, &abi.clashes, &|span| at(tcx, span)); // A census reports what a crate uses, but a missed instance is the exporter's bug. @@ -212,15 +215,20 @@ impl Callbacks for Export { /// Each exclude whose item would export without it, and that item's paths: what an /// exclude checked, from [`collect::Report::audited`], that the census's API holds by the -/// same path, except a function at one of the `refused` spans. -fn exporting(api: &Api, audited: &[(String, Vec)], refused: &FxHashSet) -> Vec<(String, Vec)> { +/// same path, except a function `refused` names by its shown path, since a generic's +/// instances share a span but Swift may refuse only some. +fn exporting( + api: &Api, + audited: &[(String, Vec)], + refused: &FxHashSet, +) -> Vec<(String, Vec)> { // Every path an exported item is checked by, from the facade's root, as the walk checks it. let mut paths = FxHashSet::default(); let mut add = |path: &[String]| { paths.insert(path[1..].join("::")); }; let methods = |methods: &[ir::Function], add: &mut dyn FnMut(&[String])| { - for f in methods.iter().filter(|f| !refused.contains(&f.span)) { + for f in methods.iter().filter(|f| !refused.contains(&f.shown)) { match f.access { // A field is checked by `field@` and, unless a method or constant takes its // name, by its path, which then names that method or constant instead. @@ -393,9 +401,9 @@ impl Export { .with_span_note(*first_span, format!("{first} is here")) .emit(); } - for (span, why) in crate::swift::refusals(&abi) { + for (function, why) in crate::swift::refusals(&abi) { tcx.dcx().span_err( - span, + function.span, format!("rust2-ffi: {why}; exclude it in the config to leave it out"), ); } diff --git a/ffi/src/swift.rs b/ffi/src/swift.rs index 2e0b9fe3a..1bfd0b6eb 100644 --- a/ffi/src/swift.rs +++ b/ffi/src/swift.rs @@ -1782,11 +1782,11 @@ fn thrown_value(thrown: &Thrown, lifted: &str) -> String { /// overloads. const MAX_OPTIONAL: usize = 2; -/// Each function or method Swift cannot export, with its span and why, which the driver +/// Each function or method Swift cannot export, and why, which the driver /// refuses before any language is generated: one taking more optional borrowed structs /// than [`MAX_OPTIONAL`], or returning an error that holds one, which `Swift.Error` /// requires be copyable. -pub fn refusals(abi: &Abi<'_>) -> Vec<(Span, String)> { +pub fn refusals<'a>(abi: &Abi<'a>) -> Vec<(&'a Function, String)> { let structs = structs(abi); let api = abi.api; let methods = (api.records.iter().flat_map(|r| &r.methods)) @@ -1800,7 +1800,7 @@ pub fn refusals(abi: &Abi<'_>) -> Vec<(Span, String)> { .count(); if optional > MAX_OPTIONAL { refusals.push(( - function.span, + function, format!( "{what}: {optional} optional borrowed objects, past the {MAX_OPTIONAL} Swift takes, which overloads each with and without it since its optional holds an object only by consuming it" ), @@ -1808,7 +1808,7 @@ pub fn refusals(abi: &Abi<'_>) -> Vec<(Span, String)> { } if function.err.as_ref().is_some_and(|err| unique(&structs, err)) { refusals.push(( - function.span, + function, format!("{what}: error holding an object Swift cannot copy, as `Swift.Error` requires"), )); } From 999f51cb4208aad7eb44efb034dcc543b4458243 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 13 Nov 2026 11:17:42 -0800 Subject: [PATCH 16/17] fix(ffi): drop the unused Span import Co-Authored-By: Claude Opus 5.5 --- ffi/src/swift.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/ffi/src/swift.rs b/ffi/src/swift.rs index 1bfd0b6eb..8888dc92d 100644 --- a/ffi/src/swift.rs +++ b/ffi/src/swift.rs @@ -23,7 +23,6 @@ use std::collections::{BTreeMap, BTreeSet, HashMap}; use std::fmt::Write; -use rustc_span::Span; use crate::abi::{self, Abi, Ty, pascal}; use crate::ir::{Access, Closure, Function, Int, Literal, Mutability, On, Param, Receiver, Type}; From 72b2d331efc6680efb4586ffafd6233ef8aeb13e Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 13 Nov 2026 11:27:52 -0800 Subject: [PATCH 17/17] style(ffi): format Co-Authored-By: Claude Opus 5.5 --- ffi/src/swift.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/ffi/src/swift.rs b/ffi/src/swift.rs index 8888dc92d..0ae2907a5 100644 --- a/ffi/src/swift.rs +++ b/ffi/src/swift.rs @@ -23,7 +23,6 @@ use std::collections::{BTreeMap, BTreeSet, HashMap}; use std::fmt::Write; - use crate::abi::{self, Abi, Ty, pascal}; use crate::ir::{Access, Closure, Function, Int, Literal, Mutability, On, Param, Receiver, Type};