Repository navigation
JNI: preserve MainActor isolation in synchronous thunks - #940
Closed
piercifani wants to merge 1 commit into
Closed
piercifani wants to merge 1 commit into
piercifani wants to merge 1 commit into
Conversation
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.
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.
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.