Skip to content

Commit 21231f5

Browse files
andrey-mogilevSpace Team
authored andcommitted
[JVM] avoid unnecessary spills of some dead locals
Workaround for detection of "will be visible by debugger" dead locals. Helps to avoid unnecessary spills, and, in particular, a case where the slot of such local becomes uninitialized on some paths after adding a state machine. ^KT-79276 Fixed
1 parent 4297254 commit 21231f5

File tree

31 files changed

+288
-1
lines changed

31 files changed

+288
-1
lines changed

analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLBlackBoxTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLReversedBlackBoxTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineTransformerMethodVisitor.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,19 @@ class CoroutineTransformerMethodVisitor(
965965
}
966966
cursor = cursor.next
967967
}
968-
return true
968+
969+
// TODO KT-79682 Below is a temporary workaround for KT-79276, it shall be removed or extended with the proper "full" fix
970+
// Check whether the variable range has meaningful operations in it
971+
cursor = local.start
972+
while (cursor != null && cursor != local.end) {
973+
if (cursor.isMeaningful) {
974+
// found at least one meaningful operation
975+
return true
976+
}
977+
cursor = cursor.next
978+
}
979+
980+
return false
969981
}
970982

971983
private fun mapFieldNameToVariable(

compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// WITH_STDLIB
2+
// WITH_COROUTINES
3+
import helpers.*
4+
import kotlin.coroutines.*
5+
6+
val traceResult = StringBuilder()
7+
8+
fun trace(o : Any) {
9+
traceResult.append(o)
10+
}
11+
12+
fun builder(c: suspend () -> Unit) {
13+
c.startCoroutine(EmptyContinuation)
14+
}
15+
16+
class Test {
17+
suspend fun someSuspendFun(): Unit = trace("S")
18+
19+
fun test(): Unit {
20+
builder {
21+
1F.also { trace(it) }
22+
try {
23+
someSuspendFun()
24+
} catch (throwable: Throwable) {
25+
someSuspendFun()
26+
throw throwable
27+
} finally {
28+
2.also { trace(it) }
29+
}
30+
}
31+
}
32+
}
33+
34+
fun box(): String {
35+
Test().test()
36+
return if (traceResult.toString() == "" + 1F + "S" + 2) "OK" else "FAIL: $traceResult"
37+
}

compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/inlineScopes/FirBlackBoxCodegenTestWithInlineScopesGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)