JVM_IR don't inline temporary val for 'when' subject

This commit is contained in:
Dmitry Petrov
2021-08-23 21:00:55 +03:00
committed by TeamCityServer
parent f4a1e27124
commit f4dd75e769
2 changed files with 9 additions and 6 deletions
@@ -393,6 +393,14 @@ class JvmOptimizationLowering(val context: JvmBackendContext) : FileLoweringPass
dontTouchTemporaryVals.add(safeCall.tmpVal)
}
if (expression.origin == IrStatementOrigin.WHEN) {
// Don't optimize out 'when' subject - otherwise we might get somewhat weird debugging behavior.
val subject = expression.statements.firstOrNull()
if (subject is IrVariable) {
dontTouchTemporaryVals.add(subject)
}
}
expression.transformChildren(this, data)
removeUnnecessaryTemporaryVariables(expression.statements)
return expression
+1 -6
View File
@@ -12,14 +12,9 @@ fun box() {
}
// JVM_IR and JVM backends have different heuristics for when to use a switch.
// JVM_IR does not use a switch in this case and therefore steps to the evaluation
// of the condition for each of the cases.
// 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