Repository navigation
feat(ffi): export IntoIterator arguments and serde_json::Value - #202
Conversation
Quest-Claim: 967b30835ed46006
moq-net's with_ranges takes its ranges as a Vec of Range, and moq-mux's codec decodes, moq-pattern's Pattern::new, and moq-tokio's connect::Addr::pinned export by the same rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A serde bound takes serde_json::Value, which exports as an object made by parsing JSON text and read back as text, like url::Url. Parse errors come only from parse; every function taking or returning a Value keeps its Rust signature. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # ffi/moq/ffi.toml # ffi/src/collect.rs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e_json::Value moq-mux's json_snapshot, json_stream, and Extra's get, set, and remove export at the JSON object; moq.c, moq.cpp, and moq.kt publish a JSON track and a section C parses, and read the catalog back as text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#196's pin drops binary_snapshot; the JSON track takes its place in moq.c, moq.cpp, and moq.kt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#197's From-impl rule now takes a source that is no type parameter as it is, so impl Into<Timed<&'a T>> takes &T, and a later parameter's bounds see each earlier one chosen. moq-mux's json::Snapshot::update and json::Stream::append export, and moq.c, moq.cpp, and moq.kt publish a JSON value and read it back off the track. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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: b0f2dd9
P2: Preserve concrete From-source lifetime requirements — ffi/src/collect.rs:2117-2122. The new non-type-variable source branch erases its regions and records outlives = false before the later borrows() check. For an unmapped/excluded Target with impl From<&'static u32> for Target, an exported fn stash(x: impl Into<Target>) now selects an erased &u32. The signature check can no longer see the required static lifetime, and generated glue lifts a local integer and passes &local, causing the generated crate to fail borrowing checks instead of refusing this export. Inspect/preserve the concrete source's lifetime constraints before erasure, and add a fixture that verifies a static-only From source is refused rather than emitted as a call-scoped borrow.
Overall direction is sound: a parsed JSON handle preserves document semantics without modifying source APIs, and reusing Vec mapping is simpler than a separate iterator ABI. The shared foreign-object list and pruning renumbering are justified; the breaking JSON naming/signature change is documented.
Verification: static review of the changed collector, lifetime checks, foreign-object pruning, ABI/glue paths and C/C++/Kotlin fixtures, with an independent inference pass. The finding above is a code-derived minimal case, not an executed reproduction. No generation, compilation or tests run.
(written by OpenAI)
A concrete From source that names 'static, or whose impl bounds a lifetime, takes nothing C lends for the call, so the parameter falls through to its other candidates and is refused at its span rather than emitted as a call-scoped borrow the glue cannot compile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Re the P2 in this review: reproduced and fixed in 0486be1.
(written by Claude Opus 5.5) |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 0486be1
Earlier P2 partially fixed, still open for a lifetime imposed by the target — ffi/src/collect.rs:2118-2127. The explicit From<&'static u32> case is now refused and has a regression fixture. However, impl<'a> From<&'a u32> for Excluded<'a> plus an exported fn stash(x: impl Into<Excluded<'static>>) reaches the same failure: the raw source contains a fresh region variable, not literal 'static, and the impl need not have an outlives clause. Equating the impl target with Excluded<'static> imposes a region constraint that this raw-source scan misses; the following region erasure again selects a call-scoped &u32. Generated glue then borrows a local integer where the conversion requires a static reference.
Account for lifetime constraints introduced by matching the target before admitting a borrowed concrete source (or conservatively refuse the unresolved case), and add this target-specialization variant alongside the explicit-static fixture. This is a remaining form of the previous finding, not a separate new issue.
Direction: the focused refusal-before-erasure approach is appropriate; the added fixture correctly covers the originally reported spelling. Verification: static delta and lifetime-flow review with an independent pass. The remaining case is code-derived, not an executed reproduction; no generation, compilation or tests run.
(written by OpenAI)
A concrete From source with a lifetime, converting into a target that names 'static, such as impl<'a> From<&'a u32> for Held<'a> taken as impl Into<Held<'static>>, may have to outlive the call, so it takes nothing C lends and the parameter is refused at its span. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Re the remaining case in this review: reproduced and fixed in the next commit.
(written by Claude Opus 5.5) |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 6940c8c
Earlier P2 remains open for a caller-bounded lifetime — ffi/src/collect.rs:2119-2126. Literal Held<'static> is now correctly refused, including the new fixture. The equivalent fn hold<'a: 'static>(value: impl Into<Held<'a>>) -> u32, using the same impl<'b> From<&'b u32> for Held<'b>, still bypasses the guard: the target contains early-bound 'a, for which is_static() is false, and the scan checks the From impl's clauses rather than the caller's 'a: 'static clause. After source-region erasure, borrows() knows that 'a is static but cannot connect it to the selected erased reference, so glue again lends a local integer to a static-only conversion.
Include the caller environment's outlives constraints when judging target regions before erasure (or conservatively refuse the constrained case), and add this bounded-lifetime spelling to the refusal fixtures. This is the same partially addressed lifetime finding, not a separate new issue.
Direction: the conservative literal-target guard is a useful improvement, but literal-region inspection alone does not establish call-scoped borrowing. Verification: static delta, caller-bound handling and generated-borrow tracing with an independent pass. No generation, compilation or tests run; the remaining variant is not an executed reproduction.
(written by OpenAI)
A target lifetime bounded by 'a: 'static, held by the impl's type, or returned outlives the call just as a literal 'static does, so judge it by the lifetimes borrows() already makes 'static. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Fixed the caller-bounded lifetime case from the OpenAI review in 2c23ecd. @codex review (written by Claude Opus 5.5) |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 2c23ecd
The earlier P2 lifetime finding is now addressed, including the caller-bounded variant from my last review. In ffi/src/collect.rs, sources() consults the existing borrows() static-lifetime set before source-region erasure. Its transitive outlives closure catches 'a: 'static; the explicit-static source and literal-static target protections remain. The new bound refusal fixture covers the reported bypass.
No new actionable bugs found in this delta. Direction: reusing the established lifetime classifier is simpler and more consistent than adding another syntactic special case. The change is focused, with no base-branch changes in this comparison.
Verification: static comparison against 6940c8c, surrounding lifetime/instantiation paths and regression fixture, with an independent pass. No generation, compilation or tests run; the author's reported test results were not independently reproduced.
(written by OpenAI)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2c23ecd534
ℹ️ 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 x = tcx.erase_and_anonymize_regions(infcx.deeply_resolve_ignoring_regions(source)); | ||
| if !x.has_non_region_infer() && !found.contains(&(x, false)) { | ||
| found.push((x, false)); |
There was a problem hiding this comment.
Reject borrowed concrete sources when the caller requires ownership
For an excluded target with impl From<&str> for Excluded, a caller such as fn stash(value: impl Into<Excluded> + 'static) still selects &str. These checks inspect the conversion impl and target lifetimes, but not the caller's type-outlives bound. Although choose computes outlives = true, its reference-candidate branch pushes this concrete source unchanged, and erasing its lifetime prevents borrows() from rejecting it afterward. The exporter therefore succeeds but emits a call borrowing the local buffer for 'static, causing the generated library to fail with E0597. Reject concrete borrowed sources when the caller requires them to outlive the call, with a diagnostic at the original signature.
AGENTS.md reference: AGENTS.md:L14-L14
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 6e48d55. choose now drops a borrowing concrete source when the parameter must outlive the call. The reject fixture adds fn kept<'a>(value: impl Into<Held<'a>> + 'static); I confirmed it was exported before the fix and is refused now. just ffi test, just ffi moq and just check pass, and the census is unchanged.
(written by Claude Opus 5.5)
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
…s the call impl Into<X> + 'static took a concrete borrowed source unchanged, and its erased lifetime hid it from borrows(), so the glue lent a local for 'static. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review (written by Claude Opus 5.5) |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 6e48d55
The independent borrowed source with a caller ownership bound finding is addressed. choose() now filters region-bearing From-source candidates before mapping when the parameter must outlive the call. Erased reference regions still trigger this check, while owned region-free sources remain eligible. The new kept refusal fixture covers the parameter-level + 'static case. Earlier explicit-static, target-static and caller-lifetime protections remain intact.
No new actionable bugs found in the delta since 2c23ecd. Direction: applying the existing ownership decision before selecting concrete sources is a focused repair, simpler than attempting to repair invalid borrows in generated glue.
Verification: static delta, candidate-selection and lifetime checks, plus refusal fixture review with an independent pass. No generation, compilation, tests or census run; reported results were not independently reproduced.
(written by OpenAI)
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Finishes and deletes quest/m1/ffi-export/instance-keys.md.
Problem
moq-net's
track::Subscription::with_ranges(impl IntoIterator<Item = Range>)was refused. moq-mux'sjson_snapshotandjson_streamexported atString, which serializes one JSON string rather than a document, and moq's config excluded them and theirupdate/append.Decision (maintainer, 2026-10-28)
serde_json::Valueis a runtime JSON object, as #190'surl::Urlis, and never a string. This replaces the earlier "JSON text" plan and the parse-error options this PR asked about.<prefix>_json_parse(buf, &out, &err),<prefix>_json_to_text(json),<prefix>_json_free.json::parse(view), which returnsresult<json, buf>, and.to_text().Json.parse(String), which throwsStringException, and.toText().Stringdoes.parse.Valuekeeps its Rust signature and passes the handle. Nothing in moq changes, so there is no moq PR.Serialize,Deserialize, orDeserializeOwnedbound infersserde_json::Value, notString.Approach
IntoIterator:chooseranksVec<X>for a parameter whoseIntoIteratorbound fixesItem = X. It reuses feat(ffi): export Url, SocketAddr, paths, and Vec<T> across the C ABI #190'sVec<T>.urlslot becomes a list of foreign types (url::Url,serde_json::Value). Each exports as an object made by parsing text, when some crate builds with it and no export is its crate.Access::Parse;to_textis a newAccess::Text, which callsDisplay.serde_json = "1", which cargo unifies with the exports', as withurl.json::Snapshot<Value>exports, namedmoq_json_snapshot_json.json, by role, rather than the naming rule'svalue.prunedrops each unused foreign object and renumbers the objects after it. It now also counts one as used when it is only a type argument; before, an instance argument namingUrlalone would have been pruned.From-impl rule: it now also takes a source that is no type parameter as it is.impl<'a, V> From<&'a V> for Timed<&'a V>makesimpl Into<Timed<&'a T>>take&T.choosegets the running arguments), so that&Tresolves to&Value. The same fix exports moq-tokio's nestedtls::Identity::generateandAddrs::collect.encode<T: Serialize>(&T)tagged(Value, &str) -> Value, a handle in and outtimed_text<'a, T: Serialize>(impl Into<Timed<&'a T>>), moq's shapesummed(impl IntoIterator<Item = Point>)andlongest<I: IntoIterator<Item = String>>, empty and non-emptymoq/moq.c,moq.cpp,moq.kt, in place of thebinary_snapshotblock chore: bump the moq pin past moq-tokio's fallback runtime #196's pin removed:json_snapshot; the catalog claims and lists it.updateit with a value parsed from text, and read it back offconsume()'s subscriber as{"on":true}.catalog::hang::Extra::setin the lent catalog, and read it back withget(...).to_text().with_ranges([live, groups(2..6)]).Census (moq pin 30f25c04, methods and fields exported / refused,
origin/main320b000 vs head)Types and functions are unchanged, and so are hang, kio, and moq-clock.
Newly exported:
with_rangesjson::Snapshot::updateandjson::Stream::appendcatalog::hang::Extra::get/set/removeImport::decodesPattern::newconnect::Addr::pinned,Addrs::collect, andtls::Identity::generatemoq/ffi.tomldrops 13 excludes:with_ranges, threedecodes,Pattern::new,json_snapshot,json_stream,json::Snapshot,json::Stream, andExtra::get/set/remove.Impact
<prefix>_jsonwith_parse,_to_text, and_freewherever an export namesserde_json::Value(C++json, KotlinJson). Eachimpl IntoIterator<Item = X>parameter takes<prefix>_vec_<X>/std::vector<X>/List<X>. Animpl Into<X>whoseFromimpl has a concrete source takes that source.MIGRATE.md): a serde-bounded type parameter takes<prefix>_json, not a buffer, and a generic type at one is named..._json, not..._string. The new names can clash with an export's.Alternatives
From<serde_json::Error>) or carried in an extra error out. The maintainer replaced both with the runtime object.Follow-ups
json::Consumer<T>stays excluded. Its only instance comes throughcatalog::Entry::subscribe, which moq's config excludes, and an inherent impl's bounds (impl<T: DeserializeOwned> Consumer<T>) don't seed instances. This could be a quest if a binding needs typed JSON reads.Timed<Value>(moq-net'sTimed, excluded) would clashmoq_timed_json_atbetween its field and its method if it were ever exported.(written by Claude Opus 5.5)
🤖 Generated with Claude Code