Skip to content

Commit 0869e55

Browse files
committed
introduce async mode
1 parent 89b2bcc commit 0869e55

File tree

8 files changed

+126
-46
lines changed

8 files changed

+126
-46
lines changed

Sources/JExtractSwiftLib/SwiftTypes/SwiftEffectSpecifier.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414

1515
enum SwiftEffectSpecifier: Equatable {
1616
case `throws`
17+
case async
1718
}

Sources/JExtractSwiftLib/SwiftTypes/SwiftFunctionSignature.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ extension SwiftFunctionSignature {
246246
effectSpecifiers.append(.throws)
247247
}
248248
if let asyncSpecifier = signature.effectSpecifiers?.asyncSpecifier {
249-
throw SwiftFunctionTranslationError.async(asyncSpecifier)
249+
effectSpecifiers.append(.async)
250250
}
251251

252252
let parameters = try signature.parameterClause.parameters.map { param in
@@ -331,7 +331,7 @@ extension SwiftFunctionSignature {
331331
effectSpecifiers.append(.throws)
332332
}
333333
if let asyncSpecifier = decl.effectSpecifiers?.asyncSpecifier {
334-
throw SwiftFunctionTranslationError.async(asyncSpecifier)
334+
effectSpecifiers.append(.async)
335335
}
336336
return effectSpecifiers
337337
}

Sources/SwiftJavaConfigurationShared/Configuration.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public struct Configuration: Codable {
4646
public var effectiveUnsignedNumbersMode: JExtractUnsignedIntegerMode {
4747
unsignedNumbersMode ?? .default
4848
}
49+
4950
public var minimumInputAccessLevelMode: JExtractMinimumAccessLevelMode?
5051
public var effectiveMinimumInputAccessLevelMode: JExtractMinimumAccessLevelMode {
5152
minimumInputAccessLevelMode ?? .default
@@ -56,6 +57,11 @@ public struct Configuration: Codable {
5657
memoryManagementMode ?? .default
5758
}
5859

60+
public var asyncMode: JExtractAsyncMode?
61+
public var effectiveAsyncMode: JExtractAsyncMode {
62+
asyncMode ?? .default
63+
}
64+
5965
// ==== java 2 swift ---------------------------------------------------------
6066

6167
/// The Java class path that should be passed along to the swift-java tool.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift.org project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of Swift.org project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
/// Configures how Swift `async` functions should be extracted by jextract.
16+
public enum JExtractAsyncMode: String, Codable {
17+
/// Extract Swift `async` APIs as Java functions that return `CompletableFuture`s.
18+
case completableFuture
19+
20+
/// Extract Swift `async` APIs as Java functions that return `Future`s.
21+
///
22+
/// This mode is useful for platforms that do not have `CompletableFuture` support, such as
23+
/// Android 23 and below.
24+
///
25+
/// - Note: Prefer using the `completableFuture` mode instead, if possible.
26+
case future
27+
}
28+
29+
30+
extension JExtractAsyncMode {
31+
public static var `default`: Self {
32+
.completableFuture
33+
}
34+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift.org project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of Swift.org project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
/// Determines which source generation mode JExtract should be using: JNI or Foreign Function and Memory.
16+
public enum JExtractGenerationMode: String, Codable {
17+
/// Foreign Value and Memory API
18+
case ffm
19+
20+
/// Java Native Interface
21+
case jni
22+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift.org project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of Swift.org project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
/// Configures how memory should be managed by the user
16+
public enum JExtractMemoryManagementMode: String, Codable {
17+
/// Force users to provide an explicit `SwiftArena` to all calls that require them.
18+
case explicit
19+
20+
/// Provide both explicit `SwiftArena` support
21+
/// and a default global automatic `SwiftArena` that will deallocate memory when the GC decides to.
22+
case allowGlobalAutomatic
23+
24+
public static var `default`: Self {
25+
.explicit
26+
}
27+
28+
public var requiresGlobalArena: Bool {
29+
switch self {
30+
case .explicit: false
31+
case .allowGlobalAutomatic: true
32+
}
33+
}
34+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift.org project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of Swift.org project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
/// The minimum access level which
16+
public enum JExtractMinimumAccessLevelMode: String, Codable {
17+
case `public`
18+
case `package`
19+
case `internal`
20+
}
21+
22+
extension JExtractMinimumAccessLevelMode {
23+
public static var `default`: Self {
24+
.public
25+
}
26+
}

Sources/SwiftJavaConfigurationShared/GenerationMode.swift renamed to Sources/SwiftJavaConfigurationShared/JExtract/JExtractUnsignedIntegerMode.swift

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
/// Determines which source generation mode JExtract should be using: JNI or Foreign Function and Memory.
16-
public enum JExtractGenerationMode: String, Codable {
17-
/// Foreign Value and Memory API
18-
case ffm
19-
20-
/// Java Native Interface
21-
case jni
22-
}
23-
2415
/// Configures how Swift unsigned integers should be extracted by jextract.
2516
public enum JExtractUnsignedIntegerMode: String, Codable {
2617
/// Treat unsigned Swift integers as their signed equivalents in Java signatures,
@@ -51,6 +42,7 @@ public enum JExtractUnsignedIntegerMode: String, Codable {
5142
// case widenOrAnnotate
5243
}
5344

45+
5446
extension JExtractUnsignedIntegerMode {
5547
public var needsConversion: Bool {
5648
switch self {
@@ -63,38 +55,3 @@ extension JExtractUnsignedIntegerMode {
6355
.annotate
6456
}
6557
}
66-
67-
/// The minimum access level which
68-
public enum JExtractMinimumAccessLevelMode: String, Codable {
69-
case `public`
70-
case `package`
71-
case `internal`
72-
}
73-
74-
extension JExtractMinimumAccessLevelMode {
75-
public static var `default`: Self {
76-
.public
77-
}
78-
}
79-
80-
81-
/// Configures how memory should be managed by the user
82-
public enum JExtractMemoryManagementMode: String, Codable {
83-
/// Force users to provide an explicit `SwiftArena` to all calls that require them.
84-
case explicit
85-
86-
/// Provide both explicit `SwiftArena` support
87-
/// and a default global automatic `SwiftArena` that will deallocate memory when the GC decides to.
88-
case allowGlobalAutomatic
89-
90-
public static var `default`: Self {
91-
.explicit
92-
}
93-
94-
public var requiresGlobalArena: Bool {
95-
switch self {
96-
case .explicit: false
97-
case .allowGlobalAutomatic: true
98-
}
99-
}
100-
}

0 commit comments

Comments
 (0)