JVM IR: do not serialize metadata for actualized optional expectations

Optional-expectation annotations which have an actual counterpart should
have never been serialized to the kotlin_module's proto. See for example
the original (correct) implementation in the old JVM backend in
`PackageCodegenImpl.addDescriptorToOptionalAnnotationsIfNeeded`.

 #KT-55611 Fixed
This commit is contained in:
Alexander Udalov
2022-12-27 22:56:18 +01:00
committed by Space Team
parent 11504fda18
commit 7a9c59aeb5
11 changed files with 84 additions and 0 deletions
@@ -85,6 +85,11 @@ public class IncrementalMultiplatformJvmCompilerRunnerTestGenerated extends Abst
runTest("jps/jps-plugin/testData/incremental/mpp/jvmOnly/multifilePartChanged/");
}
@TestMetadata("optionalExpectationWithActual")
public void testOptionalExpectationWithActual() throws Exception {
runTest("jps/jps-plugin/testData/incremental/mpp/jvmOnly/optionalExpectationWithActual/");
}
@TestMetadata("jps/jps-plugin/testData/incremental/mpp/jvmOnly/multifilePartChanged")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -97,5 +102,18 @@ public class IncrementalMultiplatformJvmCompilerRunnerTestGenerated extends Abst
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("jps/jps-plugin/testData/incremental/mpp/jvmOnly/multifilePartChanged"), Pattern.compile("^([^\\.]+)$"), null, true);
}
}
@TestMetadata("jps/jps-plugin/testData/incremental/mpp/jvmOnly/optionalExpectationWithActual")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class OptionalExpectationWithActual extends AbstractIncrementalMultiplatformJvmCompilerRunnerTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInOptionalExpectationWithActual() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("jps/jps-plugin/testData/incremental/mpp/jvmOnly/optionalExpectationWithActual"), Pattern.compile("^([^\\.]+)$"), null, true);
}
}
}
}
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.backend.jvm.ir.isOptionalAnnotationClass
import org.jetbrains.kotlin.ir.declarations.DescriptorMetadataSource
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.resolve.multiplatform.OptionalAnnotationUtil
internal val processOptionalAnnotationsPhase = makeIrModulePhase(
::ProcessOptionalAnnotations,
@@ -30,6 +31,7 @@ class ProcessOptionalAnnotations(private val context: JvmBackendContext) : FileL
private fun IrClass.registerOptionalAnnotations() {
// TODO FirMetadataSource.Class
val metadataSource = (metadata as? DescriptorMetadataSource.Class)?.descriptor ?: return
if (!OptionalAnnotationUtil.shouldGenerateExpectClass(metadataSource)) return
context.state.factory.packagePartRegistry.optionalAnnotations += metadataSource
declarations.forEach {
@@ -0,0 +1,6 @@
package org.example
@OptIn(kotlin.ExperimentalMultiplatform::class)
@Target(AnnotationTarget.FILE)
@Retention(AnnotationRetention.SOURCE)
internal actual annotation class A
@@ -0,0 +1 @@
-Xmulti-platform
@@ -0,0 +1,7 @@
@file:A
package org.example
fun foo() {
// 1
}
@@ -0,0 +1,7 @@
@file:A
package org.example
fun foo() {
// 2
}
@@ -0,0 +1,7 @@
@file:A
package org.example
fun foo() {
// 3
}
@@ -0,0 +1,14 @@
================ Step #1 =================
Compiling files:
src/b.kt
End of files
Exit code: OK
================ Step #2 =================
Compiling files:
src/b.kt
End of files
Exit code: OK
@@ -0,0 +1,7 @@
package org.example
@OptIn(kotlin.ExperimentalMultiplatform::class)
@OptionalExpectation
@Target(AnnotationTarget.FILE)
@Retention(AnnotationRetention.SOURCE)
internal expect annotation class A
@@ -13,8 +13,14 @@ expect annotation class B(val a: Array<String>)
@OptionalExpectation
expect annotation class C()
@OptionalExpectation
expect annotation class D()
actual annotation class D actual constructor()
@Suppress("OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE")
@A(42)
@B(["OK", ""])
@C
@D()
fun ok() {}
@@ -1,3 +1,12 @@
// test/D.class
// ------------------------------------------
public final annotation class test/D : kotlin/Annotation {
// signature: <init>()V
public constructor()
// module name: test-module
}
// test/OptionalAnnotationKt.class
// ------------------------------------------
package {