JVM IR: use origin to detect property/typealias $annotations methods
Now that DEFAULT_IMPLS origins for methods do not exist after previous commits, the name heuristic is no longer needed.
This commit is contained in:
+2
-4
@@ -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)
|
||||
|
||||
+1
-1
@@ -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))
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+4
-4
@@ -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
|
||||
}
|
||||
|
||||
+2
-8
@@ -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)
|
||||
|
||||
+2
-2
@@ -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 {
|
||||
|
||||
+2
-2
@@ -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) {
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+4
@@ -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
|
||||
+7
-4
@@ -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 <init>(): 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
|
||||
}
|
||||
+3
-3
@@ -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")
|
||||
|
||||
+3
-3
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user