Skip to content

[jextract] add support for throwing functions in JNI mode #277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 17, 2025

Conversation

madsodgaard
Copy link
Contributor

Adds support for generating throwing functions in JNI mode

} catch {
environment.throwAsException(error)
return Int64.jniPlaceholderValue
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

looks ok 👍


enum SwiftEffectSpecifier: Equatable {
case `throws`
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that's okey, in swift-syntax they're just as a keyword afair -- any opinion about such enum @rintaro ?

Copy link
Member

Choose a reason for hiding this comment

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

The enum look okay to me for now. We should support typed throw some day, but not now.

Copy link
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

Looks ok to me, one question Rintaro may want to chime in about our new "effect" enum here. I think it's okey though, since we just have the few limited effects we're handling, well, just the one for now, but in future maybe async

@ktoso ktoso merged commit 5c69766 into swiftlang:main Jun 17, 2025
17 checks passed
@rintaro
Copy link
Member

rintaro commented Jun 17, 2025

Looks nice!

When you enable previously-unsupported thing in SwiftFunctionSignature, I'd appreciate if you could block that in CdeclLowering.lowerFunctionSignature(_:). Otherwise FFM translation would emit malformed code.

}
case .accessors(let accessors):
if let getter = accessors.first(where: { $0.accessorSpecifier.tokenKind == .keyword(.set) }) {
effectSpecifiers = Self.effectSpecifiers(from: getter)
Copy link
Member

Choose a reason for hiding this comment

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

We should do this only if isSet is false.

switch binding.accessorBlock?.accessors {
case .getter(let getter):
if let getter = getter.as(AccessorDeclSyntax.self) {
effectSpecifiers = Self.effectSpecifiers(from: getter)
Copy link
Member

Choose a reason for hiding this comment

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

AccessorBlockSyntax.Accessors.getter can only contain CodeBlockItemListSyntax so this should be unreachable.

@rintaro
Copy link
Member

rintaro commented Jun 17, 2025

Disabling throws in FFM #280

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.

3 participants