Skip to content

jextract/ffm: Support throwing funcs in FFM mode#658

Merged
ktoso merged 5 commits intoswiftlang:mainfrom
ktoso:wip-ffm-errors
Mar 31, 2026
Merged

jextract/ffm: Support throwing funcs in FFM mode#658
ktoso merged 5 commits intoswiftlang:mainfrom
ktoso:wip-ffm-errors

Conversation

@ktoso
Copy link
Copy Markdown
Collaborator

@ktoso ktoso commented Mar 31, 2026

resolves long standing missing feature #34

I introduce a new Java error type that we use to "type erase" the thrown errors when Java gets them. In future we can do typed throws.

We also jextract and commit the wrapper for it so we don't have bootstrap issues, i.e. we can build without having to run jextract first: org.swift.swiftkit.ffm.generated.SwiftJavaErrorException

This is similar to the issue that wrap-java has with comitted generated wrappers in SwiftJava.

Added runtime and source gen tests

ktoso added 5 commits March 31, 2026 17:22
Fix misleading Java output path in regeneration script

The script echoed ${TYPE}.java but the generator may remap the
Java class name (e.g. SwiftJavaError -> SwiftJavaErrorException).
Print the output directory instead of guessing the filename.

cleanups

/// Wraps a Swift `any Error` value so it can be passed across the FFI boundary
/// as a reference-counted heap object
public final class SwiftJavaError {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is to avoid guessing if the struct we're throwing needs to be retained or now, we just wrap them all into this

@ktoso ktoso merged commit 75fd864 into swiftlang:main Mar 31, 2026
61 checks passed
ktoso added a commit to ktoso/swift-java that referenced this pull request Mar 31, 2026
* jextract/ffm: support throwing functions in ffm

* script to jextract parts of SwiftKit, like SwiftJavaError

* jextract/ffm: initial SwiftJavaError support in FFM mode

Fix misleading Java output path in regeneration script

The script echoed ${TYPE}.java but the generator may remap the
Java class name (e.g. SwiftJavaError -> SwiftJavaErrorException).
Print the output directory instead of guessing the filename.

cleanups

* re-run the ./scripts/swiftkit-ffm-generate-bindings.sh

* fix formatting and license
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.

1 participant