Repository navigation
perf(apple): add a consumer for successful Swift results - #1991
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Add SwiftResultConsumer and receiveSwiftResult(). Swift lends a successful value to the consumer, which copies it straight into Result<T>, so the value does not have to come back to C++ in a boxed swift::Optional<T>. Generated Swift code receives the consumer as a raw pointer until our minimum Xcode includes swiftlang/swift#93321 (fixes swiftlang/swift#93318).
mrousavy
force-pushed
the
mrousavy/v1-swift-result-consumer
branch
from
November 2, 2026 11:39
1858da2 to
ff5b820
Compare
This branch was previously deployed
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.
Adds
SwiftResultConsumerandreceiveSwiftResult<T>(); #1992 uses them in generated throwing Swift methods.Swift lends a successful value synchronously, and C++ copies it into
Result<T>before the borrow ends. This avoids the outer boxedswift::Optional<T>returned bytryMakeSwiftValue<T>(). Swift errors still return through the status, and the consumer catches C++ copy errors inside the Swift frame.This still copies or retains the payload. Generic wrapper moves can fall back to copies, so the complete result path is not allocation-free for every type.
withSwiftResult()remains for existing callback adapters.The relevant upstream allocation improvement is swiftlang/swift#92970, which is still open. The opaque consumer pointer separately works around #93318, with the removal condition linked to #93321 in the source.
Validation after rebasing: the real-header helper probes passed for value lifetime, nil/some optionals, error status and the debug guard, including C++ ASan/UBSan. The stacked iOS runtime suite passed with 25 tests passed, zero failures and one skipped.