JVM IR: Mark annotation implementation classes as anonymous

And add tests to ensure that annotation implementation classes are
handled correctly in jvm-abi-gen.
This commit is contained in:
Steven Schäfer
2021-08-18 15:59:52 +02:00
committed by Alexander Udalov
parent 19660f11a7
commit 6d518c8e57
18 changed files with 128 additions and 4 deletions
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.backend.jvm.codegen
import org.jetbrains.kotlin.backend.common.lower.ANNOTATION_IMPLEMENTATION
import org.jetbrains.kotlin.backend.common.psi.PsiSourceManager
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
@@ -450,7 +451,7 @@ class ClassCodegen private constructor(
for (klass in innerClasses) {
val innerClass = typeMapper.classInternalName(klass)
val outerClass =
if (klass.isSamWrapper || klass.attributeOwnerId in context.isEnclosedInConstructor)
if (klass.isSamWrapper || klass.isAnnotationImplementation || klass.attributeOwnerId in context.isEnclosedInConstructor)
null
else {
when (val parent = klass.parent) {
@@ -465,7 +466,7 @@ class ClassCodegen private constructor(
}
private val IrClass.isAnonymousInnerClass: Boolean
get() = isSamWrapper || name.isSpecial // NB '<Continuation>' is treated as anonymous inner class here
get() = isSamWrapper || name.isSpecial || isAnnotationImplementation // NB '<Continuation>' is treated as anonymous inner class here
private val IrClass.isInlineSamWrapper: Boolean
get() = isSamWrapper && visibility == DescriptorVisibilities.PUBLIC
@@ -473,6 +474,9 @@ class ClassCodegen private constructor(
private val IrClass.isSamWrapper: Boolean
get() = origin == IrDeclarationOrigin.GENERATED_SAM_IMPLEMENTATION
private val IrClass.isAnnotationImplementation: Boolean
get() = origin == ANNOTATION_IMPLEMENTATION
override fun addInnerClassInfoFromAnnotation(innerClass: IrClass) {
// It's necessary for proper recovering of classId by plain string JVM descriptor when loading annotations
// See FileBasedKotlinClass.convertAnnotationVisitor
@@ -1,21 +1,22 @@
@kotlin.Metadata
public synthetic final class AnnotationCtorCallGenerateSyntheticKt$annotationImpl$Foo$0 {
// source: 'annotationCtorCallGenerateSynthetic.kt'
enclosing class AnnotationCtorCallGenerateSyntheticKt
private synthetic final field int: int
inner (anonymous) class AnnotationCtorCallGenerateSyntheticKt$annotationImpl$Foo$0
public method <init>(p0: int): void
public synthetic final method annotationType(): java.lang.Class
public final method equals(@org.jetbrains.annotations.Nullable p0: java.lang.Object): boolean
public final method hashCode(): int
public synthetic final method int(): int
public final @org.jetbrains.annotations.NotNull method toString(): java.lang.String
public synthetic inner class AnnotationCtorCallGenerateSyntheticKt$annotationImpl$Foo$0
}
@kotlin.Metadata
public final class AnnotationCtorCallGenerateSyntheticKt {
// source: 'annotationCtorCallGenerateSynthetic.kt'
inner (anonymous) class AnnotationCtorCallGenerateSyntheticKt$annotationImpl$Foo$0
public final static method box(): void
public synthetic inner class AnnotationCtorCallGenerateSyntheticKt$annotationImpl$Foo$0
}
@java.lang.annotation.Retention(value=RUNTIME)