Skip to content

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

Merged
ktoso merged 2 commits into
swiftlang:mainfrom
madsodgaard:jextract-jni-throwing
Jun 17, 2025
Merged

[jextract] add support for throwing functions in JNI mode#277
ktoso merged 2 commits into
swiftlang:mainfrom
madsodgaard:jextract-jni-throwing

Conversation

@madsodgaard
Copy link
Copy Markdown
Contributor

Adds support for generating throwing functions in JNI mode

Comment thread Sources/JExtractSwiftLib/SwiftTypes/SwiftFunctionSignature.swift Outdated
} catch {
environment.throwAsException(error)
return Int64.jniPlaceholderValue
}
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.

looks ok 👍


enum SwiftEffectSpecifier: Equatable {
case `throws`
}
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 think that's okey, in swift-syntax they're just as a keyword afair -- any opinion about such enum @rintaro ?

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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