Skip to content

jextract: Translate Swift () -> () to java Runnable#820

Open
AmrDeveloper wants to merge 5 commits into
swiftlang:mainfrom
AmrDeveloper:jextract_runnable
Open

jextract: Translate Swift () -> () to java Runnable#820
AmrDeveloper wants to merge 5 commits into
swiftlang:mainfrom
AmrDeveloper:jextract_runnable

Conversation

@AmrDeveloper

Copy link
Copy Markdown

Translate the Swift function parameter type () -> () to the Java Runnable interface

Issue: #811

@AmrDeveloper AmrDeveloper requested a review from ktoso as a code owner July 7, 2026 17:54
@ktoso

ktoso commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

So this only does the FFM mode, could you also please do the JNI mode?

Then also please make sure we have a runtime test -- i.e. a test in Samples/SwiftJavaExtractJNISampleApp/Sources/MySwiftLibrary and Samples/SwiftJavaExtractJNISampleApp/src/test/java/com/example/swift that covers this so we didn't regress anythign and run end to end?

methodName: String,
) -> TranslatedParameter {
let parameterType =
if functionType.parameters.count == 0 && functionType.resultType.isVoid {

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.

Can you extract this into some extractKnownJavaFunctionalInterfaceType(functionType)

it should return a JavaType? and if we get nil there we do the below branch.

There we'll also handle the other known types then, like supplier etc

@ktoso

ktoso commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Yeah samples broke:


/__w/swift-java/swift-java/Samples/SwiftAndJavaJarFFMSampleLib/.build/plugins/outputs/swiftandjavajarffmsamplelib/MySwiftLibrary/destination/JExtractSwiftPlugin/src/generated/java/com/example/swift/MySwiftLibrary.java:240: error: incompatible types: Runnable cannot be converted to run
      swiftjava_MySwiftLibrary_globalCallMeRunnable_run.call(globalCallMeRunnable.$toUpcallStub(run, arena$));
                                                                                                ^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error

You can run them by


  cd Samples/SwiftAndJavaJarFFMSampleLib
  ./ci-validate.sh

@AmrDeveloper

Copy link
Copy Markdown
Author

So this only does the FFM mode, could you also please do the JNI mode?

Then also please make sure we have a runtime test -- i.e. a test in Samples/SwiftJavaExtractJNISampleApp/Sources/MySwiftLibrary and Samples/SwiftJavaExtractJNISampleApp/src/test/java/com/example/swift that covers this so we didn't regress anythign and run end to end?

I think we already have a test for Closures

public func emptyClosure(closure: () -> Void) {

https://github.com/swiftlang/swift-java/blob/main/Samples/SwiftJavaExtractJNISampleApp/src/test/java/com/example/swift/ClosuresTest.java

$0.conversion.render(&printer, $0.parameters.first!.name)
}

let methodName =

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I am still thinking of having a map to hold all names for functional interfaces 🤔

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