Repository navigation
Conversation
Quest-Claim: 48cd11df7931dbd8
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…copyable handles Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adapts #678's lent returns and inout to noncopyable structs: Option<&T> becomes an overload per optional borrowed parameter, and Option<&mut T> becomes inout T?. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ds differ in name moq's Source::follow takes two Option<&T>, whose overloads leaving out either were both follow(_:). Each present one is now labelled by its name, as a defaulted argument is: clamped(), clamped(low:), clamped(high:), clamped(low:high:). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the item's span The driver now asks the Swift generator which functions take more optional borrowed objects than its overloads cover, and refuses each at its span before any language is generated, as AGENTS.md requires of an unsupported construct. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…efuse an error holding one at its span A list or option holding a struct beside a moved class closed the class through for-in and if-let, which consume a noncopyable value: it now loops over indices and borrows through Native.option. A function whose error holds a struct is refused at its span with the bound, before any language is generated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Claims quest/m1/ffi-export/swift-noncopyable.md.
Summary
rust2-ffi's Swift generator now emits each object that is not
Copyand not thrown as an error as a~Copyablestruct that owns its handle and frees it indeinit. Swift's compiler now checks each move and borrow Rust makes:self,&self,&mut selfand&mut Tbecomeconsuming,borrowing,mutatingandinout.@frozenstruct, such asTupleStringCounter, with fields_0,_1, and so on.UniqueArray.Option<&T>of a handle becomes one overload with the parameter and one without, each present parameter labelled by its name:clamped(),clamped(low:),clamped(high:),clamped(low:high:). More than two per function is a compile error at the item's span, which the driver emits before any language is generated (ffi/fixtures/reject'samong).Option<&mut T>becomesinout T?.Copyobjects and errors) keep it.#if compiler(>=6.4), a struct withPartialEqconforms toEquatable.ffi/tests/api.swiftnow has four compile-fail cases: moved, boxed moved, lent moved and lent kept.ffi/tests/fixtures.rsbuilds each case with-D<CASE>and checks swiftc's diagnostic. The rest of the script still matches the native transcript.just ffi moq-swiftpasses with moq's Swift adapted. Locally, that run also needed #693's flacmd5exclusion, because main's pinned moq fails without it (see Waiting).Public API impact and migration
This breaks every generated Swift handle type and every signature that takes one:
&mut selfmethod on withvar, notlet. Pass&mut Tas&x.ffi/moq/moq.swift'sHeldandSlotdo."\(x)"anddebug(x)becomex.descriptionandx.debugDescription, because Swift 6.3 conforms no noncopyable type toCustomStringConvertible.UniqueArray<T>. A tuple holding one is aTupleABstruct: readt._0, or destructure withlet a = t._0; let b = t._1.f(x)with anOption<&T>becomesf(name: x), orf()forNone.BasicContainersfrom swift-collections 1.7.5, so a consumer must build and link it.just ffi swift-collectionsbuilds the static libraries from a pinned rev.Hold count benchmark
Release library,
-O, median of 5 interleaved runs, on a loaded host (load average 28.7 on 24 cores):get()The gain is confirmed, so the hold count is dropped.
Choices made without asking
_0,_1: matches Rust's.0, and a leading_keeps0a valid identifier.&Tbecomes a struct over the borrowed handle, and the struct ends withdiscard selfafter the call, so Swift never frees a handle Rust still owns. A lent&mut Ttraps with "a lent handle was replaced" if the closure assigned a new value over it, which Rust cannot express. The maintainer chose the trap over generating an assign through C, since no moq item needs it.import BasicContainers: a conditional import would make the module's shape depend on which types it exports.swiftc, not Nix. macOS CI runs without Nix, so both platforms use the same path.Option<&T>bound is 2, refused at the item's span through a Swift-only check the driver runs, rather than in collect for every language, where an optional borrow needs no overloads. moq'sSource::followtakes two.follow(rel)andfollow(instance)were bothfollow(_:).Equatableunder 6.4: objects export no hash, and the Swift 6.4 snapshot does not yet conform a noncopyable type to eitherCustom*StringConvertible, despite SE-0499.@frozentuple structs, so that another module can move each element out.Gaps
The Swift generator's other refusals are still messages without a span, out of this PR's scope:
claim,ffi/src/swift.rs);claim);distinct).The two refusals this PR adds, more optional borrowed objects than the bound and an error holding an object Swift cannot copy, are spanned (
ffi/fixtures/reject'samongandwrapped).Waiting
Optional<~Copyable>back-deploy and swift-collections at the macOS 13 target. The nightly's macOS job runsjust ffi moq-cppbefore its Swift step, and that export fails on main's pinned moq (mux::codec::flac::Config::md5,[u8; 16]) until moq-dev/rust2#693 lands. Once it does, merge main here and rungh workflow run nightly.yml --ref quest/m1/ffi-export/swift-noncopyable.Models
(Written by Opus 5.5 with high)
🤖 Generated with Claude Code
Review
Rewritten by
quest reviewafter each round.01a1c773-b96a-74f2-a925-35a624061367, round 2Inspection of the incremental changes confirms both fixes and reveals no new blocking issues; builds and tests were not run.ffi/src/swift.rs:290:Borrow mixed UniqueArray elements during handle cleanup;ffi/src/swift.rs:1073 now borrows noncopyable option contents through Native.option and indexes UniqueArray elements during cleanup, with regression coverage in ffi/tests/api.swift:551.ffi/src/swift.rs:1379:Emit noncopyable-error refusals with the function's source span;The refusals() pass now reports noncopyable errors at function.span before generation, removes the unspanned generator error, and covers wrapped in ffi/fixtures/reject/expected.txt.