Skip to content

JNI: preserve MainActor isolation in synchronous thunks - #940

Closed
piercifani wants to merge 1 commit into
swiftlang:mainfrom
skiptools:upstream/pr-938
Closed

piercifani wants to merge 1 commit into
swiftlang:mainfrom
skiptools:upstream/pr-938

Conversation

@piercifani

Copy link
Copy Markdown

Synchronous MainActor APIs currently produce nonisolated JNI entry points, so their generated bindings fail to compile when calling isolated Swift initializers or members.

Annotate these entry points with MainActor and check the caller's executor before converting arguments or accessing Swift state. Keep the Java API synchronous, preserve isolation through generic openers, and leave nonisolated members and asynchronous downcalls on their existing paths. Isolating the thunk itself also supports reference-valued JNI results in Swift 6 without requiring JNI pointers to conform to Sendable.

Add regression tests, JNI sample compilation fixtures, and documentation of the executor requirement for Java callers. Verify the regressions against the original generator, run the full Swift and JNI sample test suites, and compile the fixtures in Swift 6 language mode.

Synchronous MainActor APIs currently produce nonisolated JNI entry points,
so their generated bindings fail to compile when calling isolated Swift
initializers or members.

Annotate these entry points with MainActor and check the caller's executor
before converting arguments or accessing Swift state. Keep the Java API
synchronous, preserve isolation through generic openers, and leave
nonisolated members and asynchronous downcalls on their existing paths.
Isolating the thunk itself also supports reference-valued JNI results in
Swift 6 without requiring JNI pointers to conform to Sendable.

Add regression tests, JNI sample compilation fixtures, and documentation
of the executor requirement for Java callers. Verify the regressions
against the original generator, run the full Swift and JNI sample test
suites, and compile the fixtures in Swift 6 language mode.
@piercifani
piercifani requested a review from ktoso as a code owner November 3, 2026 15:22
@piercifani piercifani closed this Nov 3, 2026
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.

2 participants