Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions SWIFT_EXPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@ For now the plugin just clones your original functions and properties to prevent
**Temporary workaround:**
You should disable any relevant code in Swift if you would like to try Swift export.

## 🚨 `@Throws` suspend functions are unsupported

Throwing suspend functions aren't supported yet.

KMP-NativeCoroutines behaves as if a `@Throws(Exception::class)` annotation was added to all suspend functions.
Since throwing suspend functions aren't supported yet, any exception will currently cause a fatal crash.

## 🚨 Cancellation isn't supported yet

At the moment you can't cancel suspend functions.
Meaning your suspend functions will keep running until they either complete or fail.

## ⚠️ `@ObjCName` is ignored

The `@ObjCName` annotation is (currently) ignored by Swift export.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ buildscript {

allprojects {
group = "com.rickclephas.kmp"
version = "1.0.0"
version = "1.0.0-kotlin-2.3.20-Beta1"
}

apiValidation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public final class com/rickclephas/kmp/nativecoroutines/compiler/config/Suffixes
public final class com/rickclephas/kmp/nativecoroutines/compiler/config/SwiftExport : java/lang/Enum {
public static final field NO_FUNC_RETURN_TYPES Lcom/rickclephas/kmp/nativecoroutines/compiler/config/SwiftExport;
public static final field NO_THROWS_SUSPEND_FUNC Lcom/rickclephas/kmp/nativecoroutines/compiler/config/SwiftExport;
public static final field SUSPEND_FUNC_SUPPORTED Lcom/rickclephas/kmp/nativecoroutines/compiler/config/SwiftExport;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcom/rickclephas/kmp/nativecoroutines/compiler/config/SwiftExport;
public static fun values ()[Lcom/rickclephas/kmp/nativecoroutines/compiler/config/SwiftExport;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public final class com/rickclephas/kmp/nativecoroutines/compiler/config/Suffixes
public final class com/rickclephas/kmp/nativecoroutines/compiler/config/SwiftExport : java/lang/Enum {
public static final field NO_FUNC_RETURN_TYPES Lcom/rickclephas/kmp/nativecoroutines/compiler/config/SwiftExport;
public static final field NO_THROWS_SUSPEND_FUNC Lcom/rickclephas/kmp/nativecoroutines/compiler/config/SwiftExport;
public static final field SUSPEND_FUNC_SUPPORTED Lcom/rickclephas/kmp/nativecoroutines/compiler/config/SwiftExport;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcom/rickclephas/kmp/nativecoroutines/compiler/config/SwiftExport;
public static fun values ()[Lcom/rickclephas/kmp/nativecoroutines/compiler/config/SwiftExport;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.jetbrains.kotlin.utils.filterToSetOrEmpty
public enum class SwiftExport {
NO_FUNC_RETURN_TYPES,
NO_THROWS_SUSPEND_FUNC,
SUSPEND_FUNC_SUPPORTED,
}

public val SWIFT_EXPORT: ConfigOptionWithDefault<Set<SwiftExport>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal fun FirExtension.buildNativeFunction(

status = originalSymbol.getGeneratedDeclarationStatus(session)
?.copy(isInline = originalSymbol.isInline) ?: return null
if (SwiftExport.NO_FUNC_RETURN_TYPES in swiftExport) {
if (SwiftExport.NO_FUNC_RETURN_TYPES in swiftExport || SwiftExport.SUSPEND_FUNC_SUPPORTED in swiftExport) {
status = status.copy(isSuspend = callableSignature.isSuspend)
}
isLocal = originalSymbol.isLocal
Expand Down Expand Up @@ -85,7 +85,7 @@ internal fun FirExtension.buildNativeFunction(
if (annotation.shouldRefineInSwift) {
annotations.add(buildAnnotation(ClassIds.shouldRefineInSwift))
}
if (SwiftExport.NO_FUNC_RETURN_TYPES in swiftExport &&
if ((SwiftExport.NO_FUNC_RETURN_TYPES in swiftExport || SwiftExport.SUSPEND_FUNC_SUPPORTED in swiftExport) &&
SwiftExport.NO_THROWS_SUSPEND_FUNC !in swiftExport &&
callableSignature.isSuspend
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal fun FirCallableSignature.getNativeType(
val typeArgs = arrayOf<ConeTypeProjection>(getRawType(type.valueType))
nativeType = ClassIds.nativeFlow.constructClassLikeType(typeArgs, type.isNullable)
}
if (isSuspend) {
if (isSuspend && SwiftExport.SUSPEND_FUNC_SUPPORTED !in swiftExport) {
val typeArgs = arrayOf<ConeTypeProjection>(nativeType)
nativeType = ClassIds.nativeSuspend.constructClassLikeType(typeArgs)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal fun GeneratorContext.buildNativeFunctionBody(
if (callableSignature.returnType is CallableSignature.Type.Flow) {
expression = irCallAsNativeFlow(expression, coroutineScope)
}
if (callableSignature.isSuspend) {
if (callableSignature.isSuspend && SwiftExport.SUSPEND_FUNC_SUPPORTED !in swiftExport) {
expression = irCallNativeSuspend(expression, coroutineScope)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,44 @@ public void testViewmodelscope() {
runTest("src/testData/codegen/swift3/viewmodelscope.kt");
}
}

@Nested
@TestMetadata("src/testData/codegen/swift5")
@TestDataPath("$PROJECT_ROOT")
public class Swift5 {
@Test
public void testAllFilesPresentInSwift5() {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("src/testData/codegen/swift5"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kt$"), true);
}

@Test
@TestMetadata("annotations.kt")
public void testAnnotations() {
runTest("src/testData/codegen/swift5/annotations.kt");
}

@Test
@TestMetadata("coroutinescope.kt")
public void testCoroutinescope() {
runTest("src/testData/codegen/swift5/coroutinescope.kt");
}

@Test
@TestMetadata("functions.kt")
public void testFunctions() {
runTest("src/testData/codegen/swift5/functions.kt");
}

@Test
@TestMetadata("properties.kt")
public void testProperties() {
runTest("src/testData/codegen/swift5/properties.kt");
}

@Test
@TestMetadata("viewmodelscope.kt")
public void testViewmodelscope() {
runTest("src/testData/codegen/swift5/viewmodelscope.kt");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,44 @@ public void testViewmodelscope() {
runTest("src/testData/codegen/swift3/viewmodelscope.kt");
}
}

@Nested
@TestMetadata("src/testData/codegen/swift5")
@TestDataPath("$PROJECT_ROOT")
public class Swift5 {
@Test
public void testAllFilesPresentInSwift5() {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("src/testData/codegen/swift5"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kt$"), true);
}

@Test
@TestMetadata("annotations.kt")
public void testAnnotations() {
runTest("src/testData/codegen/swift5/annotations.kt");
}

@Test
@TestMetadata("coroutinescope.kt")
public void testCoroutinescope() {
runTest("src/testData/codegen/swift5/coroutinescope.kt");
}

@Test
@TestMetadata("functions.kt")
public void testFunctions() {
runTest("src/testData/codegen/swift5/functions.kt");
}

@Test
@TestMetadata("properties.kt")
public void testProperties() {
runTest("src/testData/codegen/swift5/properties.kt");
}

@Test
@TestMetadata("viewmodelscope.kt")
public void testViewmodelscope() {
runTest("src/testData/codegen/swift5/viewmodelscope.kt");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ abstract class AbstractFirBaseCodegenTest(
KmpNativeCoroutinesDirectives.STATE_FLOW_SUFFIX with "Flow"
}
listOf<Long>(
0b01, // Kotlin 2.2.21
0b11, // Kotlin 2.3.0
0b001, // Kotlin 2.2.21
0b011, // Kotlin 2.3.0
0b101, // Kotlin 2.3.20
).forEach { version ->
forTestsMatching("swift$version/*") {
defaultDirectives {
Expand Down
Loading