Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
cfe92b9
chore(quest): claim quest/m1/ffi-proofs/shapes.md
kixelated Nov 19, 2026
8387380
WIP: shapes' new positions, C driver, census takes Swift's refusals
kixelated Nov 19, 2026
b86c2b7
WIP: C++ and Kotlin drivers
kixelated Nov 19, 2026
9945c78
WIP: Python and Swift drivers; Swift's optional error describes witho…
kixelated Nov 19, 2026
f3187ac
WIP: Go driver
kixelated Nov 19, 2026
ff4b0f8
WIP: Dart driver
kixelated Nov 19, 2026
d3a2210
WIP: web driver, nightly fixes, KNOWN NaN entries, Dart error dedupe
kixelated Nov 19, 2026
53805b0
WIP: Dart driver per shape, README, shapes quest complete
kixelated Nov 19, 2026
17003a6
Merge remote-tracking branch 'origin/main' into quest/m1/ffi-proofs/s…
kixelated Nov 19, 2026
a9a6092
fix(ffi): lock each exception by its native type; KNOWN skips only ca…
kixelated Nov 19, 2026
684dff5
fix(ffi): keep a legacy exception key while a class of it bears its name
kixelated Nov 19, 2026
2b933a6
fix(ffi): answer review: respelled exception keys, Swift refusal by c…
kixelated Nov 19, 2026
73f6fae
style(ffi): format
kixelated Nov 19, 2026
dbffe9e
quest: record the maintainer's follow-up answers
kixelated Nov 19, 2026
0ee5a14
Merge origin/main into quest/m1/ffi-proofs/shapes
kixelated Nov 19, 2026
0153336
fix: keep the merge's untouched files as both parents format them
kixelated Nov 19, 2026
7cfd771
Merge origin/main into quest/m1/ffi-proofs/shapes
kixelated Nov 20, 2026
67806ad
fix: keep the merge's untouched files as both parents format them
kixelated Nov 20, 2026
e3bb8b7
Merge remote-tracking branch 'origin/main' into quest/m1/ffi-proofs/s…
kixelated Nov 20, 2026
fd010b2
ffi: prove each sink callback runs, type-check the web place, narrow …
kixelated Nov 20, 2026
dbcefc8
style: format
kixelated Nov 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,6 @@ jobs:
- name: Export
run: nix develop --command just ffi moq

# Every sampled type shape round-tripped in every language; the gate runs a subset.
- name: Shapes
run: nix develop --command just ffi shapes

# Longer random protocol scripts through the C ABI and each binding, against the
# model of what each step returns; the gate runs fewer.
- name: Protocol
Expand All @@ -216,6 +212,25 @@ jobs:
- name: Clang
run: nix develop .#clang --command bash -c 'export CC=gcc; just ffi test cpp && just ffi moq-cpp'

# Every sampled type shape round-tripped in every language: the fixed set, then shapes
# drawn from the day's seed, which a failure names to reproduce it. The gate runs a
# subset. A job of its own, since it takes as long as the export's.
ffi-shapes:
name: Shapes in every language
runs-on: ubuntu-24.04-arm
timeout-minutes: 60

steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- uses: ./.github/actions/nix

- name: Shapes
run: nix develop --command just ffi shapes

# The pinned corpus of popular crates, each censused, exported through a facade, and
# bound in every language: a panic, an error, or a binding that does not build fails it.
# Their build scripts run here, on a runner of its own holding no secret.
Expand Down Expand Up @@ -489,7 +504,7 @@ jobs:
# schedule, which runs main, gets the write token: a dispatch can run any branch.
report:
name: Report
needs: [bindings, gate, ts, bench, ffi-api, ffi, ffi-corpus, ffi-web, ffi-sanitize, ffi-cpp, ffi-android, ffi-bench, census]
needs: [bindings, gate, ts, bench, ffi-api, ffi, ffi-shapes, ffi-corpus, ffi-web, ffi-sanitize, ffi-cpp, ffi-android, ffi-bench, census]
if: ${{ !cancelled() && github.event_name == 'schedule' }}
runs-on: ubuntu-24.04
timeout-minutes: 5
Expand Down
31 changes: 20 additions & 11 deletions ffi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ item, method, trait impl, or a variant of a `#[non_exhaustive]` enum. A constant
an item's docs may change. The check runs once, on the API every language is generated from;
it compares C's names and the C++, Kotlin, Python, Swift, Go, and Dart generators' own
public names. A clash that renames a kept class, function, or member reports its language
and old and new names at the item's span. Staged `--api` files have no binding names; a
and old and new names at the item's span. An error type's exception class is known by its
error type and the type the language holds it as, since Kotlin's `UShortArray` and
`List<UShort>` may share one error type: one added beside another adds a class, and a
native type respelled or gone breaks nothing while a class still bears its old name. Staged `--api` files have no binding names; a
baseline must be a complete export. An older baseline without name tables still has its
structure checked, reporting each break before the error that it lacks names, so its
re-export with this version accepts no break that check would have caught. A binding
Expand Down Expand Up @@ -1348,7 +1351,8 @@ runtime package and each crate's include [`runtime/rt.go`](runtime/rt.go) and
## Census

