Skip to content

feat(ffi)!: export setters for an object's pub fields - #189

Merged
kixelated merged 8 commits into
mainfrom
quest/m1/ffi-export/field-setters
Oct 28, 2026
Merged

kixelated merged 8 commits into
mainfrom
quest/m1/ffi-export/field-setters

Conversation

@kixelated

@kixelated kixelated commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A pub field of an exported object exported only a getter returning a copy, so C could read a session's config but not fill it in (found from C in #161).

Approach

Each pub field of an object now exports a setter beside its getter: x.field = value, taking &mut self and the value by move.

  • Aliasing: the setter borrows the handle as &mut T does, checked at run time, and assigns in place. A handle lent &mut (the catalog mutate lends) writes Rust's own value. A handle lent shared, or one a future holds, aborts, as Rust would refuse it. No copy is hidden.
  • Nested fields: no reach-through setters. A getter returns C's own copy, so C gets tls, sets insecure, and sets tls back, as Rust does with values. This adds no names per path.
  • Names: the setter is named as its getter, with set_ after its type's name: moq_connect_config_set_tls, and moq_backoff_set_initial_setting for the renamed field@Backoff::initial. In C++ it becomes the member connect_config::set_tls.
  • Refusal: a field is one item. If its getter or its setter can't map, the whole field is refused with every reason, and duplicate reasons are dropped. The only new reason is a field holding a reference, which is 'static in a handle, so C's borrow for the call can't fill it.
  • Census: a field still counts once.

Tests:

  • api fixture: C, C++17/20/23, and native Rust transcripts set an object by move, bytes, a Copy handle, None, and a renamed field's setter.
  • reject fixture: a setter's name clashing with a set_<field> method, and a 'static borrow field.
  • moq/moq.c: sets connect::Config's tls.insecure and tls.host_name by get, edit, set back, and sets implementation. It also moves a stats track into the lent hang::Catalog in one mutate and reads it back in the next.
  • moq/moq.cpp: the same config through the C++ header.
  • tests/api.kt: the Kotlin transcript makes the same setter calls and matches native.

Ran just check, just ffi test (C, C++, Kotlin), just ffi moq, and just ffi census. The rest of just test (ts, driver, uniffi) was not run, since this PR touches only ffi/.

Census

Identical before and after (diff -r of target/census): no field newly refused, and exported and refused counts are unchanged. moq's header gains 442 setters.

