diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLoweredDeclarationOrigin.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLoweredDeclarationOrigin.kt index fd0e2a047e2..2df04199b2f 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLoweredDeclarationOrigin.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLoweredDeclarationOrigin.kt @@ -22,10 +22,8 @@ interface JvmLoweredDeclarationOrigin : IrDeclarationOrigin { object TO_ARRAY : IrDeclarationOriginImpl("TO_ARRAY") object JVM_STATIC_WRAPPER : IrDeclarationOriginImpl("JVM_STATIC_WRAPPER") object JVM_OVERLOADS_WRAPPER : IrDeclarationOriginImpl("JVM_OVERLOADS_WRAPPER") - object SYNTHETIC_METHOD_FOR_PROPERTY_ANNOTATIONS : - IrDeclarationOriginImpl("SYNTHETIC_METHOD_FOR_PROPERTY_ANNOTATIONS", isSynthetic = true) - object SYNTHETIC_METHOD_FOR_TYPEALIAS_ANNOTATIONS : - IrDeclarationOriginImpl("SYNTHETIC_METHOD_FOR_TYPEALIAS_ANNOTATIONS", isSynthetic = true) + object SYNTHETIC_METHOD_FOR_PROPERTY_OR_TYPEALIAS_ANNOTATIONS : + IrDeclarationOriginImpl("SYNTHETIC_METHOD_FOR_PROPERTY_OR_TYPEALIAS_ANNOTATIONS", isSynthetic = true) object GENERATED_PROPERTY_REFERENCE : IrDeclarationOriginImpl("GENERATED_PROPERTY_REFERENCE", isSynthetic = true) object GENERATED_MEMBER_IN_CALLABLE_REFERENCE : IrDeclarationOriginImpl("GENERATED_MEMBER_IN_CALLABLE_REFERENCE", isSynthetic = false) object ENUM_MAPPINGS_FOR_WHEN : IrDeclarationOriginImpl("ENUM_MAPPINGS_FOR_WHEN", isSynthetic = true) 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 8b21ea6ce81..c19804ada95 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 @@ -365,7 +365,7 @@ class ClassCodegen private constructor( when (val metadata = method.metadata) { is MetadataSource.Property -> { - assert(method.isSyntheticMethodForProperty) { + assert(method.origin == JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_OR_TYPEALIAS_ANNOTATIONS) { "MetadataSource.Property on IrFunction should only be used for synthetic \$annotations methods: ${method.render()}" } metadataSerializer.bindMethodMetadata(metadata, Method(node.name, node.desc)) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt index 9d49f97f540..24bfaf5740c 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt @@ -118,7 +118,7 @@ class FunctionCodegen( private fun shouldGenerateAnnotationsOnValueParameters(): Boolean = when { - irFunction.origin == JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_ANNOTATIONS -> + irFunction.origin == JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_OR_TYPEALIAS_ANNOTATIONS -> false irFunction is IrConstructor && irFunction.parentAsClass.shouldNotGenerateConstructorParameterAnnotations() -> // Not generating parameter annotations for default stubs fixes KT-7892, though 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 3a76c6f47ac..ee87513a15d 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 @@ -127,10 +127,10 @@ class MethodSignatureMapper(private val context: JvmBackendContext) { originalForDefaultAdapter?.isInvisibleInMultifilePart() == true) private fun IrSimpleFunction.getInternalFunctionForManglingIfNeeded(): IrSimpleFunction? { - if (origin != JvmLoweredDeclarationOrigin.STATIC_INLINE_CLASS_CONSTRUCTOR && - visibility == DescriptorVisibilities.INTERNAL && - !isPublishedApi() && - !isSyntheticMethodForProperty + if (visibility == DescriptorVisibilities.INTERNAL && + origin != JvmLoweredDeclarationOrigin.STATIC_INLINE_CLASS_CONSTRUCTOR && + origin != JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_OR_TYPEALIAS_ANNOTATIONS && + !isPublishedApi() ) { 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 da1885ac0f7..3ca296a9015 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 @@ -33,7 +33,6 @@ import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.getClass import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.load.java.JavaDescriptorVisibilities -import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.kotlin.JvmPackagePartSource import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName @@ -349,14 +348,9 @@ internal fun IrDeclaration.isDeprecatedCallable(context: JvmBackendContext): Boo isAnnotatedWithDeprecated || annotations.any { it.symbol == context.ir.symbols.javaLangDeprecatedConstructorWithDeprecatedFlag } -// 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 -val IrFunction.isSyntheticMethodForProperty: Boolean - get() = name.asString().endsWith(JvmAbi.ANNOTATED_PROPERTY_METHOD_NAME_SUFFIX) - internal fun IrFunction.isDeprecatedFunction(context: JvmBackendContext): Boolean = - isSyntheticMethodForProperty || isDeprecatedCallable(context) || + origin == JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_OR_TYPEALIAS_ANNOTATIONS || + isDeprecatedCallable(context) || (this as? IrSimpleFunction)?.correspondingPropertySymbol?.owner?.isDeprecatedCallable(context) == true || isAccessorForDeprecatedPropertyImplementedByDelegation || isAccessorForDeprecatedJvmStaticProperty(context) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/GenerateMultifileFacades.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/GenerateMultifileFacades.kt index 70c09b607ae..b2f51286227 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/GenerateMultifileFacades.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/GenerateMultifileFacades.kt @@ -17,7 +17,6 @@ import org.jetbrains.kotlin.backend.common.phaser.makeCustomPhase import org.jetbrains.kotlin.backend.jvm.JvmBackendContext import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin import org.jetbrains.kotlin.backend.jvm.codegen.fileParent -import org.jetbrains.kotlin.backend.jvm.codegen.isSyntheticMethodForProperty import org.jetbrains.kotlin.config.JvmAnalysisFlags import org.jetbrains.kotlin.descriptors.DescriptorVisibilities import org.jetbrains.kotlin.descriptors.Modality @@ -223,7 +222,8 @@ private fun IrSimpleFunction.createMultifileDelegateIfNeeded( name == StaticInitializersLowering.clinitName || origin == JvmLoweredDeclarationOrigin.SYNTHETIC_ACCESSOR || // $annotations methods in the facade are only needed for const properties. - (isSyntheticMethodForProperty && (metadata as? MetadataSource.Property)?.isConst != true) + (origin == JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_OR_TYPEALIAS_ANNOTATIONS && + (metadata as? MetadataSource.Property)?.isConst != true) ) return null val function = context.irFactory.buildFun { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceLowering.kt index 1331283d2b1..2b9345286ff 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceLowering.kt @@ -125,7 +125,7 @@ internal class InterfaceLowering(val context: JvmBackendContext) : IrElementTran */ (DescriptorVisibilities.isPrivate(function.visibility) && !function.isCompiledToJvmDefault(jvmDefaultMode)) || (function.origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER && !function.isCompiledToJvmDefault(jvmDefaultMode)) - || function.origin == JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_ANNOTATIONS -> { + || function.origin == JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_OR_TYPEALIAS_ANNOTATIONS -> { val defaultImpl = createDefaultImpl(function) defaultImpl.body = function.moveBodyTo(defaultImpl) removedFunctions[function.symbol] = defaultImpl.symbol @@ -175,7 +175,7 @@ internal class InterfaceLowering(val context: JvmBackendContext) : IrElementTran private fun handleAnnotationClass(irClass: IrClass) { // We produce $DefaultImpls for annotation classes only to move $annotations methods (for property annotations) there. val annotationsMethods = - irClass.functions.filter { it.origin == JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_ANNOTATIONS } + irClass.functions.filter { it.origin == JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_OR_TYPEALIAS_ANNOTATIONS } if (annotationsMethods.none()) return for (function in annotationsMethods) { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt index b5af34c168c..c0b8141e2f7 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt @@ -129,7 +129,7 @@ class JvmPropertiesLowering(private val backendContext: JvmBackendContext) : IrE private fun createSyntheticMethodForAnnotations(declaration: IrProperty): IrSimpleFunction = backendContext.irFactory.buildFun { - origin = JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_ANNOTATIONS + origin = JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_OR_TYPEALIAS_ANNOTATIONS name = Name.identifier(computeSyntheticMethodName(declaration)) visibility = declaration.visibility modality = Modality.OPEN diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStaticAnnotationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStaticAnnotationLowering.kt index 6d4b0640da6..b293cf677dc 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStaticAnnotationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStaticAnnotationLowering.kt @@ -63,7 +63,7 @@ private class JvmStaticInCompanionLowering(val context: JvmBackendContext) : IrE .filter { it.isJvmStaticDeclaration() && it.origin != IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER && - it.origin != JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_ANNOTATIONS + it.origin != JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_OR_TYPEALIAS_ANNOTATIONS } .forEach { declaration -> val jvmStaticFunction = declaration as IrSimpleFunction diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/TypeAliasAnnotationMethodsLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/TypeAliasAnnotationMethodsLowering.kt index 64b54159ec0..8ae6fda55c5 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/TypeAliasAnnotationMethodsLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/TypeAliasAnnotationMethodsLowering.kt @@ -45,7 +45,7 @@ class TypeAliasAnnotationMethodsLowering(val context: CommonBackendContext) : visibility = alias.visibility returnType = context.irBuiltIns.unitType modality = Modality.OPEN - origin = JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_TYPEALIAS_ANNOTATIONS + origin = JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_OR_TYPEALIAS_ANNOTATIONS }.apply { body = IrBlockBodyImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET) annotations += alias.annotations diff --git a/compiler/testData/codegen/bytecodeListing/annotations/internalProperty.kt b/compiler/testData/codegen/bytecodeListing/annotations/internalPropertyOrTypealias.kt similarity index 55% rename from compiler/testData/codegen/bytecodeListing/annotations/internalProperty.kt rename to compiler/testData/codegen/bytecodeListing/annotations/internalPropertyOrTypealias.kt index 3e593258693..3a795abffe6 100644 --- a/compiler/testData/codegen/bytecodeListing/annotations/internalProperty.kt +++ b/compiler/testData/codegen/bytecodeListing/annotations/internalPropertyOrTypealias.kt @@ -1,3 +1,4 @@ +@Target(AnnotationTarget.PROPERTY, AnnotationTarget.TYPEALIAS) annotation class Anno class C { @@ -7,3 +8,6 @@ class C { @Anno internal val property: Int get() = 0 + +@Anno +internal typealias Typealias = Any diff --git a/compiler/testData/codegen/bytecodeListing/annotations/internalProperty.txt b/compiler/testData/codegen/bytecodeListing/annotations/internalPropertyOrTypealias.txt similarity index 58% rename from compiler/testData/codegen/bytecodeListing/annotations/internalProperty.txt rename to compiler/testData/codegen/bytecodeListing/annotations/internalPropertyOrTypealias.txt index 8eedfcd7a03..c88b79f5d76 100644 --- a/compiler/testData/codegen/bytecodeListing/annotations/internalProperty.txt +++ b/compiler/testData/codegen/bytecodeListing/annotations/internalPropertyOrTypealias.txt @@ -1,20 +1,23 @@ +@kotlin.annotation.Target @java.lang.annotation.Retention +@java.lang.annotation.Target @kotlin.Metadata public annotation class Anno { - // source: 'internalProperty.kt' + // source: 'internalPropertyOrTypealias.kt' } @kotlin.Metadata public final class C { - // source: 'internalProperty.kt' + // source: 'internalPropertyOrTypealias.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 final class InternalPropertyOrTypealiasKt { + // source: 'internalPropertyOrTypealias.kt' + public synthetic deprecated static @Anno method Typealias$annotations(): void public synthetic deprecated static @Anno method getProperty$annotations(): void public final static method getProperty(): int } diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java index 5fb50b0a9bd..83948ecead1 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java @@ -241,9 +241,9 @@ 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("internalPropertyOrTypealias.kt") + public void testInternalPropertyOrTypealias() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/annotations/internalPropertyOrTypealias.kt"); } @TestMetadata("JvmSynthetic.kt") diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java index aad039f8b44..16f066ea6c2 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java @@ -241,9 +241,9 @@ 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("internalPropertyOrTypealias.kt") + public void testInternalPropertyOrTypealias() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/annotations/internalPropertyOrTypealias.kt"); } @TestMetadata("JvmSynthetic.kt")