[K2/N] KT-55464, KT-56091 Fix various klib annotations, including critical ones

Merge-request: KT-MR-8457
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
This commit is contained in:
Vladimir Sukharev
2023-01-26 11:15:15 +00:00
committed by Space Team
parent 53967a1822
commit 1990883bdc
19 changed files with 394 additions and 19 deletions
@@ -0,0 +1,38 @@
package test
annotation class AnnoClass
annotation class AnnoConstructor
annotation class AnnoConstructorParameter
annotation class AnnoProperty
annotation class AnnoSetParam
annotation class AnnoSetParam2
annotation class AnnoBackingField
annotation class AnnoGetter
annotation class AnnoSetter
annotation class AnnoSetter2
annotation class AnnoDelegatedField
annotation class AnnoFunction
annotation class AnnoFunctionParam
annotation class AnnoFunctionExtensionReceiver
annotation class AnnoPropertyExtensionReceiver
@AnnoClass
class Foo @AnnoConstructor constructor(@AnnoConstructorParameter i: Int) {
@AnnoProperty
@setparam:AnnoSetParam
@field:AnnoBackingField
var prop: Int = i
@AnnoGetter
get() = field + 1
@AnnoSetter
set(x: Int) { field = x*2 }
@set:AnnoSetter2
var mutableProp = 0
set(@AnnoSetParam2 x: Int) { field = x*2 }
@delegate:AnnoDelegatedField
val immutableProp by lazy { prop }
}
@AnnoFunction
fun @receiver:AnnoFunctionExtensionReceiver Foo.extfun(@AnnoFunctionParam x: Int) {}
@AnnoPropertyExtensionReceiver
val Foo.extProp get() = this.prop
@@ -0,0 +1,25 @@
annotation class AnnoBackingField constructor() : Annotation
annotation class AnnoClass constructor() : Annotation
annotation class AnnoConstructor constructor() : Annotation
annotation class AnnoConstructorParameter constructor() : Annotation
annotation class AnnoDelegatedField constructor() : Annotation
annotation class AnnoFunction constructor() : Annotation
annotation class AnnoFunctionExtensionReceiver constructor() : Annotation
annotation class AnnoFunctionParam constructor() : Annotation
annotation class AnnoGetter constructor() : Annotation
annotation class AnnoProperty constructor() : Annotation
annotation class AnnoPropertyExtensionReceiver constructor() : Annotation
annotation class AnnoSetParam constructor() : Annotation
annotation class AnnoSetParam2 constructor() : Annotation
annotation class AnnoSetter constructor() : Annotation
annotation class AnnoSetter2 constructor() : Annotation
@AnnoClass class Foo @AnnoConstructor constructor(@AnnoConstructorParameter i: Int) {
@delegate:AnnoDelegatedField val immutableProp: Int
var mutableProp: Int
@AnnoSetter2 set
@AnnoProperty @field:AnnoBackingField var prop: Int
@AnnoGetter get
@AnnoSetter set
}
@AnnoPropertyExtensionReceiver val Foo.extProp: Int
@AnnoFunction fun @receiver:AnnoFunctionExtensionReceiver Foo.extfun(@AnnoFunctionParam x: Int)
@@ -0,0 +1,53 @@
package test
@Retention(AnnotationRetention.SOURCE)
annotation class AnnoClass
@Retention(AnnotationRetention.SOURCE)
annotation class AnnoConstructor
@Retention(AnnotationRetention.SOURCE)
annotation class AnnoConstructorParameter
@Retention(AnnotationRetention.SOURCE)
annotation class AnnoProperty
@Retention(AnnotationRetention.SOURCE)
annotation class AnnoSetParam
@Retention(AnnotationRetention.SOURCE)
annotation class AnnoSetParam2
@Retention(AnnotationRetention.SOURCE)
annotation class AnnoBackingField
@Retention(AnnotationRetention.SOURCE)
annotation class AnnoGetter
@Retention(AnnotationRetention.SOURCE)
annotation class AnnoSetter
@Retention(AnnotationRetention.SOURCE)
annotation class AnnoSetter2
@Retention(AnnotationRetention.SOURCE)
annotation class AnnoDelegatedField
@Retention(AnnotationRetention.SOURCE)
annotation class AnnoFunction
@Retention(AnnotationRetention.SOURCE)
annotation class AnnoFunctionParam
@Retention(AnnotationRetention.SOURCE)
annotation class AnnoFunctionExtensionReceiver
@Retention(AnnotationRetention.SOURCE)
annotation class AnnoPropertyExtensionReceiver
@AnnoClass
class Foo @AnnoConstructor constructor(@AnnoConstructorParameter i: Int) {
@AnnoProperty
@setparam:AnnoSetParam
@field:AnnoBackingField
var prop: Int = i
@AnnoGetter
get() = field + 1
@AnnoSetter
set(x: Int) { field = x*2 }
@set:AnnoSetter2
var mutableProp = 0
set(@AnnoSetParam2 x: Int) { field = x*2 }
@delegate:AnnoDelegatedField
val immutableProp by lazy { prop }
}
@AnnoFunction
fun @receiver:AnnoFunctionExtensionReceiver Foo.extfun(@AnnoFunctionParam x: Int) {}
@AnnoPropertyExtensionReceiver
val Foo.extProp get() = this.prop
@@ -0,0 +1,22 @@
@Retention(value = AnnotationRetention.SOURCE) annotation class AnnoBackingField constructor() : Annotation
@Retention(value = AnnotationRetention.SOURCE) annotation class AnnoClass constructor() : Annotation
@Retention(value = AnnotationRetention.SOURCE) annotation class AnnoConstructor constructor() : Annotation
@Retention(value = AnnotationRetention.SOURCE) annotation class AnnoConstructorParameter constructor() : Annotation
@Retention(value = AnnotationRetention.SOURCE) annotation class AnnoDelegatedField constructor() : Annotation
@Retention(value = AnnotationRetention.SOURCE) annotation class AnnoFunction constructor() : Annotation
@Retention(value = AnnotationRetention.SOURCE) annotation class AnnoFunctionExtensionReceiver constructor() : Annotation
@Retention(value = AnnotationRetention.SOURCE) annotation class AnnoFunctionParam constructor() : Annotation
@Retention(value = AnnotationRetention.SOURCE) annotation class AnnoGetter constructor() : Annotation
@Retention(value = AnnotationRetention.SOURCE) annotation class AnnoProperty constructor() : Annotation
@Retention(value = AnnotationRetention.SOURCE) annotation class AnnoPropertyExtensionReceiver constructor() : Annotation
@Retention(value = AnnotationRetention.SOURCE) annotation class AnnoSetParam constructor() : Annotation
@Retention(value = AnnotationRetention.SOURCE) annotation class AnnoSetParam2 constructor() : Annotation
@Retention(value = AnnotationRetention.SOURCE) annotation class AnnoSetter constructor() : Annotation
@Retention(value = AnnotationRetention.SOURCE) annotation class AnnoSetter2 constructor() : Annotation
class Foo constructor(i: Int) {
val immutableProp: Int
var mutableProp: Int
var prop: Int
}
val Foo.extProp: Int
fun Foo.extfun(x: Int)
@@ -0,0 +1,5 @@
package test
class C
// If serializeTypeAnnotation() is wrong, the following callback would have wrong type: (C) -> Unit
fun C.builder(c: C.() -> Unit) {}
@@ -0,0 +1,2 @@
class C constructor()
fun C.builder(c: C.() -> Unit)
@@ -0,0 +1,7 @@
package test
annotation class Annotation
fun foo(@Annotation arg: Int) {}
// KT-56177 TODO uncomment the line after KT-56177 is fixed
//data class Clazz(@Annotation val param: Int)
@@ -0,0 +1,2 @@
annotation class Annotation constructor() : Annotation
fun foo(@Annotation arg: Int)
@@ -0,0 +1,14 @@
package test
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.TYPE)
annotation class AnnoRuntime
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.TYPE)
annotation class AnnoBinary
@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.TYPE)
annotation class AnnoSource
fun withRuntimeAnnotation(id: @AnnoRuntime Int) {}
fun withBinaryAnnotation(id: @AnnoBinary Int) {}
fun withSourceAnnotation(id: @AnnoSource Int) {}
@@ -0,0 +1,6 @@
@Retention(value = AnnotationRetention.BINARY) @Target(allowedTargets = {AnnotationTarget.TYPE}) annotation class AnnoBinary constructor() : Annotation
@Retention(value = AnnotationRetention.RUNTIME) @Target(allowedTargets = {AnnotationTarget.TYPE}) annotation class AnnoRuntime constructor() : Annotation
@Retention(value = AnnotationRetention.SOURCE) @Target(allowedTargets = {AnnotationTarget.TYPE}) annotation class AnnoSource constructor() : Annotation
fun withBinaryAnnotation(id: @AnnoBinary Int)
fun withRuntimeAnnotation(id: @AnnoRuntime Int)
fun withSourceAnnotation(id: Int)
@@ -0,0 +1,56 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.konan.blackboxtest;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("native/native.tests/testData/klibContents")
@TestDataPath("$PROJECT_ROOT")
public class NativeK1LibContentsTestGenerated extends AbstractNativeKlibContentsTest {
@Test
public void testAllFilesPresentInKlibContents() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/klibContents"), Pattern.compile("^([^_](.+)).kt$"), null, false);
}
@Test
@TestMetadata("annotations.kt")
public void testAnnotations() throws Exception {
runTest("native/native.tests/testData/klibContents/annotations.kt");
}
@Test
@TestMetadata("annotations_source_retention.kt")
public void testAnnotations_source_retention() throws Exception {
runTest("native/native.tests/testData/klibContents/annotations_source_retention.kt");
}
@Test
@TestMetadata("kt55464_serializeTypeAnnotation.kt")
public void testKt55464_serializeTypeAnnotation() throws Exception {
runTest("native/native.tests/testData/klibContents/kt55464_serializeTypeAnnotation.kt");
}
@Test
@TestMetadata("kt56018_value_parameters_annotations.kt")
public void testKt56018_value_parameters_annotations() throws Exception {
runTest("native/native.tests/testData/klibContents/kt56018_value_parameters_annotations.kt");
}
@Test
@TestMetadata("type_annotations.kt")
public void testType_annotations() throws Exception {
runTest("native/native.tests/testData/klibContents/type_annotations.kt");
}
}
@@ -0,0 +1,58 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.konan.blackboxtest;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.konan.blackboxtest.support.group.K2Pipeline;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("native/native.tests/testData/klibContents")
@TestDataPath("$PROJECT_ROOT")
@K2Pipeline()
public class NativeK2LibContentsTestGenerated extends AbstractNativeKlibContentsTest {
@Test
public void testAllFilesPresentInKlibContents() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/klibContents"), Pattern.compile("^([^_](.+)).kt$"), null, false);
}
@Test
@TestMetadata("annotations.kt")
public void testAnnotations() throws Exception {
runTest("native/native.tests/testData/klibContents/annotations.kt");
}
@Test
@TestMetadata("annotations_source_retention.kt")
public void testAnnotations_source_retention() throws Exception {
runTest("native/native.tests/testData/klibContents/annotations_source_retention.kt");
}
@Test
@TestMetadata("kt55464_serializeTypeAnnotation.kt")
public void testKt55464_serializeTypeAnnotation() throws Exception {
runTest("native/native.tests/testData/klibContents/kt55464_serializeTypeAnnotation.kt");
}
@Test
@TestMetadata("kt56018_value_parameters_annotations.kt")
public void testKt56018_value_parameters_annotations() throws Exception {
runTest("native/native.tests/testData/klibContents/kt56018_value_parameters_annotations.kt");
}
@Test
@TestMetadata("type_annotations.kt")
public void testType_annotations() throws Exception {
runTest("native/native.tests/testData/klibContents/type_annotations.kt");
}
}
@@ -100,6 +100,23 @@ fun main() {
}
}
// Klib contents tests
testGroup("native/native.tests/tests-gen", "native/native.tests/testData") {
testClass<AbstractNativeKlibContentsTest>(
suiteTestClassName = "NativeK1LibContentsTestGenerated"
) {
model("klibContents", pattern = "^([^_](.+)).kt$", recursive = false)
}
}
testGroup("native/native.tests/tests-gen", "native/native.tests/testData") {
testClass<AbstractNativeKlibContentsTest>(
suiteTestClassName = "NativeK2LibContentsTestGenerated",
annotations = listOf(provider<K2Pipeline>())
) {
model("klibContents", pattern = "^([^_](.+)).kt$", recursive = false)
}
}
// LLDB integration tests.
testGroup("native/native.tests/tests-gen", "native/native.tests/testData") {
testClass<AbstractNativeBlackBoxTest>(
@@ -0,0 +1,61 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.konan.blackboxtest
import com.intellij.openapi.util.text.StringUtilRt
import com.intellij.testFramework.TestDataFile
import org.jetbrains.kotlin.konan.blackboxtest.support.*
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.*
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationArtifact.*
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationResult.Companion.assertSuccess
import org.jetbrains.kotlin.konan.blackboxtest.support.runner.*
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.*
import org.jetbrains.kotlin.konan.blackboxtest.support.util.*
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEquals
import org.junit.jupiter.api.Tag
import java.io.File
@Tag("klib-contents")
abstract class AbstractNativeKlibContentsTest : AbstractNativeSimpleTest() {
protected fun runTest(@TestDataFile testPath: String) {
val testPathFull = getAbsoluteFile(testPath)
val testCase: TestCase = generateTestCaseWithSingleSource(testPathFull, listOf())
val testCompilationResult: TestCompilationResult.Success<out KLIB> = compileToLibrary(testCase)
val kotlinNativeClassLoader = testRunSettings.get<KotlinNativeClassLoader>()
val klibContents = testCompilationResult.assertSuccess().resultingArtifact.getContents(kotlinNativeClassLoader.classLoader)
val klibContentsFiltered = filterContentsOutput(klibContents, linestoExclude = listOf("package test {", "}", ""))
val expectedContents = File("${testPathFull.canonicalPath.substringBeforeLast(".")}.txt").readText()
assertEquals(StringUtilRt.convertLineSeparators(expectedContents), StringUtilRt.convertLineSeparators(klibContentsFiltered)) {
"Test failed. Compilation result was: $testCompilationResult"
}
}
private fun generateTestCaseWithSingleSource(source: File, extraArgs: List<String>): TestCase {
val moduleName: String = source.name
val module = TestModule.Exclusive(moduleName, emptySet(), emptySet())
module.files += TestFile.createCommitted(source, module)
return TestCase(
id = TestCaseId.Named(moduleName),
kind = TestKind.STANDALONE,
modules = setOf(module),
freeCompilerArgs = TestCompilerArgs(extraArgs),
nominalPackageName = PackageName.EMPTY,
checks = TestRunChecks.Default(testRunSettings.get<Timeouts>().executionTimeout),
extras = TestCase.WithTestRunnerExtras(TestRunnerType.DEFAULT)
).apply {
initialize(null, null)
}
}
private fun filterContentsOutput(contents: String, linestoExclude: List<String>) =
contents.split("\n").filterNot { line ->
linestoExclude.any { exclude -> exclude == line }
}.joinToString(separator = "\n")
}