Eliminated yet another descriptor use in lowerings
This commit is contained in:
committed by
alexander-gorshenev
parent
2c31173725
commit
e9685e8d17
+9
-9
@@ -74,7 +74,9 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa
|
||||
}
|
||||
|
||||
override fun lower(irFile: IrFile) {
|
||||
val kProperties = mutableMapOf<VariableDescriptorWithAccessors, Pair<IrExpression, Int>>()
|
||||
// Somehow there is no reasonable common ancestor for IrProperty and IrLocalDelegatedProperty,
|
||||
// so index by IrDeclaration.
|
||||
val kProperties = mutableMapOf<IrDeclaration, Pair<IrExpression, Int>>()
|
||||
|
||||
val arrayClass = context.ir.symbols.array.owner
|
||||
|
||||
@@ -121,7 +123,7 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa
|
||||
2 -> error("Callable reference to properties with two receivers is not allowed: ${expression.descriptor}")
|
||||
|
||||
else -> { // Cache KProperties with no arguments.
|
||||
val field = kProperties.getOrPut(expression.descriptor) {
|
||||
val field = kProperties.getOrPut(expression.symbol.owner) {
|
||||
createKProperty(expression, this) to kProperties.size
|
||||
}
|
||||
|
||||
@@ -141,16 +143,14 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa
|
||||
val endOffset = expression.endOffset
|
||||
val irBuilder = context.createIrBuilder(currentScope!!.scope.scopeOwnerSymbol, startOffset, endOffset)
|
||||
irBuilder.run {
|
||||
val propertyDescriptor = expression.descriptor
|
||||
|
||||
val receiversCount = listOf(expression.dispatchReceiver, expression.extensionReceiver).count { it != null }
|
||||
if (receiversCount == 2)
|
||||
throw AssertionError("Callable reference to properties with two receivers is not allowed: $propertyDescriptor")
|
||||
throw AssertionError("Callable reference to properties with two receivers is not allowed: ${expression}")
|
||||
else { // Cache KProperties with no arguments.
|
||||
// TODO: what about `receiversCount == 1` case?
|
||||
val field = kProperties.getOrPut(propertyDescriptor) {
|
||||
val field = kProperties.getOrPut(expression.symbol.owner) {
|
||||
createLocalKProperty(
|
||||
propertyDescriptor,
|
||||
expression.symbol.owner.name.asString(),
|
||||
expression.getter.owner.returnType,
|
||||
this
|
||||
) to kProperties.size
|
||||
@@ -265,7 +265,7 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa
|
||||
}
|
||||
}
|
||||
|
||||
private fun createLocalKProperty(propertyDescriptor: VariableDescriptorWithAccessors,
|
||||
private fun createLocalKProperty(propertyName: String,
|
||||
propertyType: IrType,
|
||||
irBuilder: IrBuilderWithScope): IrExpression {
|
||||
irBuilder.run {
|
||||
@@ -275,7 +275,7 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa
|
||||
isLocal = true,
|
||||
isMutable = false)
|
||||
val initializer = irCall(symbol.owner, constructorTypeArguments).apply {
|
||||
putValueArgument(0, irString(propertyDescriptor.name.asString()))
|
||||
putValueArgument(0, irString(propertyName))
|
||||
putValueArgument(1, with(kTypeGenerator) { irKType(propertyType) })
|
||||
}
|
||||
return initializer
|
||||
|
||||
Reference in New Issue
Block a user