Skip to content

perf(apple): add a consumer for successful Swift results - #1991

Open
mrousavy wants to merge 2 commits into
v1from
mrousavy/v1-swift-result-consumer
Open

mrousavy wants to merge 2 commits into
v1from
mrousavy/v1-swift-result-consumer

Conversation

@mrousavy

@mrousavy mrousavy commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Adds SwiftResultConsumer and receiveSwiftResult<T>() to Core. #1992 switches generated Swift methods over to them.

Throwing Swift methods that return a Swift value, such as a string, array or struct, go through withSwiftResult() today. It calls tryMakeSwiftValue<T>(), which returns T?, and C++ allocates a box for that swift::Optional<T> on every successful call. receiveSwiftResult() passes a consumer to the Swift call instead. Swift calls it while it still owns the value, and C++ copies the value straight into Result<T>. Swift errors still come back through the Result<void> status. If the copy throws, the consumer stores the exception in the Result, since it runs inside a Swift frame.

Generated Swift code gets the consumer as an UnsafeRawPointer, because naming the C++ record in exported Swift signatures hits swiftlang/swift#93318. The TODO points at the fix, swiftlang/swift#93321.

withSwiftResult() stays because the Swift callback adapters still use it.

The standalone iOS suite passes on this branch by itself.

🤖 Generated with Claude Code

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).
@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
nitro-docs Ready Ready Preview Oct 23, 2026 6:00pm UTC

Request Review

This branch was successfully deployed

1 active deployment
Preview — 1858da2e Deployed Oct 23, 2026 by vercel[bot]
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