From 6517a8ef0829f2f301d653e66688ddf97de229db Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 29 Oct 2026 19:44:18 -0700 Subject: [PATCH 1/9] chore(quest): claim quest/m3/ffi-from-chains.md Quest-Claim: e28c09b1fd47aeaf From 8ca52b0f2d17da7d8940e90603229a154def297a Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 29 Oct 2026 20:03:02 -0700 Subject: [PATCH 2/9] feat(ffi): take what converts into an Into target through a chain of From implementations An `impl Into` whose `X` does not map follows each `Into` bound of a `From` source parameter whose `Y` does not map either, through any number of levels, carrying whether a level must outlive the call and visiting each target once so a cycle ends. Two chain sources that C passes as one buffer but that hold different values, such as `String` and `Vec`, are refused as an ambiguous conversion. Co-Authored-By: Claude Opus 5.5 --- ffi/README.md | 2 +- ffi/fixtures/api/examples/transcript.rs | 12 ++- ffi/fixtures/api/ffi.toml | 8 +- ffi/fixtures/api/src/lib.rs | 58 +++++++++++++ ffi/fixtures/reject/expected.txt | 44 +++++----- ffi/fixtures/reject/ffi.toml | 2 +- ffi/fixtures/reject/src/lib.rs | 30 +++++++ ffi/src/collect.rs | 108 +++++++++++++++++------- ffi/src/ir.rs | 12 +++ ffi/tests/api.c | 3 + ffi/tests/api.cpp | 3 + ffi/tests/api.kt | 3 + quest/m3/README.md | 1 - quest/m3/ffi-from-chains.md | 23 ----- 14 files changed, 227 insertions(+), 82 deletions(-) delete mode 100644 quest/m3/ffi-from-chains.md diff --git a/ffi/README.md b/ffi/README.md index eedc1e8f2..5f2582196 100644 --- a/ffi/README.md +++ b/ffi/README.md @@ -85,7 +85,7 @@ export's, and adds nothing; another crate's type is refused. | `Option` | a null handle or buffer, or `_option_` | | a `pub const` | a `#define` if a `bool` or integer, else a function returning it | | `impl Into`, `impl AsRef`, or a bound implying one, as a supertrait does | `X`, or `&X` and then `String` or `Vec` where `X` is `str` or `[T]` | -| `impl Into`, where `X` does not map | what a `From` implementation into `X` takes: a source parameter by its bounds as above, so `impl> From for Timed` takes `Bytes`, and any other source as it is, so `impl<'a, V> From<&'a V> for Timed<&'a V>` takes `&V` | +| `impl Into`, where `X` does not map | what a `From` implementation into `X` takes: a source parameter by its bounds as above, so `impl> From for Timed` takes `Bytes`, and by each `Into` whose `Y` does not map, what converts into `Y` in turn, each `Y` once; any other source as it is, so `impl<'a, V> From<&'a V> for Timed<&'a V>` takes `&V`. Two sources C passes as one buffer, such as `String` and `Vec`, are refused, unless they are forms of one value, as `&str` and `String` are | | `impl IntoIterator`, where `X` is no type parameter | `Vec` | | another type parameter | `serde_json::Value` for a serde `Serialize` or `Deserialize` bound, else the first of `String`, `Bytes`, and `Vec` meeting its bounds, or a foreign implementation of its one exported trait; else an instance of the function at each type the exports implement a trait bounding it for, as `&X` where that meets its bounds too and no bound, its own or one a supertrait implies, makes it outlive the call, so C keeps its handle, and, as an argument of a generic type, at each argument of an instance that meets its bounds and makes each generic type the signature names an instance | diff --git a/ffi/fixtures/api/examples/transcript.rs b/ffi/fixtures/api/examples/transcript.rs index a5b592694..fbd5ce34f 100644 --- a/ffi/fixtures/api/examples/transcript.rs +++ b/ffi/fixtures/api/examples/transcript.rs @@ -9,8 +9,8 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::task::{Context, Poll, Wake, Waker}; use api_lib::{ - Channel, Counter, Event, LIMIT, Log, Logger, Message, Name, Node, Pair, Point, Registry, Shape, Size, Stack, Stamp, - Tally, Window, + Channel, Counter, Event, LIMIT, Label, Log, Logger, Message, Name, Node, Pair, Point, Registry, Shape, Size, Stack, + Stamp, Tally, Window, }; use bytes::Bytes; @@ -154,6 +154,14 @@ fn main() { println!("len {}", api_lib::len(b"abc")); println!("hex {}", api_lib::hex(Bytes::from_static(b"\xff\x00a"))); println!("timed hex {}", api_lib::timed_hex(Bytes::from_static(b"\xff\x00a"))); + println!("sample hex {}", api_lib::sample_hex(&b"\xff\x00a"[..])); + println!("queued hex {}", api_lib::queued_hex(b"\xff\x00a".to_vec())); + let tick = Label { + name: "tick".to_string(), + at: None, + ttl: None, + }; + println!("tick {}", api_lib::tick_name(tick)); for event in [Event::Moved(p), Event::Named { name: "n".to_string() }, Event::Done] { println!("{}", api_lib::describe(&event)); } diff --git a/ffi/fixtures/api/ffi.toml b/ffi/fixtures/api/ffi.toml index d1d95c012..63cdfc251 100644 --- a/ffi/fixtures/api/ffi.toml +++ b/ffi/fixtures/api/ffi.toml @@ -2,8 +2,8 @@ package = "api-fixture" prefix = "api" # The list's tail is not `Clone`, so its getter has no copy to return, one instance leaves # out a method the others keep, `Seed` is generic, so no callback implements it, `Payload` -# and `Kept` consume themselves, which no callback can, `Timed` has no instance that -# exports, and +# and `Kept` consume themselves, which no callback can, `Timed`, `Sample`, `Queued`, +# `Tick`, and `Tock` 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 # function instance is left out by its path, as `depth_past` at `polar::Point` is. @@ -12,12 +12,16 @@ exclude = [ "Node::next", "Pair::swap", "Payload", + "Queued", + "Sample", "Seed", "Slot::value", "field@Retry::delay", "field@Slot::value", "Stack::depth_past", + "Tick", "Timed", + "Tock", ] # The field `Retry::limit`, whose name its method takes. diff --git a/ffi/fixtures/api/src/lib.rs b/ffi/fixtures/api/src/lib.rs index b42f8592f..2b0cfa0ef 100644 --- a/ffi/fixtures/api/src/lib.rs +++ b/ffi/fixtures/api/src/lib.rs @@ -704,6 +704,64 @@ pub fn timed_text<'a, T: serde::Serialize + 'a>(value: impl Into>) serde_json::to_string(value.into().value).expect("a JSON document serializes") } +/// A timed payload on a track, which what converts into one converts into. +pub struct Sample(Timed); + +impl>> From for Sample { + fn from(value: T) -> Self { + Self(value.into()) + } +} + +/// A sample's bytes in hex, which need not be UTF-8, two conversions from what C lends. +pub fn sample_hex(sample: impl Into) -> String { + hex(sample.into().0.value) +} + +/// A sample queued past the conversion, so what converts into it is owned. +pub struct Queued(Sample); + +impl + 'static> From for Queued { + fn from(value: T) -> Self { + Self(value.into()) + } +} + +/// A queued sample's bytes in hex, which need not be UTF-8, three conversions from owned bytes. +pub fn queued_hex(queued: impl Into) -> String { + hex(queued.into().0.0.value) +} + +/// A name from a label, or from what converts into a `Tock`, which converts from what +/// converts into a `Tick`: a cycle, which only the label leaves. +pub struct Tick(String); + +impl From