-
Notifications
You must be signed in to change notification settings - Fork 99
implemented tuple support for ffm #632
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
ktoso
merged 6 commits into
swiftlang:main
from
amanthatdoescares:fix/jextract-ffm-tuples
Mar 19, 2026
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4efa302
implemented tuple support for ffm
amanthatdoescares 526bbce
fix the format
amanthatdoescares 886beb9
implied the suggestions
amanthatdoescares d29b03a
added a runtime test and fixed the format
amanthatdoescares 8cac265
change one of the tuples to mix types
ktoso a3d5068
mark tuples as supported in feature list
ktoso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift.org open source project | ||
| // | ||
| // Copyright (c) 2025 Apple Inc. and the Swift.org project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of Swift.org project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import JExtractSwiftLib | ||
| import Testing | ||
|
|
||
| /// FFM tuple binding tests, aligned with `JNITupleTests` where lowering allows it. | ||
| /// | ||
| /// JNI uses `(Int64, String)` for `returnPair` / `takePair`; FFM `lowerResult` does not support | ||
| /// `String` in tuple results yet, so those signatures use `(Int64, Int64)` here. | ||
|
amanthatdoescares marked this conversation as resolved.
Outdated
|
||
| @Suite | ||
| struct FFMTupleTests { | ||
| let source = """ | ||
| public func returnPair() -> (Int64, Int64) | ||
| public func takePair(_ arg: (Int64, Int64)) | ||
| public func labeledTuple() -> (x: Int32, y: Int32) | ||
| """ | ||
|
|
||
| @Test | ||
| func returnPair_javaBindings() throws { | ||
| try assertOutput( | ||
| input: source, | ||
| .ffm, | ||
| .java, | ||
| expectedChunks: [ | ||
| """ | ||
| public static org.swift.swiftkit.core.tuple.Tuple2<Long, Long> returnPair() { | ||
| try(var arena$ = Arena.ofConfined()) { | ||
| MemorySegment _result_0 = arena$.allocate(SwiftValueLayout.SWIFT_INT64); | ||
| MemorySegment _result_1 = arena$.allocate(SwiftValueLayout.SWIFT_INT64); | ||
| swiftjava_SwiftModule_returnPair.call(_result_0, _result_1); | ||
| return new org.swift.swiftkit.core.tuple.Tuple2<>(_result_0.get(SwiftValueLayout.SWIFT_INT64, 0), _result_1.get(SwiftValueLayout.SWIFT_INT64, 0)); | ||
| } | ||
| } | ||
| """, | ||
| ] | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| func takePair_javaBindings() throws { | ||
| try assertOutput( | ||
| input: source, | ||
| .ffm, | ||
| .java, | ||
| detectChunkByInitialLines: 2, | ||
| expectedChunks: [ | ||
| """ | ||
| public static void takePair(org.swift.swiftkit.core.tuple.Tuple2<Long, Long> arg) { | ||
| swiftjava_SwiftModule_takePair__.call(arg.$0, arg.$1); | ||
| } | ||
| """, | ||
| ] | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| func labeledTuple_javaBindings() throws { | ||
| try assertOutput( | ||
| input: source, | ||
| .ffm, | ||
| .java, | ||
| expectedChunks: [ | ||
| """ | ||
| public static org.swift.swiftkit.core.tuple.Tuple2<Integer, Integer> labeledTuple() { | ||
| """, | ||
| """ | ||
| return new org.swift.swiftkit.core.tuple.Tuple2<>(_result_0.get(SwiftValueLayout.SWIFT_INT32, 0), _result_1.get(SwiftValueLayout.SWIFT_INT32, 0)); | ||
| """, | ||
| ] | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| func returnPair_swiftThunks() throws { | ||
| try assertOutput( | ||
| input: source, | ||
| .ffm, | ||
| .swift, | ||
| detectChunkByInitialLines: 1, | ||
| expectedChunks: [ | ||
| """ | ||
|
amanthatdoescares marked this conversation as resolved.
|
||
| let _result = returnPair() | ||
| _result_0.initialize(to: _result.0) | ||
| _result_1.initialize(to: _result.1) | ||
| """, | ||
| ] | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| func takePair_swiftThunks() throws { | ||
| try assertOutput( | ||
| input: source, | ||
| .ffm, | ||
| .swift, | ||
| detectChunkByInitialLines: 1, | ||
| expectedChunks: [ | ||
| """ | ||
| takePair((arg_0, arg_1)) | ||
| """, | ||
| ] | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| func labeledTuple_swiftThunks() throws { | ||
| try assertOutput( | ||
| input: source, | ||
| .ffm, | ||
| .swift, | ||
| detectChunkByInitialLines: 1, | ||
| expectedChunks: [ | ||
| """ | ||
| let _result = labeledTuple() | ||
| _result_0.initialize(to: _result.0) | ||
| _result_1.initialize(to: _result.1) | ||
| """, | ||
| ] | ||
| ) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.