From 647a90720460c3e67e359ebb74cf3103d6f45a46 Mon Sep 17 00:00:00 2001 From: Vladimir Sukharev Date: Wed, 17 Jan 2024 19:18:38 +0100 Subject: [PATCH] [K/N][Tests] Migrate kt48816 tests ^KT-61259 --- .../cinterop/objc/kt48816_lazy_ir_disable.kt | 78 +++++++++++++++++++ .../cinterop/objc/kt48816_lazy_ir_enable.kt | 28 ++++++- .../box/cinterop/threadStates/callback.kt | 1 - .../threadStates/callbackOnSeparateThread.kt | 1 - .../threadStates/callbackWithException.kt | 1 - .../threadStates/callbackWithFinally.kt | 1 - .../callbackWithFinallyNoCatch.kt | 1 - .../threadStates/directStaticCFunctionCall.kt | 1 - .../box/cinterop/threadStates/nativeCall.kt | 1 - .../nestedCallbackWithException.kt | 1 - .../threadStates/nestedCallbackWithFinally.kt | 1 - .../box/cinterop/threadStates/nestedCalls.kt | 1 - .../backend.native/tests/build.gradle | 19 ----- .../tests/interop/objc/kt48816/objclib.def | 2 - .../tests/interop/objc/kt48816/objclib.h | 9 --- .../FirNativeCodegenBoxTestGenerated.java | 12 +++ .../FirNativeCodegenBoxTestNoPLGenerated.java | 12 +++ .../NativeCodegenBoxTestGenerated.java | 12 +++ .../NativeCodegenBoxTestNoPLGenerated.java | 12 +++ .../support/group/ExtTestCaseGroupProvider.kt | 2 + 20 files changed, 155 insertions(+), 41 deletions(-) create mode 100644 compiler/testData/codegen/box/cinterop/objc/kt48816_lazy_ir_disable.kt rename kotlin-native/backend.native/tests/interop/objc/kt48816/main.kt => compiler/testData/codegen/box/cinterop/objc/kt48816_lazy_ir_enable.kt (63%) delete mode 100644 kotlin-native/backend.native/tests/interop/objc/kt48816/objclib.def delete mode 100644 kotlin-native/backend.native/tests/interop/objc/kt48816/objclib.h diff --git a/compiler/testData/codegen/box/cinterop/objc/kt48816_lazy_ir_disable.kt b/compiler/testData/codegen/box/cinterop/objc/kt48816_lazy_ir_disable.kt new file mode 100644 index 00000000000..439d50538d2 --- /dev/null +++ b/compiler/testData/codegen/box/cinterop/objc/kt48816_lazy_ir_disable.kt @@ -0,0 +1,78 @@ +// TARGET_BACKEND: NATIVE +// DISABLE_NATIVE: isAppleTarget=false +// Without a fix, fails in two-stage mode. +// The bug was accidentally fixed with lazy IR for caches, so testing it with this feature disabled: +// FREE_COMPILER_ARGS: -Xlazy-ir-for-caches=disable + +// MODULE: cinterop +// FILE: objclib.def +language = Objective-C +headers = objclib.h +headerFilter = objclib.h **/NSObject.h **/NSDate.h **/NSUUID.h + +// FILE: objclib.h +#import +#import +#import + +@interface MyClass1 : NSObject +@end + +@interface MyClass2 : NSObject +@end + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) +import kotlin.reflect.* +import kotlin.test.* +import objclib.* + +// https://youtrack.jetbrains.com/issue/KT-48816 +open class Base { + operator fun KProperty1.getValue(ref: Base, property: KProperty<*>): NSUUID? { + return null + } + operator fun KProperty1.getValue(ref: Base, property: KProperty<*>): NSDate? { + return null + } +} +class Usage: Base() +class B + +// The compilation should fail with the above; +// but anyway try to actually use the code, just to ensure it doesn't get DCEd: + +val B.uuid: NSUUID get() = fail() +val B.date: NSDate get() = fail() + +fun test1() { + val uuidProperty = B::uuid + val dateProperty = B::date + val usage = Usage() + with(usage) { + assertNull(uuidProperty.getValue(usage, uuidProperty)) + assertNull(dateProperty.getValue(usage, dateProperty)) + } +} + +// One more reproducer, just in case: +class Property + +open class Base2 { + fun getValue(property: Property) = null + fun getValue(property: Property) = null +} +class Usage2 : Base2() + +fun test2() { + val usage = Usage2() + assertNull(usage.getValue(Property())) + assertNull(usage.getValue(Property())) +} + +fun box(): String { + test1() + test2() + return "OK" +} \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/objc/kt48816/main.kt b/compiler/testData/codegen/box/cinterop/objc/kt48816_lazy_ir_enable.kt similarity index 63% rename from kotlin-native/backend.native/tests/interop/objc/kt48816/main.kt rename to compiler/testData/codegen/box/cinterop/objc/kt48816_lazy_ir_enable.kt index 3d97bf3750b..451975cbce3 100644 --- a/kotlin-native/backend.native/tests/interop/objc/kt48816/main.kt +++ b/compiler/testData/codegen/box/cinterop/objc/kt48816_lazy_ir_enable.kt @@ -1,3 +1,28 @@ +// TARGET_BACKEND: NATIVE +// DISABLE_NATIVE: isAppleTarget=false +// The bug was accidentally fixed with lazy IR for caches, so testing it with this feature enabled, and disabled(in other test file): +// FREE_COMPILER_ARGS: -Xlazy-ir-for-caches=enable + +// MODULE: cinterop +// FILE: objclib.def +language = Objective-C +headers = objclib.h +headerFilter = objclib.h **/NSObject.h **/NSDate.h **/NSUUID.h + +// FILE: objclib.h +#import +#import +#import + +@interface MyClass1 : NSObject +@end + +@interface MyClass2 : NSObject +@end + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) import kotlin.reflect.* import kotlin.test.* import objclib.* @@ -45,7 +70,8 @@ fun test2() { assertNull(usage.getValue(Property())) } -fun main() { +fun box(): String { test1() test2() + return "OK" } \ No newline at end of file diff --git a/compiler/testData/codegen/box/cinterop/threadStates/callback.kt b/compiler/testData/codegen/box/cinterop/threadStates/callback.kt index 62d6f28dbf2..0dd466b2240 100644 --- a/compiler/testData/codegen/box/cinterop/threadStates/callback.kt +++ b/compiler/testData/codegen/box/cinterop/threadStates/callback.kt @@ -4,7 +4,6 @@ */ // TARGET_BACKEND: NATIVE // NATIVE_STANDALONE -// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative // MODULE: cinterop // FILE: threadStates.def language = C diff --git a/compiler/testData/codegen/box/cinterop/threadStates/callbackOnSeparateThread.kt b/compiler/testData/codegen/box/cinterop/threadStates/callbackOnSeparateThread.kt index ad638763e4b..77755f7f5ad 100644 --- a/compiler/testData/codegen/box/cinterop/threadStates/callbackOnSeparateThread.kt +++ b/compiler/testData/codegen/box/cinterop/threadStates/callbackOnSeparateThread.kt @@ -4,7 +4,6 @@ */ // TARGET_BACKEND: NATIVE // NATIVE_STANDALONE -// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative // MODULE: cinterop // FILE: threadStates.def language = C diff --git a/compiler/testData/codegen/box/cinterop/threadStates/callbackWithException.kt b/compiler/testData/codegen/box/cinterop/threadStates/callbackWithException.kt index a3bd3d68cbf..a68a5948f97 100644 --- a/compiler/testData/codegen/box/cinterop/threadStates/callbackWithException.kt +++ b/compiler/testData/codegen/box/cinterop/threadStates/callbackWithException.kt @@ -4,7 +4,6 @@ */ // TARGET_BACKEND: NATIVE // NATIVE_STANDALONE -// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative // MODULE: cinterop // FILE: threadStates.def language = C diff --git a/compiler/testData/codegen/box/cinterop/threadStates/callbackWithFinally.kt b/compiler/testData/codegen/box/cinterop/threadStates/callbackWithFinally.kt index 48a445c3e8d..c8c7e6a1541 100644 --- a/compiler/testData/codegen/box/cinterop/threadStates/callbackWithFinally.kt +++ b/compiler/testData/codegen/box/cinterop/threadStates/callbackWithFinally.kt @@ -4,7 +4,6 @@ */ // TARGET_BACKEND: NATIVE // NATIVE_STANDALONE -// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative // MODULE: cinterop // FILE: threadStates.def language = C diff --git a/compiler/testData/codegen/box/cinterop/threadStates/callbackWithFinallyNoCatch.kt b/compiler/testData/codegen/box/cinterop/threadStates/callbackWithFinallyNoCatch.kt index 4c221e9781e..53b602f1dce 100644 --- a/compiler/testData/codegen/box/cinterop/threadStates/callbackWithFinallyNoCatch.kt +++ b/compiler/testData/codegen/box/cinterop/threadStates/callbackWithFinallyNoCatch.kt @@ -4,7 +4,6 @@ */ // TARGET_BACKEND: NATIVE // NATIVE_STANDALONE -// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative // MODULE: cinterop // FILE: threadStates.def language = C diff --git a/compiler/testData/codegen/box/cinterop/threadStates/directStaticCFunctionCall.kt b/compiler/testData/codegen/box/cinterop/threadStates/directStaticCFunctionCall.kt index 8bd33aa792c..964dfa9fe20 100644 --- a/compiler/testData/codegen/box/cinterop/threadStates/directStaticCFunctionCall.kt +++ b/compiler/testData/codegen/box/cinterop/threadStates/directStaticCFunctionCall.kt @@ -4,7 +4,6 @@ */ // TARGET_BACKEND: NATIVE // NATIVE_STANDALONE -// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative @file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class, kotlinx.cinterop.ExperimentalForeignApi::class) import kotlin.native.runtime.Debugging diff --git a/compiler/testData/codegen/box/cinterop/threadStates/nativeCall.kt b/compiler/testData/codegen/box/cinterop/threadStates/nativeCall.kt index 847cea2b291..7ba75e8d49c 100644 --- a/compiler/testData/codegen/box/cinterop/threadStates/nativeCall.kt +++ b/compiler/testData/codegen/box/cinterop/threadStates/nativeCall.kt @@ -4,7 +4,6 @@ */ // TARGET_BACKEND: NATIVE // NATIVE_STANDALONE -// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative // MODULE: cinterop // FILE: threadStates.def language = C diff --git a/compiler/testData/codegen/box/cinterop/threadStates/nestedCallbackWithException.kt b/compiler/testData/codegen/box/cinterop/threadStates/nestedCallbackWithException.kt index e54fe8c91ef..e92d826a6e3 100644 --- a/compiler/testData/codegen/box/cinterop/threadStates/nestedCallbackWithException.kt +++ b/compiler/testData/codegen/box/cinterop/threadStates/nestedCallbackWithException.kt @@ -4,7 +4,6 @@ */ // TARGET_BACKEND: NATIVE // NATIVE_STANDALONE -// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative // MODULE: cinterop // FILE: threadStates.def language = C diff --git a/compiler/testData/codegen/box/cinterop/threadStates/nestedCallbackWithFinally.kt b/compiler/testData/codegen/box/cinterop/threadStates/nestedCallbackWithFinally.kt index 686f8634b0d..3bca16c73a1 100644 --- a/compiler/testData/codegen/box/cinterop/threadStates/nestedCallbackWithFinally.kt +++ b/compiler/testData/codegen/box/cinterop/threadStates/nestedCallbackWithFinally.kt @@ -4,7 +4,6 @@ */ // TARGET_BACKEND: NATIVE // NATIVE_STANDALONE -// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative // MODULE: cinterop // FILE: threadStates.def language = C diff --git a/compiler/testData/codegen/box/cinterop/threadStates/nestedCalls.kt b/compiler/testData/codegen/box/cinterop/threadStates/nestedCalls.kt index 14a5b5c758d..31ba253f379 100644 --- a/compiler/testData/codegen/box/cinterop/threadStates/nestedCalls.kt +++ b/compiler/testData/codegen/box/cinterop/threadStates/nestedCalls.kt @@ -4,7 +4,6 @@ */ // TARGET_BACKEND: NATIVE // NATIVE_STANDALONE -// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative // MODULE: cinterop // FILE: threadStates.def language = C diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 82150c0b81b..78a3549f6e2 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -1176,10 +1176,6 @@ if (PlatformInfo.isAppleTarget(project)) { it.defFile 'interop/objc/kt42172/objclib.def' it.headers "$projectDir/interop/objc/kt42172/objclib.h" } - createInterop("objc_kt48816") { - it.defFile 'interop/objc/kt48816/objclib.def' - it.headers "$projectDir/interop/objc/kt48816/objclib.h" - } createInterop("objc_kt55938") { it.defFile 'interop/objc/kt55938/objclib.def' it.headers "$projectDir/interop/objc/kt55938/objclib.h" @@ -1648,21 +1644,6 @@ if (PlatformInfo.isAppleTarget(project)) { UtilsKt.codesign(project, dylibFile.toString()) } } - - } - - interopTest("interop_objc_kt48816_without_lazy_ir_for_caches") { - // Without a fix, fails in two-stage mode. - source = "interop/objc/kt48816/main.kt" - interop = "objc_kt48816" - // The bug was accidentally fixed with lazy IR for caches, so testing it with this feature disabled: - flags = ["-Xlazy-ir-for-caches=disable"] - } - - interopTest("interop_objc_kt48816_with_lazy_ir_for_caches") { - source = "interop/objc/kt48816/main.kt" - interop = "objc_kt48816" - flags = ["-Xlazy-ir-for-caches=enable"] } interopTest("interop_objc_kt55938") { diff --git a/kotlin-native/backend.native/tests/interop/objc/kt48816/objclib.def b/kotlin-native/backend.native/tests/interop/objc/kt48816/objclib.def deleted file mode 100644 index 8dfe477cdbd..00000000000 --- a/kotlin-native/backend.native/tests/interop/objc/kt48816/objclib.def +++ /dev/null @@ -1,2 +0,0 @@ -language = Objective-C -headerFilter = **/objclib.h **/NSObject.h **/NSDate.h **/NSUUID.h diff --git a/kotlin-native/backend.native/tests/interop/objc/kt48816/objclib.h b/kotlin-native/backend.native/tests/interop/objc/kt48816/objclib.h deleted file mode 100644 index eb10cfce69c..00000000000 --- a/kotlin-native/backend.native/tests/interop/objc/kt48816/objclib.h +++ /dev/null @@ -1,9 +0,0 @@ -#import -#import -#import - -@interface MyClass1 : NSObject -@end - -@interface MyClass2 : NSObject -@end diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java index ecbf4b5a805..fa3843984cb 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java @@ -5074,6 +5074,18 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe runTest("compiler/testData/codegen/box/cinterop/objc/kt34467.kt"); } + @Test + @TestMetadata("kt48816_lazy_ir_disable.kt") + public void testKt48816_lazy_ir_disable() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/objc/kt48816_lazy_ir_disable.kt"); + } + + @Test + @TestMetadata("kt48816_lazy_ir_enable.kt") + public void testKt48816_lazy_ir_enable() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/objc/kt48816_lazy_ir_enable.kt"); + } + @Test @TestMetadata("kt53151.kt") public void testKt53151() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java index d0afabe23c5..f6d122f1b69 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java @@ -5190,6 +5190,18 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB runTest("compiler/testData/codegen/box/cinterop/objc/kt34467.kt"); } + @Test + @TestMetadata("kt48816_lazy_ir_disable.kt") + public void testKt48816_lazy_ir_disable() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/objc/kt48816_lazy_ir_disable.kt"); + } + + @Test + @TestMetadata("kt48816_lazy_ir_enable.kt") + public void testKt48816_lazy_ir_enable() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/objc/kt48816_lazy_ir_enable.kt"); + } + @Test @TestMetadata("kt53151.kt") public void testKt53151() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java index de117b43d50..3407572bed8 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java @@ -4958,6 +4958,18 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest runTest("compiler/testData/codegen/box/cinterop/objc/kt34467.kt"); } + @Test + @TestMetadata("kt48816_lazy_ir_disable.kt") + public void testKt48816_lazy_ir_disable() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/objc/kt48816_lazy_ir_disable.kt"); + } + + @Test + @TestMetadata("kt48816_lazy_ir_enable.kt") + public void testKt48816_lazy_ir_enable() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/objc/kt48816_lazy_ir_enable.kt"); + } + @Test @TestMetadata("kt53151.kt") public void testKt53151() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java index ec7e379baa2..e338de760aa 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java @@ -5075,6 +5075,18 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT runTest("compiler/testData/codegen/box/cinterop/objc/kt34467.kt"); } + @Test + @TestMetadata("kt48816_lazy_ir_disable.kt") + public void testKt48816_lazy_ir_disable() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/objc/kt48816_lazy_ir_disable.kt"); + } + + @Test + @TestMetadata("kt48816_lazy_ir_enable.kt") + public void testKt48816_lazy_ir_enable() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/objc/kt48816_lazy_ir_enable.kt"); + } + @Test @TestMetadata("kt53151.kt") public void testKt53151() throws Exception { diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/group/ExtTestCaseGroupProvider.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/group/ExtTestCaseGroupProvider.kt index 6cab39998ff..99de5b01b95 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/group/ExtTestCaseGroupProvider.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/group/ExtTestCaseGroupProvider.kt @@ -29,6 +29,7 @@ import org.jetbrains.kotlin.konan.test.blackbox.support.TestDirectives.DISABLE_N import org.jetbrains.kotlin.konan.test.blackbox.support.TestDirectives.DISABLE_NATIVE_K2 import org.jetbrains.kotlin.konan.test.blackbox.support.TestDirectives.FILECHECK_STAGE import org.jetbrains.kotlin.konan.test.blackbox.support.TestDirectives.FREE_CINTEROP_ARGS +import org.jetbrains.kotlin.konan.test.blackbox.support.TestDirectives.FREE_COMPILER_ARGS import org.jetbrains.kotlin.konan.test.blackbox.support.TestDirectives.IGNORE_NATIVE import org.jetbrains.kotlin.konan.test.blackbox.support.TestDirectives.IGNORE_NATIVE_K1 import org.jetbrains.kotlin.konan.test.blackbox.support.TestDirectives.IGNORE_NATIVE_K2 @@ -171,6 +172,7 @@ private class ExtTestDataFile( private fun assembleFreeCompilerArgs(): TestCompilerArgs { val args = mutableListOf() + structure.directives.listValues(FREE_COMPILER_ARGS.name)?.let { args.addAll(it)} testDataFileSettings.languageSettings.sorted().mapTo(args) { "-XXLanguage:$it" } testDataFileSettings.optInsForCompiler.sorted().mapTo(args) { "-opt-in=$it" } args += "-opt-in=kotlin.native.internal.InternalForKotlinNative" // for `Any.isPermanent()` and `Any.isLocal()`