Skip to content

jextract: support Swift custom operators#829

Draft
AbdAlRahmanGad wants to merge 12 commits into
swiftlang:mainfrom
AbdAlRahmanGad:operators
Draft

jextract: support Swift custom operators#829
AbdAlRahmanGad wants to merge 12 commits into
swiftlang:mainfrom
AbdAlRahmanGad:operators

Conversation

@AbdAlRahmanGad

Copy link
Copy Markdown
Member

Comment thread Sources/SwiftExtract/SwiftAnalysisVisitor.swift
Comment thread Sources/JExtractSwiftLib/JavaIdentifierFactory.swift
}
private var deferredConstrainedExtensions: [DeferredConstrainedExtension] = []

private static func isOperatorFunction(_ node: FunctionDeclSyntax) -> Bool {

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.

This may be worth changing into operatorKind: SwiftOperatorKind?`

and make a new SwiftOperatorKind that is enum SwiftOperatorKind { case prefixOperator; case binaryOperator; case postfixOperator }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I ended up not adding the new enum beacause it didn't really fit in and didn't simplify the code

Comment thread Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift Outdated
Comment thread Sources/JExtractSwiftLib/JavaIdentifierFactory.swift
Comment thread Tests/JExtractSwiftTests/JNI/JNIOperatorsTests.swift
Comment thread Tests/SwiftExtractTests/AnalysisResultTests.swift Outdated
public func Java_com_example_swift_Number__00024plus__JJ(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, left: jlong, right: jlong) -> jlong {
...
let result$ = UnsafeMutablePointer<Number>.allocate(capacity: 1)
result$.initialize(to: ( ((left$.pointee) + (right$.pointee)))

@ktoso ktoso Jul 16, 2026

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.

Suggested change
result$.initialize(to: ( ((left$.pointee) + (right$.pointee)))
result$.initialize(to: ((left$.pointee) + (right$.pointee)))

do we have an unbalanced () here? Is the sourcegen wrong or the test wrongly asserted that

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ah, so it turns out I added it in the codegen step code but now it's balanced!

Comment thread Sources/JExtractSwiftLib/JavaIdentifierFactory.swift
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