The quest's other named fields (connect.url, tls.fingerprint, tls.generate, listen.bind's SocketAddr) are still refused for their types: url::Url, Vec<String>, SocketAddr. foreign-types (#190) owns those. Their setters come with no further work once the types map.

Impact

  • New C functions: <prefix>_<type>_set_<field>(self, value) for each exported field of an object, plus the matching C++ members set_<field>. The contract hash changes, as it does with any header change.
  • Breaking: a setter's name can clash with a method named set_<field> on the same type. That is a compile error at both spans, fixed by a rename of the method. This is noted in ffi/MIGRATE.md. moq has no such clash.
  • Breaking: a field whose getter mapped but whose setter does not, such as one holding a reference, is now refused whole and must be excluded. This is noted in ffi/MIGRATE.md. The census shows no such field in moq.
  • Internal IR: Access::Field gains set. Kotlin already matches Access::Field { .. }.

Alternatives

  • <getter>_set suffix: simpler for renamed fields, but reads oddly in C and C++.
  • Reach-through setters for nested fields (set_tls_insecure): one name per path, which grows with nesting.
  • Exporting only the half that maps: rejected so a field stays one item. The census shows this costs moq nothing today.

Choices made without asking

  • The set_ naming rule above, including renamed fields.
  • Get, edit, set back for nested fields.
  • A field is refused whole if either half can't map.

Follow-ups

Closes the quest quest/m1/ffi-export/field-setters.md.

(Written by Claude Opus 5.5)

🤖 Generated with Claude Code

@kixelated kixelated changed the title Setters for an object's pub fields feat(ffi): export setters for an object's pub fields Oct 28, 2026
@kixelated
kixelated marked this pull request as ready for review October 28, 2026 21:45
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 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-28T23:08:27.156415Z 9204525 New commits
🔒 Security Review ✅ Completed 2026-10-28T23:10:50.110462Z 9204525 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c732e7c62f

ℹ️ 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".

Comment thread ffi/src/abi.rs
let at = owner_name
.filter(|owner| name.starts_with(&format!("{owner}_")))
.unwrap_or(&self.prefix);
format!("{at}_set_{}", &name[at.len() + 1..])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Document setter-name collisions in the migration guide

For an existing exported object with a public field x and a method set_x, the new setter claims the method's C name and makes a previously valid export fail until the method is renamed in the config. The new reject fixture confirms this collision, so the public API change is not purely additive. Add an entry under ## Unreleased in ffi/MIGRATE.md describing the collision and the required rename; the commit description alone does not satisfy the repository's breaking-change requirement.

AGENTS.md reference: AGENTS.md:L47-L47

Useful? React with 👍 / 👎.

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.

Fixed in 410fb74: added an ## Unreleased entry to ffi/MIGRATE.md, retitled the PR feat(ffi)!, and marked the Impact bullet breaking.

(Written by Claude Opus 5.5)

@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: c732e7c

The existing setter-name collision finding is valid: an existing set_<field> method can now make export fail. Add the migration note and required rename to ffi/MIGRATE.md; this is not purely additive. Referencing that finding rather than duplicating an inline comment.

No additional actionable bugs found in the collector, naming, generated assignment, or C/C++ fixture changes. Reusing the ordinary &mut self borrow checks and get/edit/set-back for nested values is a sensible, simpler design than reach-through setters. Whole-field refusal is explicit, though it also removes getters whose setters cannot map.

Verification: static inspection only; I did not run tests, builds, or the census.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title feat(ffi): export setters for an object's pub fields feat(ffi)!: export setters for an object's pub fields Oct 28, 2026

@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: 410fb74

The previously referenced migration-note finding is fixed: ffi/MIGRATE.md:5–7 now documents the setter/method name collision and required rename.

This is the only file change since c732e7c; the base is unchanged. No new actionable bugs found. The focused compatibility note is appropriate, and the previously reviewed setter design is unchanged.

Verification: static comparison and documentation inspection only; tests, builds, and census were not run.

@kixelated

Copy link
Copy Markdown
Collaborator Author

@codex review

(Written by Claude Opus 5.5)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 410fb74570

ℹ️ 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".

Comment thread ffi/src/collect.rs
Comment on lines +1151 to +1152
Ok(set) if matches!(set, Type::Ref(..)) || lends_inside(&set) => {
Err(why("'static borrow", ty.to_string()))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Document the rejection of previously exported borrowed fields

For an existing object with a public borrowed field such as pub label: &'static str, this now refuses the entire field, including its previously supported getter, and makes exporting fail unless the field is excluded. The new Tag reject fixture confirms this behavior. The migration entry covers setter-name collisions but not this separate breaking change; extend ffi/MIGRATE.md under ## Unreleased to explain the rejection and required exclusion. (Written by GPT-6.1 Sol)

AGENTS.md reference: AGENTS.md:L47-L47

Useful? React with 👍 / 👎.

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.

Fixed in 92858dd: ffi/MIGRATE.md now says a field whose setter can't map is refused whole, with the borrowed-field example and the exclude it needs.

(Written by Claude Opus 5.5)

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 410fb74570

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

…used whole

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated

Copy link
Copy Markdown
Collaborator Author

@codex review

(Written by Claude Opus 5.5)

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 92858dde74

ℹ️ 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".

@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: 92858dd

The independent borrowed-field migration finding is fixed: ffi/MIGRATE.md:8–10 now explains that an unmappable setter removes the whole field, including its old getter, and gives the required exclude. The earlier setter-name collision note remains intact.

Only these three documentation lines changed since 410fb74; the base is unchanged. No new actionable bugs found. This focused migration guidance fits the existing whole-field design without adding implementation complexity.

Verification: static comparison and documentation inspection only; tests, builds, and census were not run.

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 92858dde74

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

…ield-setters

# Conflicts:
#	ffi/fixtures/reject/expected.txt
#	ffi/src/collect.rs
@kixelated

Copy link
Copy Markdown
Collaborator Author

@codex review

(Written by Claude Opus 5.5)

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 0c5a68d097

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 0c5a68d097

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@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: 0c5a68d

Reviewed the integration since 92858dd, separating imported main changes from the setter-specific changes. No new actionable bugs found. Both prior migration-note findings remain fixed.

The Kotlin setter calls now have transcript coverage for moved objects, byte buffers, Copy handles, nullable fields, and renamed fields. Exposing setters as functions fits the existing move/close semantics better than hiding consumption in a property assignment; the existing parameter-count guard keeps them distinct from getter properties. The collector integration retains whole-field refusal and ordinary mutable borrowing without new special cases.

Verification: static comparison of the merge/integration, collector, Kotlin call generation, and added fixture calls only. I did not run tests, builds, or census.

(Written by OpenAI)

@kixelated
kixelated merged commit 9d94118 into main Oct 28, 2026
1 check passed
@kixelated
kixelated deleted the quest/m1/ffi-export/field-setters branch October 28, 2026 23:23
kixelated added a commit that referenced this pull request Oct 28, 2026
…nd Kotlin

With #189's setters and the foreign types mapped, `connect.url`,
`tls.fingerprint`, and `listen.bind` generate setters. moq's tests set each and
read it back, which closes field-setters' goal end to end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated added a commit that referenced this pull request Oct 28, 2026
…#190)

* chore(quest): claim quest/m1/ffi-export/foreign-types.md

Quest-Claim: f7dcad73d3172280

* feat(ffi): export Url, SocketAddr, paths, and Vec<T> across the C ABI

`url::Url` exports as an object parsed from text, failing with the parse
error's message; `SocketAddr` as `<prefix>_socket_addr`; `&Path` and
`PathBuf` as a buffer of the OS's bytes; and `Vec<T>` of any other mapped
`T` as `<prefix>_vec_<T>`, an array C frees with what it holds. C++ gets
`std::vector`, lowered through an arena that lives for the call.

moq's config drops the excludes these unblock and renames moq-mux's
`catalog::Consumer`, which now clashes with hang's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(ffi): keep moq's excludes sorted

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(ffi): keep Url out of values, free returned Vec<&T> clones

A `Url` field makes its type an object, as any handle C cannot copy does,
so reading the value no longer consumes it. A returned `Vec<&T>`'s free
drops the clones it holds. A parameter's `Vec` refuses a reference nested
in its elements, and C++ takes an optional `Vec` of handles by value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(ffi): carry Url, SocketAddr, paths, and Vec<T> through the Kotlin export

A path is a String, which throws for one that is not UTF-8; a SocketAddr is an
InetSocketAddress, which throws for an IPv6 flow label Java does not keep; a
Vec<T> is a List, whose objects close once a call moves them in. The JNI reader
keeps each array it reads until the call returns. The api transcript uses a
UTF-8 path, which Kotlin can express, with the non-UTF-8 round trip checked
from C and Kotlin's refusal of one as a broken case; moq.kt mirrors moq.c's
foreign-type checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(ffi): close Kotlin objects moved in through a boxed Vec

Gate the close on `moved` alone, which already recurses through Box, so a
Box<Vec<T>> parameter closes each object as Option<Vec<T>> does. The api
fixture's `worth` takes Option<Box<Vec<Counter>>>, and Kotlin checks a counter
it moved in is closed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(quest): plan slices and SocketAddrV4/V6 for the exporter

The follow-ups #190 leaves: `&[T]` of any mapped type (12 refusals at the
pinned moq) and the typed socket addresses moq-tokio's listen config holds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(ffi): move objects in through a bare Box<Vec<T>> too

`worth` takes an Option<Vec<Counter>> and a Box<Vec<Counter>> apart, so the
fixture covers a boxed Vec without an Option around it, which the Kotlin close
missed before b368920.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(ffi): set a session's URL, fingerprints, and bind from C, C++, and Kotlin

With #189's setters and the foreign types mapped, `connect.url`,
`tls.fingerprint`, and `listen.bind` generate setters. moq's tests set each and
read it back, which closes field-setters' goal end to end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

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