FIR2IR: split property annotations according to use-site targets.
This commit is contained in:
committed by
Mikhail Glukhikh
parent
9bc8fdcb3c
commit
931ba4892a
+48
-7
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.fir.backend.generators
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.fir.backend.*
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter
|
||||
@@ -164,22 +165,31 @@ internal class ClassMemberGenerator(
|
||||
val initializer = property.initializer
|
||||
val delegate = property.delegate
|
||||
val propertyType = property.returnTypeRef.toIrType()
|
||||
irProperty.initializeBackingField(descriptor, initializerExpression = initializer ?: delegate)
|
||||
irProperty.initializeBackingField(property, descriptor, initializerExpression = initializer ?: delegate)
|
||||
irProperty.getter?.setPropertyAccessorContent(
|
||||
property.getter, irProperty, propertyType, property.getter is FirDefaultPropertyGetter
|
||||
property, property.getter, irProperty, propertyType, property.getter is FirDefaultPropertyGetter
|
||||
)
|
||||
if (property.isVar) {
|
||||
irProperty.setter?.setPropertyAccessorContent(
|
||||
property.setter, irProperty, propertyType, property.setter is FirDefaultPropertySetter
|
||||
property, property.setter, irProperty, propertyType, property.setter is FirDefaultPropertySetter
|
||||
)
|
||||
}
|
||||
irProperty.annotations = property.annotations.mapNotNull {
|
||||
it.accept(visitor, null) as? IrConstructorCall
|
||||
}
|
||||
irProperty.annotations +=
|
||||
property.annotations
|
||||
.filter {
|
||||
it.useSiteTarget == null || it.useSiteTarget == AnnotationUseSiteTarget.PROPERTY
|
||||
}
|
||||
.mapNotNull {
|
||||
it.accept(visitor, null) as? IrConstructorCall
|
||||
}
|
||||
return irProperty
|
||||
}
|
||||
|
||||
private fun IrProperty.initializeBackingField(descriptor: PropertyDescriptor, initializerExpression: FirExpression?) {
|
||||
private fun IrProperty.initializeBackingField(
|
||||
property: FirProperty,
|
||||
descriptor: PropertyDescriptor,
|
||||
initializerExpression: FirExpression?
|
||||
) {
|
||||
val irField = backingField ?: return
|
||||
conversionScope.withParent(irField) {
|
||||
declarationStorage.enterScope(descriptor)
|
||||
@@ -189,9 +199,17 @@ internal class ClassMemberGenerator(
|
||||
}
|
||||
declarationStorage.leaveScope(descriptor)
|
||||
}
|
||||
irField.annotations +=
|
||||
property.annotations
|
||||
.filter {
|
||||
it.useSiteTarget == AnnotationUseSiteTarget.FIELD ||
|
||||
it.useSiteTarget == AnnotationUseSiteTarget.PROPERTY_DELEGATE_FIELD
|
||||
}
|
||||
.mapNotNull { it.accept(visitor, null) as? IrConstructorCall }
|
||||
}
|
||||
|
||||
private fun IrFunction.setPropertyAccessorContent(
|
||||
property: FirProperty,
|
||||
propertyAccessor: FirPropertyAccessor?,
|
||||
correspondingProperty: IrProperty,
|
||||
propertyType: IrType,
|
||||
@@ -228,6 +246,29 @@ internal class ClassMemberGenerator(
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isSetter) {
|
||||
annotations +=
|
||||
property.annotations
|
||||
.filter { it.useSiteTarget == AnnotationUseSiteTarget.PROPERTY_SETTER }
|
||||
.mapNotNull { it.accept(visitor, null) as? IrConstructorCall }
|
||||
valueParameters.singleOrNull()?.annotations =
|
||||
valueParameters.singleOrNull()?.annotations?.plus(
|
||||
property.annotations
|
||||
.filter { it.useSiteTarget == AnnotationUseSiteTarget.SETTER_PARAMETER }
|
||||
.mapNotNull { it.accept(visitor, null) as? IrConstructorCall }
|
||||
)!!
|
||||
} else {
|
||||
annotations +=
|
||||
property.annotations
|
||||
.filter { it.useSiteTarget == AnnotationUseSiteTarget.PROPERTY_GETTER }
|
||||
.mapNotNull { it.accept(visitor, null) as? IrConstructorCall }
|
||||
}
|
||||
extensionReceiverParameter?.annotations =
|
||||
extensionReceiverParameter?.annotations?.plus(
|
||||
property.annotations
|
||||
.filter { it.useSiteTarget == AnnotationUseSiteTarget.RECEIVER }
|
||||
.mapNotNull { it.accept(visitor, null) as? IrConstructorCall }
|
||||
)!!
|
||||
}
|
||||
|
||||
private fun IrFieldAccessExpression.setReceiver(declaration: IrDeclaration): IrFieldAccessExpression {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
package test
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// !LANGUAGE: +UseGetterNameForPropertyAnnotationsMethodOnJvm
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
|
||||
|
||||
+2
-2
@@ -16,9 +16,9 @@ FILE fqName:<root> fileName:/delegateFieldWithAnnotations.kt
|
||||
public open fun toString (): kotlin.String declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
PROPERTY name:test1 visibility:public modality:FINAL [delegated,val]
|
||||
annotations:
|
||||
Ann
|
||||
FIELD PROPERTY_DELEGATE name:test1$delegate type:kotlin.Lazy<kotlin.Int> visibility:private [final,static]
|
||||
annotations:
|
||||
Ann
|
||||
EXPRESSION_BODY
|
||||
CALL 'public final fun lazy <T> (initializer: kotlin.Function0<T of kotlin.lazy>): kotlin.Lazy<T of kotlin.lazy> declared in kotlin' type=kotlin.Lazy<kotlin.Int> origin=null
|
||||
<T>: kotlin.Int
|
||||
|
||||
+8
-6
@@ -84,13 +84,13 @@ FILE fqName:<root> fileName:/delegatedPropertyAccessorsWithAnnotations.kt
|
||||
public open fun toString (): kotlin.String declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
PROPERTY name:test1 visibility:public modality:FINAL [delegated,val]
|
||||
annotations:
|
||||
A(x = 'test1.get')
|
||||
FIELD PROPERTY_DELEGATE name:test1$delegate type:<root>.Cell visibility:private [final,static]
|
||||
EXPRESSION_BODY
|
||||
CONSTRUCTOR_CALL 'public constructor <init> (value: kotlin.Int) [primary] declared in <root>.Cell' type=<root>.Cell origin=null
|
||||
value: CONST Int type=kotlin.Int value=1
|
||||
FUN DELEGATED_PROPERTY_ACCESSOR name:<get-test1> visibility:public modality:FINAL <> () returnType:kotlin.Int
|
||||
annotations:
|
||||
A(x = 'test1.get')
|
||||
correspondingProperty: PROPERTY name:test1 visibility:public modality:FINAL [delegated,val]
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-test1> (): kotlin.Int declared in <root>'
|
||||
@@ -99,15 +99,13 @@ FILE fqName:<root> fileName:/delegatedPropertyAccessorsWithAnnotations.kt
|
||||
thisRef: CONST Null type=kotlin.Nothing? value=null
|
||||
kProp: PROPERTY_REFERENCE 'public final test1: kotlin.Int [delegated,val]' field=null getter='public final fun <get-test1> (): kotlin.Int declared in <root>' setter=null type=kotlin.reflect.KProperty0<kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE
|
||||
PROPERTY name:test2 visibility:public modality:FINAL [delegated,var]
|
||||
annotations:
|
||||
A(x = 'test2.get')
|
||||
A(x = 'test2.set')
|
||||
A(x = 'test2.set.param')
|
||||
FIELD PROPERTY_DELEGATE name:test2$delegate type:<root>.Cell visibility:private [final,static]
|
||||
EXPRESSION_BODY
|
||||
CONSTRUCTOR_CALL 'public constructor <init> (value: kotlin.Int) [primary] declared in <root>.Cell' type=<root>.Cell origin=null
|
||||
value: CONST Int type=kotlin.Int value=2
|
||||
FUN DELEGATED_PROPERTY_ACCESSOR name:<get-test2> visibility:public modality:FINAL <> () returnType:kotlin.Int
|
||||
annotations:
|
||||
A(x = 'test2.get')
|
||||
correspondingProperty: PROPERTY name:test2 visibility:public modality:FINAL [delegated,var]
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-test2> (): kotlin.Int declared in <root>'
|
||||
@@ -116,8 +114,12 @@ FILE fqName:<root> fileName:/delegatedPropertyAccessorsWithAnnotations.kt
|
||||
thisRef: CONST Null type=kotlin.Nothing? value=null
|
||||
kProp: PROPERTY_REFERENCE 'public final test2: kotlin.Int [delegated,var]' field=null getter='public final fun <get-test2> (): kotlin.Int declared in <root>' setter='public final fun <set-test2> (<set-?>: kotlin.Int): kotlin.Unit declared in <root>' type=kotlin.reflect.KMutableProperty0<kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE
|
||||
FUN DELEGATED_PROPERTY_ACCESSOR name:<set-test2> visibility:public modality:FINAL <> (<set-?>:kotlin.Int) returnType:kotlin.Unit
|
||||
annotations:
|
||||
A(x = 'test2.set')
|
||||
correspondingProperty: PROPERTY name:test2 visibility:public modality:FINAL [delegated,var]
|
||||
VALUE_PARAMETER name:<set-?> index:0 type:kotlin.Int
|
||||
annotations:
|
||||
A(x = 'test2.set.param')
|
||||
BLOCK_BODY
|
||||
CALL 'public final fun setValue (thisRef: kotlin.Any?, kProp: kotlin.Any?, newValue: kotlin.Int): kotlin.Unit [operator] declared in <root>.Cell' type=kotlin.Unit origin=null
|
||||
$this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:test2$delegate type:<root>.Cell visibility:private [final,static]' type=<root>.Cell origin=null
|
||||
|
||||
+4
-4
@@ -28,9 +28,9 @@ FILE fqName:<root> fileName:/fieldsWithAnnotations.kt
|
||||
public open fun toString (): kotlin.String declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
PROPERTY name:testVal visibility:public modality:FINAL [val]
|
||||
annotations:
|
||||
TestAnn(x = 'testVal.field')
|
||||
FIELD PROPERTY_BACKING_FIELD name:testVal type:kotlin.String visibility:private [final,static]
|
||||
annotations:
|
||||
TestAnn(x = 'testVal.field')
|
||||
EXPRESSION_BODY
|
||||
CONST String type=kotlin.String value="a val"
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-testVal> visibility:public modality:FINAL <> () returnType:kotlin.String
|
||||
@@ -39,9 +39,9 @@ FILE fqName:<root> fileName:/fieldsWithAnnotations.kt
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-testVal> (): kotlin.String declared in <root>'
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:testVal type:kotlin.String visibility:private [final,static]' type=kotlin.String origin=null
|
||||
PROPERTY name:testVar visibility:public modality:FINAL [var]
|
||||
annotations:
|
||||
TestAnn(x = 'testVar.field')
|
||||
FIELD PROPERTY_BACKING_FIELD name:testVar type:kotlin.String visibility:private [static]
|
||||
annotations:
|
||||
TestAnn(x = 'testVar.field')
|
||||
EXPRESSION_BODY
|
||||
CONST String type=kotlin.String value="a var"
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-testVar> visibility:public modality:FINAL <> () returnType:kotlin.String
|
||||
|
||||
-2
@@ -25,8 +25,6 @@ FILE fqName:<root> fileName:/primaryConstructorParameterWithAnnotations.kt
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test modality:FINAL visibility:public superTypes:[kotlin.Any]'
|
||||
PROPERTY name:x visibility:public modality:FINAL [val]
|
||||
annotations:
|
||||
Ann
|
||||
FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:private [final]
|
||||
EXPRESSION_BODY
|
||||
GET_VAR 'x: kotlin.Int declared in <root>.Test.<init>' type=kotlin.Int origin=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
|
||||
+6
-5
@@ -41,12 +41,12 @@ FILE fqName:<root> fileName:/propertyAccessorsFromClassHeaderWithAnnotations.kt
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]'
|
||||
PROPERTY name:x visibility:public modality:FINAL [val]
|
||||
annotations:
|
||||
A(x = 'C.x.get')
|
||||
FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:private [final]
|
||||
EXPRESSION_BODY
|
||||
GET_VAR 'x: kotlin.Int declared in <root>.C.<init>' type=kotlin.Int origin=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-x> visibility:public modality:FINAL <> ($this:<root>.C) returnType:kotlin.Int
|
||||
annotations:
|
||||
A(x = 'C.x.get')
|
||||
correspondingProperty: PROPERTY name:x visibility:public modality:FINAL [val]
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.C
|
||||
BLOCK_BODY
|
||||
@@ -54,13 +54,12 @@ FILE fqName:<root> fileName:/propertyAccessorsFromClassHeaderWithAnnotations.kt
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=null
|
||||
receiver: GET_VAR '<this>: <root>.C declared in <root>.C.<get-x>' type=<root>.C origin=null
|
||||
PROPERTY name:y visibility:public modality:FINAL [var]
|
||||
annotations:
|
||||
A(x = 'C.y.get')
|
||||
A(x = 'C.y.set')
|
||||
FIELD PROPERTY_BACKING_FIELD name:y type:kotlin.Int visibility:private
|
||||
EXPRESSION_BODY
|
||||
GET_VAR 'y: kotlin.Int declared in <root>.C.<init>' type=kotlin.Int origin=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-y> visibility:public modality:FINAL <> ($this:<root>.C) returnType:kotlin.Int
|
||||
annotations:
|
||||
A(x = 'C.y.get')
|
||||
correspondingProperty: PROPERTY name:y visibility:public modality:FINAL [var]
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.C
|
||||
BLOCK_BODY
|
||||
@@ -68,6 +67,8 @@ FILE fqName:<root> fileName:/propertyAccessorsFromClassHeaderWithAnnotations.kt
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:y type:kotlin.Int visibility:private' type=kotlin.Int origin=null
|
||||
receiver: GET_VAR '<this>: <root>.C declared in <root>.C.<get-y>' type=<root>.C origin=null
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<set-y> visibility:public modality:FINAL <> ($this:<root>.C, <set-?>:kotlin.Int) returnType:kotlin.Unit
|
||||
annotations:
|
||||
A(x = 'C.y.set')
|
||||
correspondingProperty: PROPERTY name:y visibility:public modality:FINAL [var]
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.C
|
||||
VALUE_PARAMETER name:<set-?> index:0 type:kotlin.Int
|
||||
|
||||
Vendored
+6
-5
@@ -50,29 +50,30 @@ FILE fqName:<root> fileName:/propertyAccessorsWithAnnotations.kt
|
||||
VALUE_PARAMETER name:value index:0 type:kotlin.String
|
||||
BLOCK_BODY
|
||||
PROPERTY name:test3 visibility:public modality:FINAL [val]
|
||||
annotations:
|
||||
TestAnn(x = 'test3.get')
|
||||
FIELD PROPERTY_BACKING_FIELD name:test3 type:kotlin.String visibility:private [final,static]
|
||||
EXPRESSION_BODY
|
||||
CONST String type=kotlin.String value=""
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test3> visibility:public modality:FINAL <> () returnType:kotlin.String
|
||||
annotations:
|
||||
TestAnn(x = 'test3.get')
|
||||
correspondingProperty: PROPERTY name:test3 visibility:public modality:FINAL [val]
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-test3> (): kotlin.String declared in <root>'
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test3 type:kotlin.String visibility:private [final,static]' type=kotlin.String origin=null
|
||||
PROPERTY name:test4 visibility:public modality:FINAL [var]
|
||||
annotations:
|
||||
TestAnn(x = 'test4.get')
|
||||
TestAnn(x = 'test4.set')
|
||||
FIELD PROPERTY_BACKING_FIELD name:test4 type:kotlin.String visibility:private [static]
|
||||
EXPRESSION_BODY
|
||||
CONST String type=kotlin.String value=""
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test4> visibility:public modality:FINAL <> () returnType:kotlin.String
|
||||
annotations:
|
||||
TestAnn(x = 'test4.get')
|
||||
correspondingProperty: PROPERTY name:test4 visibility:public modality:FINAL [var]
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-test4> (): kotlin.String declared in <root>'
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test4 type:kotlin.String visibility:private [static]' type=kotlin.String origin=null
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<set-test4> visibility:public modality:FINAL <> (<set-?>:kotlin.String) returnType:kotlin.Unit
|
||||
annotations:
|
||||
TestAnn(x = 'test4.set')
|
||||
correspondingProperty: PROPERTY name:test4 visibility:public modality:FINAL [var]
|
||||
VALUE_PARAMETER name:<set-?> index:0 type:kotlin.String
|
||||
BLOCK_BODY
|
||||
|
||||
Vendored
+4
-4
@@ -16,8 +16,6 @@ FILE fqName:<root> fileName:/propertySetterParameterWithAnnotations.kt
|
||||
public open fun toString (): kotlin.String declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
PROPERTY name:p visibility:public modality:FINAL [var]
|
||||
annotations:
|
||||
AnnParam
|
||||
FIELD PROPERTY_BACKING_FIELD name:p type:kotlin.Int visibility:private [static]
|
||||
EXPRESSION_BODY
|
||||
CONST Int type=kotlin.Int value=0
|
||||
@@ -29,6 +27,8 @@ FILE fqName:<root> fileName:/propertySetterParameterWithAnnotations.kt
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<set-p> visibility:public modality:FINAL <> (<set-?>:kotlin.Int) returnType:kotlin.Unit
|
||||
correspondingProperty: PROPERTY name:p visibility:public modality:FINAL [var]
|
||||
VALUE_PARAMETER name:<set-?> index:0 type:kotlin.Int
|
||||
annotations:
|
||||
AnnParam
|
||||
BLOCK_BODY
|
||||
SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:p type:kotlin.Int visibility:private [static]' type=kotlin.Unit origin=null
|
||||
value: GET_VAR '<set-?>: kotlin.Int declared in <root>.<set-p>' type=kotlin.Int origin=null
|
||||
@@ -42,8 +42,6 @@ FILE fqName:<root> fileName:/propertySetterParameterWithAnnotations.kt
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]'
|
||||
PROPERTY name:p visibility:public modality:FINAL [var]
|
||||
annotations:
|
||||
AnnParam
|
||||
FIELD PROPERTY_BACKING_FIELD name:p type:kotlin.Int visibility:private
|
||||
EXPRESSION_BODY
|
||||
GET_VAR 'p: kotlin.Int declared in <root>.C.<init>' type=kotlin.Int origin=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
@@ -58,6 +56,8 @@ FILE fqName:<root> fileName:/propertySetterParameterWithAnnotations.kt
|
||||
correspondingProperty: PROPERTY name:p visibility:public modality:FINAL [var]
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.C
|
||||
VALUE_PARAMETER name:<set-?> index:0 type:kotlin.Int
|
||||
annotations:
|
||||
AnnParam
|
||||
BLOCK_BODY
|
||||
SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:p type:kotlin.Int visibility:private' type=kotlin.Unit origin=null
|
||||
receiver: GET_VAR '<this>: <root>.C declared in <root>.C.<set-p>' type=<root>.C origin=null
|
||||
|
||||
Reference in New Issue
Block a user