From 106c91be4d489e63054b4a4cf01041e5542210b6 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Wed, 28 Oct 2026 16:54:57 -0700 Subject: [PATCH 1/2] chore(quest): claim quest/m1/ffi-export/slices.md Quest-Claim: 3b4564c9755de085 From 77fce05e4f47e8f32bf0189c17fa1f86754cad43 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Wed, 28 Oct 2026 17:07:31 -0700 Subject: [PATCH 2/2] feat(ffi): export &[T] of any type, and SocketAddrV4 and SocketAddrV6 A slice crosses as a `Vec` does, as `_vec_`: passed in, Rust lifts the array into a `Vec` that coerces to the slice; returned, `ToOwned` clones it into one, so its elements need `Clone`. A slice of references or handles stays refused as a parameter, as a `Vec` of them is. `SocketAddrV4` and `SocketAddrV6` share `_socket_addr`: one of the other family aborts from C and throws from Kotlin. moq's ALPNS, the `ALL` constants, `Pattern::segments`, `connect::Addr`, `Hops::as_slice`, `Muxer::fragment`, and `listen::Config::preferred_v4`/`_v6` export. Co-Authored-By: Claude Opus 5.5 --- ffi/MIGRATE.md | 3 ++ ffi/README.md | 13 ++++--- ffi/fixtures/api/examples/transcript.rs | 10 +++++ ffi/fixtures/api/src/lib.rs | 50 +++++++++++++++++++++++++ ffi/fixtures/reject/expected.txt | 3 ++ ffi/fixtures/reject/src/lib.rs | 15 ++++++++ ffi/moq/ffi.toml | 12 +----- ffi/moq/moq.c | 10 +++++ ffi/moq/moq.cpp | 6 +++ ffi/moq/moq.kt | 4 ++ ffi/runtime/rt.kt | 12 ++++++ ffi/runtime/rt.rs | 16 ++++++++ ffi/src/abi.rs | 4 +- ffi/src/collect.rs | 39 ++++++++++++++++--- ffi/src/cpp.rs | 6 +-- ffi/src/glue.rs | 16 +++++--- ffi/src/ir.rs | 16 ++++++-- ffi/src/kotlin.rs | 10 +++-- ffi/tests/api.c | 43 +++++++++++++++++++++ ffi/tests/api.cpp | 34 +++++++++++++++++ ffi/tests/api.kt | 15 ++++++++ ffi/tests/fixtures.rs | 2 + quest/m1/ffi-export/README.md | 1 - quest/m1/ffi-export/slices.md | 27 ------------- 24 files changed, 299 insertions(+), 68 deletions(-) delete mode 100644 quest/m1/ffi-export/slices.md diff --git a/ffi/MIGRATE.md b/ffi/MIGRATE.md index 469623d97..a0b8e0069 100644 --- a/ffi/MIGRATE.md +++ b/ffi/MIGRATE.md @@ -2,6 +2,9 @@ ## Unreleased +- `&[T]` of any type and `SocketAddrV4` and `SocketAddrV6` map, so a struct or enum whose + fields were refused only for the socket addresses is a value now, not an object, and + an item that newly exports can clash with another's C name, which takes a `rename`. - `Vec`, `PathBuf`, `SocketAddr`, and `url::Url` map, so a struct or enum whose fields were refused only for them is a value now, not an object: moq-tokio's `listen::Bind` is the C enum `moq_listen_bind`, freed with `moq_listen_bind_free(&b)`, diff --git a/ffi/README.md b/ffi/README.md index bff644dd9..95d96f840 100644 --- a/ffi/README.md +++ b/ffi/README.md @@ -74,9 +74,9 @@ export's, and adds nothing; another crate's type is refused. | `&str`, `String`, `&[u8]`, `Vec`, `bytes::Bytes` | `_buf`: a view passed in, an owned buffer returned | | `&Path`, `PathBuf` | `_buf` of the path's bytes as the OS holds them on Unix, which need not be UTF-8, else UTF-8 | | `Duration` | `_duration` | -| `SocketAddr` | `_socket_addr`: its IP's bytes, port, and whether it is IPv6 | +| `SocketAddr`, `SocketAddrV4`, `SocketAddrV6` | `_socket_addr`: its IP's bytes, port, and whether it is IPv6; one of the other family passed to `V4` or `V6` aborts | | `url::Url` | an object `_url`, made by `_url_parse`, which fails with the parse error's message, and printed by `_to_string` | -| `Vec` of any other `T` | `_vec_`: an array of `T`'s C values, viewed passed in and owned returned; `Vec<&T>` only returned | +| `Vec` and `&[T]` of any other `T` | `_vec_`: an array of `T`'s C values, viewed passed in and owned returned, a slice as a clone; of references only returned | | `Waker`, taken by value | `_waker`, as a future's poll takes it | | `Range`, `Bound` of an integer | `_range_`, `_bound_`: a `_bound` kind and a value | | `impl RangeBounds` of an integer | `_bounds_`: its start and end bounds | @@ -232,10 +232,11 @@ kotlinx-coroutines. Each value crosses JNI as a scalar, a handle as a `Long`, by - **Bytes** are `ByteArray`, strings `String`, `Option` `T?`, a tuple `Pair`, `Triple`, or past them a generated `Tuple`, `Duration` `kotlin.time.Duration`, and an `Err` a thrown `Exception` holding it, whose message is its `Display`. -- A **path** is a `String`: one Rust returns that is not UTF-8 throws. A `SocketAddr` is a - `java.net.InetSocketAddress`, which must be resolved; one Rust returns with an IPv6 flow - label, which Java does not keep, throws. A `Vec` is a `List`, and passing it by - value closes each object in it once the call returns. +- A **path** is a `String`: one Rust returns that is not UTF-8 throws. A `SocketAddr`, + `SocketAddrV4`, or `SocketAddrV6` is a `java.net.InetSocketAddress`, which must be + resolved and, for `V4` or `V6`, of that family; one Rust returns with an IPv6 flow + label, which Java does not keep, throws. A `Vec` or `&[T]` is a `List`, and passing + a `Vec` by value closes each object in it once the call returns. - **Traits** are interfaces; once Rust drops an implementation, it is closed if `AutoCloseable`. - **Closures** lent for a call are function types, which Rust calls only during the call, diff --git a/ffi/fixtures/api/examples/transcript.rs b/ffi/fixtures/api/examples/transcript.rs index bc7b4af43..5fe4f4b08 100644 --- a/ffi/fixtures/api/examples/transcript.rs +++ b/ffi/fixtures/api/examples/transcript.rs @@ -370,4 +370,14 @@ fn main() { println!("sums {:?}", api_lib::sums(vec![vec![1, 2], Vec::new(), vec![3]])); let site = api_lib::Site::new(base); println!("site {} {}", site.home, site.home); + + // Slices, passed in and returned as clones, and the socket address of each family. + println!("shapes {:?} greetings {:?}", api_lib::Shape::ALL, api_lib::GREETINGS); + let trail = api_lib::Trail::new( + &[api_lib::Point { x: 1, y: 2 }, api_lib::Point { x: 3, y: 4 }], + &["a".to_string(), "b".to_string()], + ); + println!("trail {:?} {:?}", trail.points(), trail.labels()); + let (v4, v6) = api_lib::nexts("127.0.0.1:8080".parse().unwrap(), "[::1%3]:443".parse().unwrap()); + println!("nexts {} {} {} {}", v4.ip(), v4.port(), v6.port(), v6.scope_id()); } diff --git a/ffi/fixtures/api/src/lib.rs b/ffi/fixtures/api/src/lib.rs index 73d2aaebe..fecfcedc5 100644 --- a/ffi/fixtures/api/src/lib.rs +++ b/ffi/fixtures/api/src/lib.rs @@ -981,3 +981,53 @@ impl Site { Self { home } } } + +impl Shape { + /// Every shape, as a constant slice. + pub const ALL: &'static [Shape] = &[Shape::Circle, Shape::Square]; +} + +/// Greetings, as a constant slice of references, each returned as a clone. +pub const GREETINGS: &[&str] = &["hi", "hello"]; + +/// A trail through points, each labeled: slices passed in and lent back out. +pub struct Trail { + points: Vec, + labels: Vec