JVM IR: optimize isStaticInlineClassReplacementDelegatingCall

Static inline class replacements are possible only in inline classes.

Iterating over class declarations here took ~0.5% of backend time on
average projects, and up to 4% of total compilation time on degenerate
projects such as the one in KT-20055.
This commit is contained in:
Alexander Udalov
2022-01-31 15:04:11 +01:00
parent 6e999f6e84
commit d0f958d7a1
@@ -42,10 +42,16 @@ private fun IrFunction.isBridgeToSuspendImplMethod(): Boolean =
it.name.asString() == name.asString() + SUSPEND_IMPL_NAME_SUFFIX && it.attributeOwnerId == attributeOwnerId
}
private fun IrFunction.isStaticInlineClassReplacementDelegatingCall(): Boolean =
this is IrAttributeContainer && !isStaticInlineClassReplacement &&
(parent as? IrClass)?.declarations?.find { it is IrAttributeContainer && it.attributeOwnerId == attributeOwnerId && it !== this }
?.isStaticInlineClassReplacement == true
private fun IrFunction.isStaticInlineClassReplacementDelegatingCall(): Boolean {
if (this !is IrAttributeContainer || isStaticInlineClassReplacement) return false
val parentClass = parent as? IrClass ?: return false
if (!parentClass.isSingleFieldValueClass) return false
return parentClass.declarations.find {
it is IrAttributeContainer && it.attributeOwnerId == attributeOwnerId && it !== this
}?.isStaticInlineClassReplacement == true
}
private val BRIDGE_ORIGINS = setOf(
IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER,