JVM_IR: move FunctionReference lowering before PropertyReference

so that `$$delegatedProperties` are generated in the lambdas' classes.
This commit is contained in:
pyos
2020-09-25 15:34:22 +02:00
committed by Alexander Udalov
parent 1190457759
commit 4f171a9eb5
5 changed files with 13 additions and 7 deletions
@@ -96,7 +96,7 @@ class JvmBackendContext(
internal val classCodegens = mutableMapOf<IrClass, ClassCodegen>() internal val classCodegens = mutableMapOf<IrClass, ClassCodegen>()
val localDelegatedProperties = mutableMapOf<IrClass, List<IrLocalDelegatedPropertySymbol>>() val localDelegatedProperties = mutableMapOf<IrAttributeContainer, List<IrLocalDelegatedPropertySymbol>>()
internal val multifileFacadesToAdd = mutableMapOf<JvmClassName, MutableList<IrClass>>() internal val multifileFacadesToAdd = mutableMapOf<JvmClassName, MutableList<IrClass>>()
val multifileFacadeForPart = mutableMapOf<IrClass, JvmClassName>() val multifileFacadeForPart = mutableMapOf<IrClass, JvmClassName>()
@@ -289,6 +289,7 @@ private val jvmFilePhases = listOf(
moveOrCopyCompanionObjectFieldsPhase, moveOrCopyCompanionObjectFieldsPhase,
inlineCallableReferenceToLambdaPhase, inlineCallableReferenceToLambdaPhase,
functionReferencePhase,
propertyReferencePhase, propertyReferencePhase,
constPhase, constPhase,
propertiesPhase, propertiesPhase,
@@ -310,7 +311,6 @@ private val jvmFilePhases = listOf(
enumWhenPhase, enumWhenPhase,
singletonReferencesPhase, singletonReferencesPhase,
functionReferencePhase,
singleAbstractMethodPhase, singleAbstractMethodPhase,
assertionPhase, assertionPhase,
returnableBlocksPhase, returnableBlocksPhase,
@@ -37,7 +37,7 @@ class DescriptorMetadataSerializer(
} }
override fun serialize(metadata: MetadataSource): Pair<MessageLite, JvmStringTable>? { override fun serialize(metadata: MetadataSource): Pair<MessageLite, JvmStringTable>? {
val localDelegatedProperties = (irClass.attributeOwnerId as? IrClass)?.let(context.localDelegatedProperties::get) val localDelegatedProperties = context.localDelegatedProperties[irClass.attributeOwnerId]
if (localDelegatedProperties != null && localDelegatedProperties.isNotEmpty()) { if (localDelegatedProperties != null && localDelegatedProperties.isNotEmpty()) {
context.state.bindingTrace.record( context.state.bindingTrace.record(
CodegenBinding.DELEGATED_PROPERTIES_WITH_METADATA, CodegenBinding.DELEGATED_PROPERTIES_WITH_METADATA,
@@ -475,8 +475,11 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext)
0, 0,
//don't pass receivers otherwise LocalDeclarationLowering will create additional captured parameters //don't pass receivers otherwise LocalDeclarationLowering will create additional captured parameters
IrFunctionReferenceImpl( IrFunctionReferenceImpl(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, irFunctionReference.type, target, 0, irFunctionReference.reflectionTarget, null UNDEFINED_OFFSET, UNDEFINED_OFFSET, irFunctionReference.type, target,
) irFunctionReference.typeArgumentsCount, irFunctionReference.reflectionTarget, null
).apply {
copyTypeArgumentsFrom(irFunctionReference)
}
) )
} }
@@ -48,7 +48,10 @@ import org.jetbrains.kotlin.types.Variance
internal val propertyReferencePhase = makeIrFilePhase( internal val propertyReferencePhase = makeIrFilePhase(
::PropertyReferenceLowering, ::PropertyReferenceLowering,
name = "PropertyReference", name = "PropertyReference",
description = "Construct KProperty instances returned by expressions such as A::x and A()::x" description = "Construct KProperty instances returned by expressions such as A::x and A()::x",
// This must be done after contents of functions are extracted into separate classes, or else the `$$delegatedProperties`
// field will end up in the wrong class (not the one that declares the delegated property).
prerequisite = setOf(functionReferencePhase)
) )
internal class PropertyReferenceLowering(val context: JvmBackendContext) : ClassLoweringPass { internal class PropertyReferenceLowering(val context: JvmBackendContext) : ClassLoweringPass {
@@ -413,7 +416,7 @@ internal class PropertyReferenceLowering(val context: JvmBackendContext) : Class
} }
}) })
context.localDelegatedProperties[irClass.attributeOwnerId as IrClass] = context.localDelegatedProperties[irClass.attributeOwnerId] =
kProperties.keys.filterIsInstance<IrLocalDelegatedPropertySymbol>() kProperties.keys.filterIsInstance<IrLocalDelegatedPropertySymbol>()
} }
} }