Skip to content

Fix async JNI strict concurrency#730

Open
nerzh wants to merge 1 commit intoswiftlang:mainfrom
nerzh:fix/variables-strict-concurrency
Open

Fix async JNI strict concurrency#730
nerzh wants to merge 1 commit intoswiftlang:mainfrom
nerzh:fix/variables-strict-concurrency

Conversation

@nerzh
Copy link
Copy Markdown

@nerzh nerzh commented May 2, 2026

Problem found:

Swift Java generated JNI wrappers for async Swift functions no longer compile with newer Swift strict concurrency checks. The generated Task closures capture JNI values and temporary Swift conversion values that are not Sendable, so Swift reports data-race risk errors during compilation.

How it was fixed:

I added an unchecked Sendable wrapper for values that must cross into the generated async Task body. The generator now tracks, structurally, which temporary values are created during JNI-to-Swift parameter conversion and wraps only those values before creating the task. Inside the task, the original values are restored from the wrapper and used as before.

This avoids fragile string parsing of generated Swift code and keeps the fix limited to async JNI generation. Existing async JNI tests were updated to match the new generated output.

@nerzh nerzh requested a review from ktoso as a code owner May 2, 2026 10:48
@ktoso
Copy link
Copy Markdown
Collaborator

ktoso commented May 4, 2026

Hi thanks for the PR, I’m on holiday so unable to review deeply here this week.

im worried about unsafe wrappers like this, and would like to explore other options

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