Skip to content

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

Merged
mrousavy merged 1 commit into
v1from
mrousavy/v1-swift-result-consumer
Nov 2, 2026
Merged

mrousavy merged 1 commit 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>(); #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 boxed swift::Optional<T> returned by tryMakeSwiftValue<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.

@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
nitro-docs Skipped Skipped Nov 2, 2026 11:39am UTC

Request Review

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
mrousavy force-pushed the mrousavy/v1-swift-result-consumer branch from 1858da2 to ff5b820 Compare November 2, 2026 11:39
@mrousavy
mrousavy added this pull request to stack #2030 November 2, 2026 11:39
@mrousavy
mrousavy merged commit 8f1bac2 into v1 Nov 2, 2026
11 of 16 checks passed

This branch was previously deployed

1 inactive deployment
Preview — ff5b8200 Deployed Nov 2, 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