`--census dir` exports nothing. It writes `<package>.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
lists each refused item at its span, a binding's own refusals such as Swift's included,
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.
That list is checked by collecting again with it: it holds what Swift alone refuses, and
not an instance only refused items named, which nothing names once they are left out.
Expand Down Expand Up @@ -1566,15 +1570,20 @@ binding, which builds for each, and staged with `--api` and `--with`; a build fo
not exported fails, and items that differ between the two are refused, naming both.
The shape tests (`tests/fixtures/shapes.rs`) sample value types from the IR's `Type`, each
leaf alone and in each wrapper, then nested to depth 3 from a fixed seed, and emit a crate
of `make_N(seed)`, `echo_N(v)`, and `digest_N(&v)` per shape, with the shape in a closure's
parameter and return and in a future besides. Its census decides what exports, so a shape
refused by design is left out rather than failed. Each language's driver is a generated
flat list of `digest(echo(make(seed)))` calls whose printed digests must match the crate's
own, run natively. The gate runs a subset; `just ffi shapes` runs every sampled shape, as
the nightly does. `KNOWN` lists what a binding still gets wrong, each with the quest that
fixes it; the driver skips those shapes, so the fix deletes its entry, and the nightly fails
on an entry that matches no exported shape. A new IR `Type` variant fails `ir_covered`
until the sampler covers it.
of `make_N(seed)`, `echo_N(v)`, and `digest_N(&v)` per shape, with the shape in each
position a binding maps apart: a closure's parameter and return, a future, a `Result`'s
value and error, a `&mut` written back, beside other parameters, an `Option<&T>`, an
object's methods, and a trait a caller implements. A digest hashes floats by their bits,
so a NaN's payload counts, and the sampler draws signaling and quiet NaNs. Its census
decides what exports, so a shape refused by design is left out rather than failed. Each
language's driver, the web's on Node included, is a generated list of these calls whose
printed digests must match the crate's own, run natively, or as wasm under Node's WASI
for the web, where `usize` is 32 bits. The gate runs a subset; `just ffi shapes` runs
every sampled shape and, as the nightly does, more drawn from the day's seed, which it
prints and `RUST2_SHAPES_SEED` replays. `KNOWN` lists what a binding still gets wrong,
each with the quest that fixes it; the driver skips those calls, so the fix deletes its
entry, and the nightly fails on an entry that matches no call of the fixed set. A new IR
`Type` variant fails `ir_covered` until the sampler covers it.
The corpus (`tests/fixtures/corpus.rs`) exports stock crates as a consumer would: each
crate of `corpus/crates.txt`, the top crates on crates.io by downloads that are libraries
building as they are, pinned by `corpus/Cargo.lock`, through a facade of its own, `pub use
Expand Down
5 changes: 4 additions & 1 deletion ffi/fixtures/api/ffi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# converts into them, and
# `field@` leaves out a field alone where a method takes its path, as `Retry`'s and
# `Slot<u8>`'s do, and `Retry::jitter` and `field@Retry::jitter` leave out a refused method
# and its field. `Slot<u32>` has no such method, so its path alone names its field. A
# and its field, as `Retry::spread` and `field@Retry::spread` do a method Swift alone
# refuses and its field. `Slot<u32>` 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, and a
# method a `Deref` forwards by the object's, as `Pad<u16>::lines` is. A forwarded field
# sharing its path with a method is `field@`, as `Pad<u16>`'s `title` is, so `Marker::x`
Expand All @@ -25,9 +26,11 @@ exclude = [
"Scoped",
"Slot<u32>::value",
"Retry::jitter",
"Retry::spread",
"field@Pad<u16>::title",
"field@Retry::delay",
"field@Retry::jitter",
"field@Retry::spread",
"field@Slot<u8>::value",
"Stack::depth_past<api::polar::Point>",
"Stored",
Expand Down
9 changes: 9 additions & 0 deletions ffi/fixtures/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2843,6 +2843,9 @@ pub struct Retry {
/// 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,
/// Its field exports, but Swift refuses the method of its name, so the config excludes
/// both, and the census lists only `field@Retry::spread` as excluding what exports.
pub spread: u64,
}

impl Retry {
Expand All @@ -2851,6 +2854,7 @@ impl Retry {
limit,
delay: None,
jitter: 0,
spread: 0,
}
}

Expand All @@ -2866,6 +2870,11 @@ impl Retry {
self.limit = Some(limit);
}

/// The spread plus three optional borrowed counters, past what Swift takes.
pub fn spread(&self, first: Option<&Counter>, second: Option<&Counter>, third: Option<&Counter>) -> u64 {
self.spread + among(first, second, third)
}

/// The jitter capped by `cap`, if any: a nested `Option`, which the export refuses.
pub fn jitter(&self, cap: Option<Box<Option<u32>>>) -> u32 {
cap.and_then(|cap| *cap).map_or(self.jitter, |cap| self.jitter.min(cap))
Expand Down
4 changes: 2 additions & 2 deletions ffi/fixtures/lock/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ fixtures/lock/src/lib.rs:202:1: rust2-ffi: the API breaks the baseline at struct
fixtures/lock/src/lib.rs:21:2: rust2-ffi: the API breaks the baseline at const `lock::limits_max::RATE`: its C name `LOCK_LIMITS_MAX_RATE` is now `LOCK_LIMITS_MAX_RATE_`, and `LOCK_LIMITS_MAX_RATE` names const `lock::limits::MAX_RATE`
fixtures/lock/src/lib.rs:231:1: rust2-ffi: the API breaks the baseline at struct `lock::Beat`: how it is held: a word compared by its bits, and now bytes compared by Rust
fixtures/lock/src/lib.rs:30:1: rust2-ffi: the API breaks the baseline at fn `lock::removed`: it is removed
fixtures/lock/src/lib.rs:356:1: rust2-ffi: the API breaks the baseline at enum `lock::Speed`: variant `Fast` is removed; variant `Quick` is added to an exhaustive enum
fixtures/lock/src/lib.rs:36:1: rust2-ffi: the API breaks the baseline at fn `lock::portable`: it is no longer on wasm32-unknown-unknown
fixtures/lock/src/lib.rs:379:1: rust2-ffi: the API breaks the baseline at type `lock::Gauge`: its handle is now checked at run time, so each call taking it gains a status, and throws in Swift
fixtures/lock/src/lib.rs:373:1: rust2-ffi: the API breaks the baseline at enum `lock::Speed`: variant `Fast` is removed; variant `Quick` is added to an exhaustive enum
fixtures/lock/src/lib.rs:396:1: rust2-ffi: the API breaks the baseline at type `lock::Gauge`: its handle is now checked at run time, so each call taking it gains a status, and throws in Swift
fixtures/lock/src/lib.rs:46:1: rust2-ffi: the API breaks the baseline at fn `lock::scale`: its parameter `x`'s type; its return type
fixtures/lock/src/lib.rs:66:2: rust2-ffi: the API breaks the baseline at fn `lock::Meter::add`: its parameter `n`'s type
fixtures/lock/src/lib.rs:7:2: rust2-ffi: the API breaks the baseline at fn `lock::audio_encoder::finish`: its C name `lock_audio_encoder_finish` is now `lock_audio_encoder_finish_`, and `lock_audio_encoder_finish` names fn `lock::audio::encoder_finish`
Expand Down
17 changes: 17 additions & 0 deletions ffi/fixtures/lock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,23 @@ pub fn failing_borrowed() -> Result<u32, &'static str> {
Err("failure")
}

/// An error whose key, `vec_u16`, `added` gives a `BTreeSet<u16>` too, which Kotlin,
/// Python, and Dart hold as another type and so throw as an exception of its own: an
/// addition. A `Vec<NonZero<u16>>` shares its C type, which Dart holds apart.
pub fn samples() -> Result<u32, Vec<u16>> {
Err(vec![1])
}

#[cfg(feature = "added")]
pub fn samples_set() -> Result<u32, std::collections::BTreeSet<u16>> {
Err([1].into())
}

#[cfg(feature = "added")]
pub fn samples_nonzero() -> Result<u32, Vec<std::num::NonZero<u16>>> {
Err(vec![std::num::NonZero::<u16>::MIN])
}

/// Error wrappers and variants occupy their own language namespaces.
#[cfg(not(feature = "closures"))]
pub fn failing() -> Result<u32, String> {
Expand Down
14 changes: 10 additions & 4 deletions ffi/src/dart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2713,18 +2713,24 @@ impl<'a> Gen<'a> {
Thrown::Itself
}
_ => {
// One exception for each C type and Dart type: a `Vec<NonZero<u16>>` shares
// `Vec<u16>`'s C type, but Dart holds it as a `List<int>`, not a `Uint16List`.
let key = self.abi.key(err);
let seen = self.thrown.iter().find(|(_, seen)| self.abi.key(seen) == key);
let dt = self.dt(err);
let thrown: Vec<(String, Type)> = (self.thrown.iter())
.filter(|(_, seen)| self.abi.key(seen) == key)
.map(|(name, seen)| (name.clone(), seen.clone()))
.collect();
let seen = thrown.into_iter().find(|(_, seen)| self.dt(seen) == dt);
let name = match seen {
Some((name, _)) => name.clone(),
Some((name, _)) => name,
None => {
let dt = self.dt(err);
let name = self.claim(&format!("{}Exception", pascal(&key)), format!("the error type `{dt}`"));
self.thrown.insert(name.clone(), err.clone());
name
}
};
self.locked.insert(crate::lock::error_key(self.abi, err), name.clone());
crate::lock::exception(&mut self.locked, self.abi, err, &dt, &name);
Thrown::Wrapped(name)
}
}
Expand Down
Loading