Repository navigation
feat(ffi): export &[T] of any type, and SocketAddrV4 and SocketAddrV6 - #205
Conversation
Quest-Claim: 3b4564c9755de085
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>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
kixelated
left a comment
There was a problem hiding this comment.
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.
Co-authored-by: Luke Curley <432854+kixelated@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Claims quest/m1/ffi-export/slices.md and finishes it.
Problem
After #190, the census still refused
&[T]of any type butu8(12 refusals at the pinned moq), andSocketAddrV4andSocketAddrV6(moq-tokio'slisten::Config::preferred_v4andpreferred_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 aVec, which coerces to the slice at the call. Returned, the glue's borrowed-return lowering now callsToOwned::to_ownedinstead ofClone::clone. That is the same for every sizedClonetype, and turns a&[T]into aVec<T>of clones, so a returned slice needs its elementsClone. The generators need no change: C, C++, and Kotlin already handle a borrowedVec.slice of references), as aVecof 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.SocketAddrV4andSocketAddrV6:Type::SocketAddrnow 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 throwsIllegalArgumentExceptionbefore the call, since a Kotlin caller can easily pass the wrongInetAddress.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;V4andV6aborting from C on the wrong family rather than converting an IPv4-mapped IPv6 address.Proof
Shape::ALL, a constant&[Shape]of a plain enum;GREETINGS, a constant&[&str];&[Point]and a&[String]passed in;&[Point], and a returned&[Label]whose clones own memory;SocketAddrV4andSocketAddrV6in and out, with the scope ID kept.Clonetype.moq/moq.c,moq.cpp, andmoq.ktagainst moq readALPNS, and setlisten.preferred_v4orpreferred_v6and read it back.Census
moq's exports (exported / refused), before and after, against main at 75a5cad:
All four refused constants now export (as getters).
moq/ffi.tomldrops the 11 excludes this unblocks:ALPNS,Hops::as_slice,stats::Failure::ALL,stats::RefusalKind::ALL;Pattern::segments;accept::Failure::ALL,connect::Addr,listen::Config::preferred_v4,listen::Config::preferred_v6;container::fmp4::Muxer::fragment.It adds
connect::Addr::pinned, which takes anIntoIterator, 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'sCertificateDer.Impact
SocketAddrV4orSocketAddrV6is now a value. An item that newly exports can clash with another's C name.<prefix>_vec_<T>for new element types. No new runtime names.Follow-ups
connect::Addr::pinnedonce instance-keys mapsIntoIterator.std::slice::Iterreturns (Hops::iter,Versions::iter,Patterns::iter) could cross as the same array.🤖 Generated with Claude Code