JVM IR: Start fake variables for default lambdas after initialization
KT-52702
This commit is contained in:
committed by
Alexander Udalov
parent
08f18c2940
commit
194a1d1c6a
@@ -140,12 +140,11 @@ class DefaultLambda(info: ExtractedDefaultLambda, sourceCompiler: SourceCompiler
|
||||
val withFakeVariable =
|
||||
MethodNode(originNode.access, originNode.name, originNode.desc, originNode.signature, originNode.exceptions?.toTypedArray())
|
||||
val fakeVarIndex = originNode.maxLocals
|
||||
withFakeVariable.instructions.add(LdcInsnNode(0))
|
||||
withFakeVariable.instructions.add(VarInsnNode(Opcodes.ISTORE, fakeVarIndex))
|
||||
val startLabel = LabelNode().also { withFakeVariable.instructions.add(it) }
|
||||
originNode.accept(withFakeVariable)
|
||||
val startLabel =
|
||||
withFakeVariable.instructions.first as? LabelNode ?: LabelNode().apply { withFakeVariable.instructions.insert(this) }
|
||||
val endLabel = withFakeVariable.instructions.last as? LabelNode ?: LabelNode().apply { withFakeVariable.instructions.add(this) }
|
||||
withFakeVariable.instructions.insert(startLabel, VarInsnNode(Opcodes.ISTORE, fakeVarIndex))
|
||||
withFakeVariable.instructions.insert(startLabel, LdcInsnNode(0))
|
||||
|
||||
withFakeVariable.localVariables.add(
|
||||
LocalVariableNode(
|
||||
|
||||
+6
@@ -13735,6 +13735,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/kt48391.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52702.kt")
|
||||
public void testKt52702() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/kt52702.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt6382.kt")
|
||||
public void testKt6382() throws Exception {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// IGNORE_BACKEND: JS
|
||||
// Check that local variables for inline functions and inline default lambdas start
|
||||
// after they are initialized.
|
||||
|
||||
inline fun spray() {
|
||||
val a = Any()
|
||||
val b = Any()
|
||||
val c = Any()
|
||||
val d = Any()
|
||||
val e = Any()
|
||||
}
|
||||
|
||||
inline fun f(block: () -> String = { "OK" }): String = block()
|
||||
|
||||
fun box(): String {
|
||||
// On the JVM, this call adds some locals with reference types to the LVT
|
||||
// which end after the call returns.
|
||||
spray()
|
||||
// When inlining `f` we'll reuse the same slots that previously contained
|
||||
// locals with reference types for the $i$f$f and $i$a$-f-... variables.
|
||||
// Since these locals have integer types D8 would produce a warning if they
|
||||
// started before being initialized, which would cause the test to fail.
|
||||
return f()
|
||||
}
|
||||
+6
@@ -13615,6 +13615,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/kt48391.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52702.kt")
|
||||
public void testKt52702() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/kt52702.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt6382.kt")
|
||||
public void testKt6382() throws Exception {
|
||||
|
||||
+6
@@ -13735,6 +13735,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/kt48391.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52702.kt")
|
||||
public void testKt52702() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/kt52702.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt6382.kt")
|
||||
public void testKt6382() throws Exception {
|
||||
|
||||
+5
@@ -11063,6 +11063,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/kt48391.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt52702.kt")
|
||||
public void testKt52702() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/kt52702.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt6382.kt")
|
||||
public void testKt6382() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/kt6382.kt");
|
||||
|
||||
+6
@@ -10239,6 +10239,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/kt48391.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52702.kt")
|
||||
public void testKt52702() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/kt52702.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt6382.kt")
|
||||
public void testKt6382() throws Exception {
|
||||
|
||||
+6
@@ -10281,6 +10281,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/kt48391.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52702.kt")
|
||||
public void testKt52702() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/kt52702.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt6382.kt")
|
||||
public void testKt6382() throws Exception {
|
||||
|
||||
+5
@@ -9103,6 +9103,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/kt48391.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt52702.kt")
|
||||
public void testKt52702() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/kt52702.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt6382.kt")
|
||||
public void testKt6382() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/kt6382.kt");
|
||||
|
||||
+6
@@ -11227,6 +11227,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/kt48391.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52702.kt")
|
||||
public void testKt52702() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/kt52702.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt6382.kt")
|
||||
public void testKt6382() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user