Skip to content

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

Merged
ktoso merged 5 commits into
swiftlang:mainfrom
AmrDeveloper:jextract_runnable
Jul 13, 2026
Merged

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

Conversation

@AmrDeveloper

Copy link
Copy Markdown
Contributor

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?

Comment thread Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator+JavaTranslation.swift Outdated
@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
Contributor 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
Contributor 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 🤔

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.

Let's make a file with KnownFunctionalInterfaces.swift and cases on there; they should all have case ...(JavaType, method: ...) since they all have a single method and then we can take the name off off that

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.

I'd really welcome a follow up PR fixing this up so it's less random method names in here like that

CountDownLatch countDownLatch = new CountDownLatch(3);

MySwiftLibrary.globalCallMeRunnable(new MySwiftLibrary.globalCallMeRunnable.run() {
MySwiftLibrary.globalCallMeRunnable(new java.lang.Runnable() {

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.

Good Yeap!

@ktoso ktoso merged commit ce047be into swiftlang:main Jul 13, 2026
42 checks passed
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