[JVM] Never treat arguments to methods as locals that can be removed.
Fixes KT-44347
This commit is contained in:
@@ -119,6 +119,20 @@ fun MethodNode.removeEmptyCatchBlocks() {
|
||||
|
||||
fun MethodNode.removeUnusedLocalVariables() {
|
||||
val used = BooleanArray(maxLocals) { false }
|
||||
|
||||
// Arguments are always used whether or not they are in the local variable table
|
||||
// or used by instructions.
|
||||
var argumentIndex = 0
|
||||
val isStatic = (access and Opcodes.ACC_STATIC) != 0
|
||||
if (!isStatic) {
|
||||
used[argumentIndex++] = true
|
||||
}
|
||||
for (argumentType in Type.getArgumentTypes(desc)) {
|
||||
for (i in 0 until argumentType.size) {
|
||||
used[argumentIndex++] = true
|
||||
}
|
||||
}
|
||||
|
||||
for (insn in instructions) {
|
||||
when (insn) {
|
||||
is VarInsnNode -> {
|
||||
|
||||
+6
@@ -5591,6 +5591,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt17588.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt44347.kt")
|
||||
public void testKt44347() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt44347.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("sharedSlotsWithCapturedVars.kt")
|
||||
public void testSharedSlotsWithCapturedVars() throws Exception {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.coroutines.*
|
||||
|
||||
fun launch(block: suspend (Long) -> String): String {
|
||||
var result = ""
|
||||
block.startCoroutine(0L, Continuation(EmptyCoroutineContext) { result = it.getOrThrow() })
|
||||
return result
|
||||
}
|
||||
|
||||
suspend fun g() {}
|
||||
|
||||
class C {
|
||||
suspend fun f(i: Long): String {
|
||||
var x = 0
|
||||
listOf<Int>().map { x }
|
||||
g()
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String = launch(C()::f)
|
||||
+6
@@ -5591,6 +5591,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt17588.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt44347.kt")
|
||||
public void testKt44347() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt44347.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("sharedSlotsWithCapturedVars.kt")
|
||||
public void testSharedSlotsWithCapturedVars() throws Exception {
|
||||
|
||||
+6
@@ -5591,6 +5591,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt17588.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt44347.kt")
|
||||
public void testKt44347() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt44347.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("sharedSlotsWithCapturedVars.kt")
|
||||
public void testSharedSlotsWithCapturedVars() throws Exception {
|
||||
|
||||
+5
@@ -4878,6 +4878,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt17588.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt44347.kt")
|
||||
public void testKt44347() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt44347.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sharedSlotsWithCapturedVars.kt")
|
||||
public void testSharedSlotsWithCapturedVars() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/sharedSlotsWithCapturedVars.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+5
@@ -3993,6 +3993,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt17588.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt44347.kt")
|
||||
public void testKt44347() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt44347.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sharedSlotsWithCapturedVars.kt")
|
||||
public void testSharedSlotsWithCapturedVars() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/sharedSlotsWithCapturedVars.kt");
|
||||
|
||||
Generated
+5
@@ -3993,6 +3993,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt17588.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt44347.kt")
|
||||
public void testKt44347() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt44347.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sharedSlotsWithCapturedVars.kt")
|
||||
public void testSharedSlotsWithCapturedVars() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/sharedSlotsWithCapturedVars.kt");
|
||||
|
||||
Generated
+5
@@ -3993,6 +3993,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt17588.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt44347.kt")
|
||||
public void testKt44347() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt44347.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sharedSlotsWithCapturedVars.kt")
|
||||
public void testSharedSlotsWithCapturedVars() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/sharedSlotsWithCapturedVars.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java
Generated
+5
@@ -2864,6 +2864,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt17200.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt44347.kt")
|
||||
public void testKt44347() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt44347.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sharedSlotsWithCapturedVars.kt")
|
||||
public void testSharedSlotsWithCapturedVars() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/sharedSlotsWithCapturedVars.kt");
|
||||
|
||||
Reference in New Issue
Block a user