Skip to content

feat(ffi): export &[T] of any type, and SocketAddrV4 and SocketAddrV6 - #205

Merged
kixelated merged 4 commits into
mainfrom
quest/m1/ffi-export/slices
Oct 29, 2026
Merged

kixelated merged 4 commits into
mainfrom
quest/m1/ffi-export/slices

Conversation

@kixelated

@kixelated kixelated commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Claims quest/m1/ffi-export/slices.md and finishes it.

Problem

After #190, the census still refused &[T] of any type but u8 (12 refusals at the pinned moq), and SocketAddrV4 and SocketAddrV6 (moq-tokio's listen::Config::preferred_v4 and preferred_v6).

Approach

  • &[T] maps to the IR form a &Vec<T> already has, Ref(List(T)), and crosses as the same <prefix>_vec_<T>. Passed in, the glue lifts C's array into a Vec, which coerces to the slice at the call. Returned, the glue's borrowed-return lowering now calls ToOwned::to_owned instead of Clone::clone. That is the same for every sized Clone type, and turns a &[T] into a Vec<T> of clones, so a returned slice needs its elements Clone. The generators need no change: C, C++, and Kotlin already handle a borrowed Vec.
  • As a parameter, a slice of references is refused (slice of references), as a Vec of them is, and so is a slice of handles (reference to a handle inside a value), since lifting would move each value out of its caller's handle.
  • SocketAddrV4 and SocketAddrV6: Type::SocketAddr now carries a family (Any, V4, V6) and all three share <prefix>_socket_addr. From C, passing an address of the other family aborts, as an IPv4 address with IPv6 bytes already does. Kotlin throws IllegalArgumentException before the call, since a Kotlin caller can easily pass the wrong InetAddress.

Choices made without asking: reusing Ref(List) rather than adding a [T] IR type, which I tried first and which would have needed an arm in every generator for no difference in what crosses; V4 and V6 aborting from C on the wrong family rather than converting an IPv4-mapped IPv6 address.

Proof

  • The api fixture's transcript from C, C++ at 17/20/23, and Kotlin covers:
    • Shape::ALL, a constant &[Shape] of a plain enum;
    • GREETINGS, a constant &[&str];
    • a &[Point] and a &[String] passed in;
    • a returned &[Point], and a returned &[Label] whose clones own memory;
    • SocketAddrV4 and SocketAddrV6 in and out, with the scope ID kept.
  • New failure cases: a C abort and a Kotlin throw for the wrong family.
  • Three new reject cases: a slice of references, a slice of handles, and a returned slice of a non-Clone type.
  • moq/moq.c, moq.cpp, and moq.kt against moq read ALPNS, and set listen.preferred_v4 or preferred_v6 and read it back.

Census

moq's exports (exported / refused), before and after, against main at 75a5cad:

Before After
Types 461 / 118 461 / 118
Functions 36 / 20 37 / 20
Methods and fields 2259 / 183 2269 / 176
Constants 15 / 4 15 / 0

All four refused constants now export (as getters). moq/ffi.toml drops the 11 excludes this unblocks:

  • moq-net: ALPNS, Hops::as_slice, stats::Failure::ALL, stats::RefusalKind::ALL;
  • moq-pattern: Pattern::segments;
  • moq-tokio: accept::Failure::ALL, connect::Addr, listen::Config::preferred_v4, listen::Config::preferred_v6;
  • moq-mux: container::fmp4::Muxer::fragment.

It adds connect::Addr::pinned, which takes an IntoIterator, the instance-keys quest's work.

Still refused, by rule or for other types:

  • cli::check_env: a &[&str] parameter, plus refused CLI types;
  • tls::PeerIdentity::chain: rustls's CertificateDer.

Impact

  • Breaking (MIGRATE.md): a struct or enum refused as a value only for a SocketAddrV4 or SocketAddrV6 is now a value. An item that newly exports can clash with another's C name.
  • New C names: the getters and methods above, and <prefix>_vec_<T> for new element types. No new runtime names.

Follow-ups

  • connect::Addr::pinned once instance-keys maps IntoIterator.
  • std::slice::Iter returns (Hops::iter, Versions::iter, Patterns::iter) could cross as the same array.

🤖 Generated with Claude Code

kixelated and others added 2 commits October 28, 2026 16:54
A slice crosses as a `Vec` does, as `<prefix>_vec_<T>`: 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 `<prefix>_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 <noreply@anthropic.com>
@kixelated kixelated changed the title Slices of any type, and SocketAddrV4/V6 feat(ffi): export &[T] of any type, and SocketAddrV4 and SocketAddrV6 Oct 29, 2026
@kixelated
kixelated marked this pull request as ready for review October 29, 2026 00:07
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T02:49:12.864015Z 0d32c8f New commits
🔒 Security Review ✅ Completed 2026-10-29T02:51:54.515074Z 0d32c8f New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review by review (OpenAI)

Reviewed commit: 77fce05

No actionable bugs found. Reusing the existing array ABI and owned-list cleanup is a simpler direction than adding a separate slice representation: inputs are lifted into call-local vectors, returned slices become owned clones, and unsupported borrowed/handle-bearing inputs remain refused. Keeping the socket family in the IR while sharing the C layout preserves the existing ABI; family checks are applied during Rust lifting and Kotlin serialization. The migration note appropriately calls out newly exported values and possible name collisions.

Verification: static inspection of collection/refusal rules, glue and ABI ownership, socket conversion paths, and the C/C++/Kotlin positive and failure fixtures. I did not run builds, census, tests or sanitizers; the fixture results reported in the PR were not independently reproduced.

@kixelated
kixelated merged commit 29e7ea2 into main Oct 29, 2026
1 check passed
@kixelated
kixelated deleted the quest/m1/ffi-export/slices branch October 29, 2026 03:08
kixelated added a commit that referenced this pull request Oct 29, 2026
Co-authored-by: Luke Curley <432854+kixelated@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant