From fbf56c054bc5fe3cc91a9263aa9447fd161c9745 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 13 Oct 2020 19:13:06 +0200 Subject: [PATCH] JVM IR: fix names of $annotations methods for internal properties #KT-40384 Fixed --- .../backend/jvm/codegen/ClassCodegen.kt | 8 +++----- .../jvm/codegen/MethodSignatureMapper.kt | 3 ++- .../backend/jvm/codegen/irCodegenUtils.kt | 4 ++-- .../annotations/internalProperty.kt | 9 +++++++++ .../annotations/internalProperty.txt | 20 +++++++++++++++++++ ...dPropertyWithInlineClassTypeInSignature.kt | 3 +++ ...PropertyWithInlineClassTypeInSignature.txt | 2 ++ .../codegen/BytecodeListingTestGenerated.java | 5 +++++ .../ir/IrBytecodeListingTestGenerated.java | 5 +++++ 9 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 compiler/testData/codegen/bytecodeListing/annotations/internalProperty.kt create mode 100644 compiler/testData/codegen/bytecodeListing/annotations/internalProperty.txt diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ClassCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ClassCodegen.kt index 51f2f63dfa9..9c6454aeb20 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ClassCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ClassCodegen.kt @@ -28,7 +28,6 @@ import org.jetbrains.kotlin.ir.expressions.IrFunctionReference import org.jetbrains.kotlin.ir.expressions.impl.IrBlockBodyImpl import org.jetbrains.kotlin.ir.expressions.impl.IrSetFieldImpl import org.jetbrains.kotlin.ir.util.* -import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.java.JvmAnnotationNames import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader import org.jetbrains.kotlin.metadata.jvm.serialization.JvmStringTable @@ -366,10 +365,9 @@ class ClassCodegen private constructor( when (val metadata = method.metadata) { is MetadataSource.Property -> { - // We can't check for JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_ANNOTATIONS because for interface methods - // moved to DefaultImpls, origin is changed to DEFAULT_IMPLS - // TODO: fix origin somehow, because otherwise $annotations methods in interfaces also don't have ACC_SYNTHETIC - assert(method.name.asString().endsWith(JvmAbi.ANNOTATED_PROPERTY_METHOD_NAME_SUFFIX)) { method.dump() } + assert(method.isSyntheticMethodForProperty) { + "MetadataSource.Property on IrFunction should only be used for synthetic \$annotations methods: ${method.render()}" + } metadataSerializer.bindMethodMetadata(metadata, Method(node.name, node.desc)) } is MetadataSource.Function -> metadataSerializer.bindMethodMetadata(metadata, Method(node.name, node.desc)) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt index 9e7a463c6e0..c2c11d12ccc 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt @@ -130,7 +130,8 @@ class MethodSignatureMapper(private val context: JvmBackendContext) { private fun IrSimpleFunction.getInternalFunctionForManglingIfNeeded(): IrSimpleFunction? { if (origin != JvmLoweredDeclarationOrigin.STATIC_INLINE_CLASS_CONSTRUCTOR && visibility == DescriptorVisibilities.INTERNAL && - !isPublishedApi() + !isPublishedApi() && + !isSyntheticMethodForProperty ) { return this } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt index e536bf5a25f..6d4ea931b07 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt @@ -417,5 +417,5 @@ val IrDeclaration.psiElement: PsiElement? val IrMemberAccessExpression<*>.psiElement: PsiElement? get() = (symbol.descriptor.original as? DeclarationDescriptorWithSource)?.psiElement -fun IrSimpleType.isRawType() = - hasAnnotation(JvmGeneratorExtensions.RAW_TYPE_ANNOTATION_FQ_NAME) \ No newline at end of file +fun IrSimpleType.isRawType(): Boolean = + hasAnnotation(JvmGeneratorExtensions.RAW_TYPE_ANNOTATION_FQ_NAME) diff --git a/compiler/testData/codegen/bytecodeListing/annotations/internalProperty.kt b/compiler/testData/codegen/bytecodeListing/annotations/internalProperty.kt new file mode 100644 index 00000000000..3e593258693 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/annotations/internalProperty.kt @@ -0,0 +1,9 @@ +annotation class Anno + +class C { + @Anno + internal val property: Int get() = 0 +} + +@Anno +internal val property: Int get() = 0 diff --git a/compiler/testData/codegen/bytecodeListing/annotations/internalProperty.txt b/compiler/testData/codegen/bytecodeListing/annotations/internalProperty.txt new file mode 100644 index 00000000000..8eedfcd7a03 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/annotations/internalProperty.txt @@ -0,0 +1,20 @@ +@java.lang.annotation.Retention +@kotlin.Metadata +public annotation class Anno { + // source: 'internalProperty.kt' +} + +@kotlin.Metadata +public final class C { + // source: 'internalProperty.kt' + public method (): void + public synthetic deprecated static @Anno method getProperty$test_module$annotations(): void + public final method getProperty$test_module(): int +} + +@kotlin.Metadata +public final class InternalPropertyKt { + // source: 'internalProperty.kt' + public synthetic deprecated static @Anno method getProperty$annotations(): void + public final static method getProperty(): int +} diff --git a/compiler/testData/codegen/bytecodeListing/inlineClasses/annotatedPropertyWithInlineClassTypeInSignature.kt b/compiler/testData/codegen/bytecodeListing/inlineClasses/annotatedPropertyWithInlineClassTypeInSignature.kt index c008f02f0e9..4615635be00 100644 --- a/compiler/testData/codegen/bytecodeListing/inlineClasses/annotatedPropertyWithInlineClassTypeInSignature.kt +++ b/compiler/testData/codegen/bytecodeListing/inlineClasses/annotatedPropertyWithInlineClassTypeInSignature.kt @@ -17,4 +17,7 @@ class C { @Anno val returnType: Z get() = Z(0) + + @Anno + internal val Z.internal: Int get() = 0 } diff --git a/compiler/testData/codegen/bytecodeListing/inlineClasses/annotatedPropertyWithInlineClassTypeInSignature.txt b/compiler/testData/codegen/bytecodeListing/inlineClasses/annotatedPropertyWithInlineClassTypeInSignature.txt index 37c16108ad2..bd90808cf29 100644 --- a/compiler/testData/codegen/bytecodeListing/inlineClasses/annotatedPropertyWithInlineClassTypeInSignature.txt +++ b/compiler/testData/codegen/bytecodeListing/inlineClasses/annotatedPropertyWithInlineClassTypeInSignature.txt @@ -17,6 +17,8 @@ public final class AnnotatedPropertyWithInlineClassTypeInSignatureKt { public final class C { // source: 'annotatedPropertyWithInlineClassTypeInSignature.kt' public method (): void + public synthetic deprecated static @Anno method getInternal-IQRRRT4$test_module$annotations(p0: int): void + public final method getInternal-IQRRRT4$test_module(p0: int): int public synthetic deprecated static @Anno method getMemberExtension-IQRRRT4$annotations(p0: int): void public final method getMemberExtension-IQRRRT4(p0: int): int public synthetic deprecated static @Anno method getReturnType-a_XrcN0$annotations(): void diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java index fc7ae3cdc51..b4ac638b4dd 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java @@ -166,6 +166,11 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { runTest("compiler/testData/codegen/bytecodeListing/annotations/deprecatedJvmOverloads.kt"); } + @TestMetadata("internalProperty.kt") + public void testInternalProperty() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/annotations/internalProperty.kt"); + } + @TestMetadata("JvmSynthetic.kt") public void testJvmSynthetic() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/annotations/JvmSynthetic.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java index b3934b4ec38..0d169d8959f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java @@ -166,6 +166,11 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes runTest("compiler/testData/codegen/bytecodeListing/annotations/deprecatedJvmOverloads.kt"); } + @TestMetadata("internalProperty.kt") + public void testInternalProperty() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/annotations/internalProperty.kt"); + } + @TestMetadata("JvmSynthetic.kt") public void testJvmSynthetic() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/annotations/JvmSynthetic.kt");