From 42057b7fe053bee0bfb8ccce219add11fd2bfba7 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 16 Jun 2023 23:56:05 +0200 Subject: [PATCH] IR: do not copy call in ForLoopsLowering This is just a refactoring/optimization that makes use of the fact that IrCall.symbol is now mutable. --- .../common/lower/loops/ForLoopsLowering.kt | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/ForLoopsLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/ForLoopsLowering.kt index 14beece0beb..572ccce8c2d 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/ForLoopsLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/ForLoopsLowering.kt @@ -17,12 +17,14 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrSymbolOwner import org.jetbrains.kotlin.ir.declarations.IrVariable import org.jetbrains.kotlin.ir.expressions.* -import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl import org.jetbrains.kotlin.ir.expressions.impl.IrCompositeImpl import org.jetbrains.kotlin.ir.types.getClass import org.jetbrains.kotlin.ir.types.isNothing import org.jetbrains.kotlin.ir.types.isStrictSubtypeOfClass -import org.jetbrains.kotlin.ir.util.* +import org.jetbrains.kotlin.ir.util.dump +import org.jetbrains.kotlin.ir.util.functions +import org.jetbrains.kotlin.ir.util.hasEqualFqName +import org.jetbrains.kotlin.ir.util.render import org.jetbrains.kotlin.ir.visitors.* import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.util.OperatorNameConventions @@ -343,14 +345,10 @@ private class RangeLoopTransformer( val loopCondition = loop.condition as? IrCall ?: return loopCondition.dispatchReceiver?.type = receiverType - val nextCall = loopVariable.initializer as? IrCall ?: return - loopVariable.initializer = with(nextCall) { - IrCallImpl( - startOffset, endOffset, type, next.symbol, typeArgumentsCount, valueArgumentsCount, origin, superQualifierSymbol - ).apply { - copyTypeAndValueArgumentsFrom(nextCall) - dispatchReceiver?.type = receiverType - } + val nextCall = loopVariable.initializer + if (nextCall is IrCall) { + nextCall.symbol = next.symbol + nextCall.dispatchReceiver?.type = receiverType } }