Skip to content

feat(ffm): add support for async Swift functions via CompletableFuture - #870

Open
amanmaurya92 wants to merge 4 commits into
swiftlang:mainfrom
amanmaurya92:feature/issue-392
Open

feat(ffm): add support for async Swift functions via CompletableFuture#870
amanmaurya92 wants to merge 4 commits into
swiftlang:mainfrom
amanmaurya92:feature/issue-392

Conversation

@amanmaurya92

Copy link
Copy Markdown
Contributor

Title:

feat(ffm): add support for async Swift functions via CompletableFuture

Description:

Resolves #392.

This PR adds Foreign Function & Memory (FFM) API support for Swift async functions, bridging them to Java's CompletableFuture (achieving parity with the existing JNI implementation).

Key Changes:

  • C-Decl Lowering: Modified function lowering to map Swift async function returns to Void in the C declaration, and appended async$completion and async$error callback pointers for asynchronous resolution.
  • Java Translation & Bindings: Upgraded the return type of async functions in Java from their raw mapped type to CompletableFuture<T>. When the downcall is invoked, it allocates MemorySegments for the upcalls and resolves the CompletableFuture from within the C callback stubs.
  • Swift Thunks: Thunks for async functions now spawn a Task to call the original Swift async function, bridging the execution context from the synchronous C call. The C callback pointers are invoked upon Task completion.

Testing:

  • Added/verified the async function test cases in JExtractSwiftTests ensuring the C/Java layout and lowering logic functions correctly for FFM. (All 500 FFM code generation tests pass successfully).

@amanmaurya92
amanmaurya92 marked this pull request as ready for review August 7, 2026 10:16
@amanmaurya92
amanmaurya92 requested a review from ktoso as a code owner August 7, 2026 10:16

@ktoso ktoso left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please include a runtime test in the Samples/FFM sample, we must have runtime testing of new substantial functionality.

@ktoso

ktoso commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Uhm, this doesn't even add any tests -- please add tests asserting the shape of generated thunks.

We don't mind AI generated contributions, which this really seems like, but please make sure the quality of contributions is higher -- you must include tests, both source and runtime. Look at other PRs how new features are introduced please.

@ktoso ktoso left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please include tests as well as update documentation for the supported feature list in docs.

Comment thread .agents/workflows/review-swift-java-pr.md Outdated
@amanmaurya92
amanmaurya92 requested a review from ktoso August 10, 2026 09:40
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.

jextract: should handle asynchronous swift functions

2 participants