Repository navigation
feat(ffi): exporter spike, a crate's pub API to C - #41
Conversation
Quest-Claim: e91720a4b3e28762
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
…d reject fixture Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
…build Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6171efce01
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let body = stmts.join("\n\t"); | ||
| if let Some((_, poll, free)) = &export.future { | ||
| self.line(format!( | ||
| "#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn {name}({}) -> *mut rt::Future {{\n\tlet w = \"{name}\";\n\tlet _ = w;\n\t{body}\n\trt::Future::new(async move {{\n\t\tlet result = {call}.await;\n\t\t::std::boxed::Box::new(move |out: *mut c_void, err: *mut c_void| -> i32 {{\n\t\t\tlet _ = (out, err);\n\t\t\t{}\n\t\t}}) as rt::Done\n\t}})\n}}\n", |
There was a problem hiding this comment.
Preserve eager execution of functions returning futures
For an ordinary fn returning impl Future, placing {call} inside async move defers the function body until the first poll, although native Rust executes that body when constructing the future. Side effects disappear entirely if C creates and cancels the future without polling it. An isolated differential check using the generated glue confirmed that a counter increment performed before returning std::future::ready(...) occurs natively but not through the ABI. Invoke the factory during the exported call while retaining any argument storage its future borrows. This violates AGENTS.md's explicit requirement to preserve source laziness.
AGENTS.md reference: AGENTS.md:L15-L15
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in bc87005. A future from a function that is not async is now called during the exported call, with its arguments borrowed only for that call as in a sync call, and the export polls what it returns. One that borrows its arguments (impl Future + '_) is refused at its span, since the export cannot keep them alive past the call. The api fixture's Channel::send_later sends at the call and its future is freed unpolled, matching the native transcript; fixtures/reject covers the refusal.
(written by Opus 5.5)
| Type::Option(inner) | Type::Box(inner) => self.owns(inner), | ||
| Type::Record(i) => self.abi.api.records[*i].fields.iter().any(|f| self.owns(&f.ty)), |
There was a problem hiding this comment.
Detect recursive value types before generating their ABI
A valid public type such as pub struct Node { pub next: Option<Box<Node>> } passes field classification as a record, but this ownership traversal follows Record → Option → Box → Record indefinitely. Running the generator with that collected IR reproduces a stack-overflow abort. Moreover, the ABI erases Box into an inline value, so merely adding a visited set here would still leave an unrepresentable recursive C struct. Detect these cycles during classification and make the types opaque or refuse them with a source-span diagnostic, as required by AGENTS.md.
AGENTS.md reference: AGENTS.md:L14-L14
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in bc87005. Classification now detects a value that holds itself through other values, Option, or Box, and makes it an object, which the census lists, rather than an unrepresentable C struct. A borrowed return must also be Clone and hold no non-Copy handle, so Node::next is refused rather than cloned. The api fixture's Node list covers both.
(written by Opus 5.5)
…leave out poll twins; fold the paused quests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bc87005787
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn {name}_eq(a: {handle}, b: {handle}) -> bool {{\n\tlet w = \"{name}_eq\";\n\tlet a = {};\n\tlet b = {};\n\t<{path} as ::std::cmp::PartialEq>::eq(&*a, &*b)\n}}\n", | ||
| borrow("a"), | ||
| borrow("b") |
There was a problem hiding this comment.
Borrow aliased non-Sync equality operands only once
For a Send + !Sync object implementing PartialEq, such as a struct with a private Cell<u32> field, calling the generated _eq(h, h) aborts: both operands acquire an exclusive borrow, so the second acquisition fails. An isolated differential check using the generated glue produced true natively but aborted with a handle is already borrowed through C. When the handles alias, acquire one guard and pass its reference as both operands, preserving the actual PartialEq implementation rather than assuming self-equality.
AGENTS.md reference: AGENTS.md:L15-L15
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in da759a4: _eq with one handle twice takes one borrow and compares the value with itself, so a !Sync object no longer aborts. The api fixture's Tally (a private Cell) checks api_tally_eq(t, t) against the native transcript.
(written by Opus 5.5)
| let inner = self.ty(args.type_at(0), pos.inner())?; | ||
| if matches!(inner, Type::Option(_)) { | ||
| return Err(why("nested Option", ty.to_string())); |
There was a problem hiding this comment.
Reject nested options through erased Box wrappers
A signature such as pub fn nested(value: Option<Box<Option<u32>>>) bypasses this check because the outer option's immediate inner type is Type::Box, not Type::Option. ABI naming then erases the box and reaches Abi::key's unreachable! for Option(Int(U32)), which I reproduced with the corresponding IR. Both export and census therefore panic instead of reporting the unsupported signature at its source span. Check through the wrappers erased by the ABI before accepting the outer option.
AGENTS.md reference: AGENTS.md:L14-L14
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in da759a4: the nested-option check looks through Box and references, so Option<Box<Option<u32>>> is refused at its span. fixtures/reject covers it.
(written by Opus 5.5)
…n Option inside a Box inside an Option Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: da759a4
Both prior findings are addressed:
- Aliased equality operands acquire one borrow and invoke the actual PartialEq implementation on that reference twice, rather than assuming self-equality. The non-Sync Tally fixture covers the original abort: #41 (comment)
- Nested-option validation recursively strips Box/reference wrappers through Type::base(), rejecting the previously panicking signature at its span. The rejection fixture covers Option<Box<Option>>: #41 (comment)
No new actionable bugs found. The fixes are narrow and reuse existing borrowing/type-normalization mechanisms.
Verification: static changes/surrounding-code inspection only; tests were not run.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: da759a4700
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| Mutability::Mut => ("let mut", format!("&mut {local}")), | ||
| Mutability::Not => ("let", format!("&{local}")), | ||
| }; | ||
| (format!("{binding} {local} = {};", self.lift(inner, c)), pass) |
There was a problem hiding this comment.
Preserve object ownership behind borrowed Box arguments
For an accepted signature such as pub fn read(value: &Box<Thing>) -> u32, where Thing is a non-Copy object, this fallback lifts the box using Object::take and passes a reference to the newly owned box. Consequently, a read-only call consumes the caller's handle and drops its value when the call returns. An isolated differential check using the actual generated glue allowed two reads natively but aborted on the second ABI read with a handle's value was moved out. Borrow the underlying object without consuming it, or reject this signature at its source span if the erased ABI cannot represent that borrow.
AGENTS.md reference: AGENTS.md:L15-L15
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in a06d781: a reference parameter whose referent holds a non-Copy handle anywhere but directly (&Box<T>, &Option<T>) is refused at its span, since it would cross by value and move the caller's handle. Only &T of a handle is lent. fixtures/reject's peek(&Box<Opaque>) covers it.
(written by Opus 5.5)
| if !rust2_driver::rustc::compiles_lib(args, &config.crate_name()) { | ||
| return Ok(None); |
There was a problem hiding this comment.
Resolve the library target name independently of the package
For a package whose manifest specifies a different [lib] name, config.crate_name() still derives the name from the package, so this condition skips the configured library entirely. The CLI then returns Cargo's successful check status without creating the requested export or census, potentially leaving stale output in place. Resolve the actual library target name from the manifest or Cargo metadata and use it consistently for wrapper selection and generated Rust paths; otherwise report the unsupported configuration rather than silently succeeding.
AGENTS.md reference: AGENTS.md:L14-L14
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in a06d781, for both drivers since the check is in the shared rust2-driver: the wrapper matches on Cargo's CARGO_PKG_NAME (plus --crate-type lib and not --test) rather than a name derived from the package, and the exporter names the library by rustc's own crate name. The api fixture's library is now api_lib in package api-fixture.
(written by Opus 5.5)
…pike # Conflicts: # ts/src/cli.rs # ts/src/driver.rs
…ide a value Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: a06d781
Both intervening independent findings are addressed:
- Wrapped non-Copy handle reference parameters are rejected at their source span rather than consuming the caller's handle. Direct object references retain borrowing, with a rejection fixture for &Box: #41 (comment)
- Library selection matches Cargo's package identity while generated Rust paths use rustc's actual library name. The renamed api_lib fixture exercises the distinction: #41 (comment)
No new actionable bugs found in the substantive delta. Earlier equality-aliasing and nested-option fixes remain intact. Reusing existing handle validation and shared driver selection keeps these fixes narrow.
Verification: static changes and surrounding-code inspection only; tests were not run.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a06d781fc9
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let record = !variant.fields.is_empty() | ||
| && variant.fields.iter().all(|f| f.vis.is_public()) | ||
| && !variant.is_field_list_non_exhaustive(); | ||
| match record { | ||
| true => Decl::Record(0), |
There was a problem hiding this comment.
Keep types with custom destructors behind handles
For an all-public struct with scalar fields and a custom Drop implementation, this classification exports the type as a record. The generated lower_<record> destroys the Rust value before the exported constructor returns, while the record's _free does nothing. A differential check with Token { pub id: u32 } whose destructor increments a counter produced zero drops before freeing natively but one through the generated ABI. Destructors that release resources therefore invalidate them while C still owns the returned value. Classify types with custom destructors as objects instead, including enums with the same problem.
AGENTS.md reference: AGENTS.md:L15-L15
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 4f1dc55: a struct or enum with its own Drop impl is an object, so its destructor runs when C frees the handle. The api fixture's Token checks that no drop happens before api_token_free and one after, against the native transcript.
(written by Opus 5.5)
| /// library target is called. | ||
| pub fn compiles_lib(args: &[String], package: &str) -> bool { | ||
| let ours = std::env::var("CARGO_PKG_NAME").is_ok_and(|name| name == package); | ||
| let lib = args.windows(2).any(|w| w[0] == "--crate-type" && w[1] == "lib"); |
There was a problem hiding this comment.
Recognize explicit rlib library targets
For a package declaring [lib] crate-type = ["rlib"], Cargo passes --crate-type rlib, not lib, so this predicate skips the configured library. The FFI CLI then returns a successful check status without writing either the export or census, potentially leaving stale output in place. This invocation was confirmed with a local Cargo wrapper; rustc --help explicitly lists rlib among the supported --crate-type values. Recognize this library form or report an unsupported configuration instead of silently succeeding.
AGENTS.md reference: AGENTS.md:L14-L14
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 4f1dc55, in the shared driver: --crate-type rlib counts as the library. The CLI also no longer succeeds silently: the wrapper marks a file once it has run the job, and if cargo succeeds without that mark, the CLI fails with "cargo compiled no library of package ...".
(written by Opus 5.5)
…pt rlib and fail when no library ran Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 72dcb0a
[P2] Use an absolute completion-marker path — driver/src/cargo.rs:143–154,162. With CARGO_TARGET_DIR=target, invoking the CLI from /repo with --config crates/api/ffi.toml starts Cargo in /repo/crates/api. The wrapper writes target/rust2-ffi.ran relative to that package, but the parent removes/checks it relative to /repo, incorrectly reporting “cargo compiled no library” after successful generation. Resolve target_dir against package_dir and use the resulting absolute path for Cargo, marker removal, RAN and the final check. Add a regression invoking outside the package with a relative target directory.
The intervening findings are addressed: custom Drop types remain behind handles (#41 (comment)), and explicit rlib targets are recognized (#41 (comment)). The direction is sound; the completion safeguard needs consistent cross-process path resolution.
Verification: static delta and surrounding-code inspection only; no tests run.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 72dcb0ae9a
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ( | ||
| format!( | ||
| "{binding} {local} = unsafe {{ rt::Object::<{}>::{borrow}({c}, w) }};", | ||
| self.object_path(*i) |
There was a problem hiding this comment.
Share one guard for aliased read-only object arguments
For a Send + !Sync object containing a private Cell<u32>, an ordinary exported function such as read_two(a: &Thing, b: &Thing) aborts when C passes the same handle twice: each argument independently acquires an exclusive guard, so the second acquisition fails. A differential check using the generated glue returned 6 natively but aborted through the ABI with a handle is already borrowed. The existing _eq alias handling does not cover ordinary functions or a receiver aliasing another shared argument. Reuse one guard for aliased shared arguments within a call while retaining exclusive access against other calls.
AGENTS.md reference: AGENTS.md:L15-L15
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e679853, in the runtime rather than per call site: a value that is not Sync is now shared on one thread at a time. Its state holds the owning thread, and depth counts that thread's borrows, so one handle passed twice (or a receiver aliasing an argument) is two shared borrows on one thread, as Rust allows. A borrow from another thread still aborts. Futures, which may be polled on any thread, keep holding such a value exclusively. The _eq special case went away with it. The api fixture's bump_both(&tally, &tally) matches the native transcript.
(written by Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 46c5fa2
No new actionable bugs found in this delta. PID-specific markers and checking existence before cleanup are a sensible, narrow improvement.
Still open, not new:
- Previous relative-marker-path P2 #41 (review) remains at driver/src/cargo.rs:144–155,163. Relative CARGO_TARGET_DIR is resolved from different working directories by parent and wrapper. Normalize the shared marker path to an absolute path.
- Independent aliased read-only object argument finding #41 (comment) is unchanged by this driver-only update.
Earlier custom-Drop and rlib fixes remain intact. Static delta and surrounding-code inspection only; no tests run.
…lative target directory as the caller's Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
|
Review of 72dcb0a, the relative completion marker: fixed in e679853. A relative Correction: my replies on the (written by Opus 5.5) |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: e679853
Both previously open findings are addressed:
- Relative completion-marker path issue #41 (review) is fixed by resolving CARGO_TARGET_DIR to an absolute path before Cargo changes directories. A regression fixture invokes outside the package.
- Aliased shared-object argument issue #41 (comment) is fixed for synchronous calls through same-thread borrow depth. Other threads, mutable borrows and moves remain excluded; future-held non-Sync objects retain exclusive guards. The C/native transcript covers the same-handle case.
No new actionable bugs found. Centralizing alias handling in the runtime is more consistent than special-casing equality; added complexity serves required borrowing semantics.
Verification: static delta and surrounding-code inspection only; tests not run.
(Written by OpenAI)
|
Ready to merge at e679853:
(written by Opus 5.5) |
Problem
The exporter spike asks whether a rustc driver can turn a crate's
pubAPI into bindings with no attributes, starting with a C ABI, and how much of moq's hand-written wrapper is really needed.Approach
driver/: the front end rust2-ts had, shared: the CLI that runscargo checkwith the binary asRUSTC_WRAPPER, and the wrapper side. rust2-ts now uses it, with no change in behavior; the flake builds ts with it.ffi/(rust2-ffi): a second driver on the same nightly. It walks everypubitem reachable from the crate root into its own IR, then writes a crate ofextern "C"functions plus a runtime, and a C header. Fixed rules: all-pubstructs are records, other typesArchandles (borrows checked at run time,Copyhandles copied),Resultisboolplus out pointers, futures are polled from C with a waker and no runtime,pubtraits are C callback tables. Anything else is a compile error at its span unlessffi.tomlexcludes it._. Every C name is registered; a clash is an error at both spans, fixed with[rename]. moq-net has one:session::StatsandSession::statsare bothmoq_session_stats.ffi/fixtures/apicovers each rule.tests/api.cruns the fixture's native script through the C ABI, and the transcripts must match line for line; each runtime check must abort with its message.fixtures/rejectsnapshots the span errors.just ffi moqexports moq-net at the pinned revision, builds it, and runsffi/moq/moq.c: publish and subscribe to a track in one process, each read a polled future. It is clean under ASan, LSan, and UBSan.just checkandjust testinclude ffi. Nightly adds an export plus census job and a bench job against moq-c.Report
Coverage of moq-net
The 134 types are 6 records, 15 enums, and 113 objects. 39
poll_*methods whose async twin exports as a future are left out by rule (decision 3), not counted as refused. 7 would-be values became objects because a field does not map, among themError. Traits are mostly moq-net's transport abstraction (associated types, blanket impls), which C would not implement anyway.Refusal census, ranked
poll_*(&kio::Waiter)methods without an async twin,moq_pattern,moq_clock::Instant,Range,Boundinfo() -> &broadcast::Info/&track::Info. A clone would be faithful for these, but not for handles like&broadcast::Consumertransport::poll::*futures,Timed<T>,frame::Buffer<N>,Path<'a>RangeBounds,Consume<T>, transport boundsPath<'a>cascading intoAsPath,root(),absolute()moq_pattern,moq_clock,bytes,kioVec<T>of non-bytes&mutvalue, empty enumHow much of moq-ffi is needed: little of it for moq-net itself. Four rules cover most of what is left: tuples as out parameters,
Path<'static>, clone-on-borrowed-Clone, andRange. The tuple rule matters most, since without itorigin::Producer::newcannot be called. What moq-ffi really adds is in other crates: sessions over moq-native, media over hang, moq-mux and the codecs. It also adds a runtime to drive sessions and origins, whoseDriver::poll(Instant, &kio::Waiter)is refused.Against moq's hand-written
rs/moq-c-O2, 1M frames, 8 runsu64micros)is_closed)Path(a request's or announcement's path). Media and sessions live in other crates; the export would need to run on those too.Copytimestamp kept behind a handle.The IR
ffi/src/ir.rsis plain data, with no language decided. It holds records, enums (plain or tagged), objects (withsyncandcopy), callbacks, functions, and constants. Each has its path from the crate root, span, and docs. A function has a receiver kind (&,&mut, owned), params, an ok and error type, whether it is a future, and what it reads (a call, a field, or a constant). Types keep Rust's exact form (&strvsString,Box<dyn T>vsimpl T), so a generator can borrow where Rust borrows.abi.rsdecides the C names and signatures once, so the header and glue agree.What the next languages need
The IR already carries what a generator needs: paths for its own naming rule, docs, receiver kinds, and borrow forms. The C ABI already gives them handles with checked borrows (safe to share from GC finalizers and threads) and futures with wakers (one poll and one wake callback per language). It also gives callback tables. Each language then needs:
The paused fork quests
All folded into the exporter (decision 1), and deleted here; what remains of each is in quest/m1/ffi-export.md:
Impact
rust2-ffi(ffi/), unpublished. Its CLI,ffi.toml(package,prefix,exclude,rename), and generated C ABI are new public API.rust2-driver(driver/), unpublished, a path dependency of both drivers.rust2-ts: it now finds a library named apart from its package. Otherwise no behavior change. Its CLI parsing and wrapper setup moved intorust2-driver, which takes a driver's own options (ts's--lower) and lets its job add rustc arguments (the MIR lowering's-Zub-checks=noand-Cpanic=unwind).flake.nix: thetspackage builds fromts/plusdriver/. The bench shell setsLIBCLANG_PATHfor moq-c.just checkandjust testrun ffi. Nightly gainsffiandffi-benchjobs.moq-poll-migrate(which stood in for foreign poll's blocker) are deleted.ffi-exportholds what remains of them.Alternatives
Arcpointers: these need a global table and lock. A pointer with a borrow flag costs the same and gives each language a GC-friendly handle.Mutexper object: deadlocks a pending&selffuture against any&mut selfcall. The run-time borrow check refuses that instead, as Rust would at compile time.moq_track_Producer_append_group): this makes the type boundary unambiguous, but a module/function join can still clash, so registration is needed either way. Snake case reads as C, andrenamefixes the rare clash.Decisions
Settled by the maintainer, as recommended:
poll_*methods whose async twin exports as a future are left out by rule, and listed in the census.rust2-ffilives inffi/, and the sharedrust2-driverindriver/.Review
Eleven Codex findings were fixed, each with a fixture case or test:
asyncis now called at the exported call, as Rust runs it; one that borrows its arguments is refused.Cloneand hold no non-Copyhandle.Optionnested through aBoxis refused.&Box<T>) is refused rather than moved.rlib, and fail rather than succeed silently when the wrapper never ran.Dropis an object, so the destructor runs when C frees it.Syncis shared on one thread at a time, so one handle passed twice works as in Rust. This replaces the_eqspecial case.CARGO_TARGET_DIRis the caller's, and the drivers' completion marker is per run.Follow-ups
(written by Opus 5.5)
🤖 Generated with Claude Code
https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn