diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index 72c0f2e4a6e..9b52ae4b9fc 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -646,11 +646,6 @@ class ExpressionCodegen( return MaterialValue(this, type, expression.symbol.owner.realType) } - private fun IrValueDeclaration.isTemporaryVal() = - this is IrVariable && - !this.isVar && - this.origin == IrDeclarationOrigin.IR_TEMPORARY_VARIABLE - internal fun genOrGetLocal(expression: IrExpression, type: Type, parameterType: IrType, data: BlockInfo): StackValue = if (expression is IrGetValue) StackValue.local( @@ -1229,7 +1224,7 @@ class ExpressionCodegen( val afterStore = markNewLabel() val catchBody = clause.result - var catchBlockInfo = BlockInfo(data) + val catchBlockInfo = BlockInfo(data) catchBlockInfo.variables.add(VariableInfo(parameter, index, descriptorType, afterStore)) val catchResult = catchBody.accept(this, catchBlockInfo) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmOptimizationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmOptimizationLowering.kt index 837168de29b..bb8fe1087dd 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmOptimizationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmOptimizationLowering.kt @@ -322,7 +322,10 @@ class JvmOptimizationLowering(val context: JvmBackendContext) : FileLoweringPass initializer } is IrValueParameter -> - return initializer + return if (initializerValue.isAssignable) + null + else + initializer } } @@ -394,9 +397,10 @@ class JvmOptimizationLowering(val context: JvmBackendContext) : FileLoweringPass } if (expression.origin == IrStatementOrigin.WHEN) { - // Don't optimize out 'when' subject - otherwise we might get somewhat weird debugging behavior. + // Don't optimize out 'when' subject initialized with a variable, + // otherwise we might get somewhat weird debugging behavior. val subject = expression.statements.firstOrNull() - if (subject is IrVariable) { + if (subject is IrVariable && subject.initializer is IrGetValue) { dontTouchTemporaryVals.add(subject) } } diff --git a/compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/safeCallWithReturnValue.kt b/compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/safeCallWithReturnValue.kt index 00019742547..b9158e9a009 100644 --- a/compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/safeCallWithReturnValue.kt +++ b/compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/safeCallWithReturnValue.kt @@ -8,10 +8,5 @@ fun test(x: A?) { x?.foo() } -// JVM_TEMPLATES // 2 POP // 0 ACONST_NULL - -// JVM_IR_TEMPLATES -// 2 POP -// 0 ACONST_NULL \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/safeLet.kt b/compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/safeLet.kt index ef7af973d3f..5eb27d2a884 100644 --- a/compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/safeLet.kt +++ b/compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/safeLet.kt @@ -19,9 +19,4 @@ fun test(ss: List) { // 0 INVOKESTATIC java/lang/Boolean\.valueOf // 0 CHECKCAST java/lang/Boolean // 0 ACONST_NULL - -// JVM_TEMPLATES -// 2 POP - -// JVM_IR_TEMPLATES // 2 POP diff --git a/compiler/testData/codegen/bytecodeText/inline/noFakeVariableForInlineOnlyFun.kt b/compiler/testData/codegen/bytecodeText/inline/noFakeVariableForInlineOnlyFun.kt index 0b059f4f515..ab58701ee4b 100644 --- a/compiler/testData/codegen/bytecodeText/inline/noFakeVariableForInlineOnlyFun.kt +++ b/compiler/testData/codegen/bytecodeText/inline/noFakeVariableForInlineOnlyFun.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR - @Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") @kotlin.internal.InlineOnly inline fun inlineOnlyFun(): Int { diff --git a/compiler/testData/debug/stepping/whenConstant.kt b/compiler/testData/debug/stepping/whenConstant.kt index a849cd6b5f8..f508da70f08 100644 --- a/compiler/testData/debug/stepping/whenConstant.kt +++ b/compiler/testData/debug/stepping/whenConstant.kt @@ -12,9 +12,12 @@ fun box() { } // JVM_IR and JVM backends have different heuristics for when to use a switch. -// JVM_IR inlines constant value subject and folds unreachable branches. // LINENUMBERS // test.kt:4 box +// LINENUMBERS JVM_IR +// test.kt:5 box +// test.kt:7 box +// LINENUMBERS // test.kt:10 box // test.kt:12 box \ No newline at end of file