From d0f958d7a1a930671324592451e676cd11b22be7 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 31 Jan 2022 15:04:11 +0100 Subject: [PATCH] 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. --- .../kotlin/backend/jvm/ir/JvmIrCoroutineUtils.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrCoroutineUtils.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrCoroutineUtils.kt index 918f4151faa..5fdb7b12fb9 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrCoroutineUtils.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrCoroutineUtils.kt @@ -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,