[IR] Fix saving function calls during inlining const properties in PropertyAccessorInlineLowering (#3971)

This commit is contained in:
LepilkinaElena
2020-12-10 12:24:23 +03:00
committed by GitHub
parent dccfb33bcc
commit c8c83c04c0
18 changed files with 121 additions and 44 deletions
@@ -570,3 +570,38 @@ val IrFunction.originalFunction: IrFunction
val IrProperty.originalProperty: IrProperty
get() = attributeOwnerId as? IrProperty ?: this
// TODO: support more cases like built-in operator call and so on
fun IrExpression?.isPure(anyVariable: Boolean, checkFields: Boolean = true): Boolean {
if (this == null) return true
fun IrExpression.isPureImpl(): Boolean {
return when (this) {
is IrConst<*> -> true
is IrGetValue -> {
if (anyVariable) return true
val valueDeclaration = symbol.owner
if (valueDeclaration is IrVariable) !valueDeclaration.isVar
else true
}
is IrGetObjectValue -> type.isUnit()
else -> false
}
}
if (isPureImpl()) return true
if (!checkFields) return false
if (this is IrGetField) {
if (!symbol.owner.isFinal) {
if (!anyVariable) {
return false
}
}
return receiver.isPure(anyVariable)
}
return false
}