[JVM] Do not put the name of default lambda parameter in LVT.
If we do, the local variable table will not make sense. As as
example:
```
inline fun foo(getString: () -> String = { "OK" }) {
println(getString())
}
inline fun bar() {
}
fun main() {
bar()
foo()
}
```
leads to the following bytecode:
```
public static final void main();
descriptor: ()V
flags: ACC_PUBLIC, ACC_STATIC, ACC_FINAL
Code:
stack=2, locals=4, args_size=0
0: iconst_0
1: istore_0
2: nop
3: nop
4: iconst_0
5: istore_1
6: nop
7: ldc #53 // String OK
9: astore_2
10: iconst_0
11: istore_3
12: getstatic #30 // Field java/lang/System.out:Ljava/io/PrintStream;
15: aload_2
16: invokevirtual #36 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
19: nop
20: return
LineNumberTable:
line 9: 0
line 13: 2
line 10: 3
line 14: 4
line 15: 6
line 16: 7
line 17: 19
line 11: 20
LocalVariableTable:
Start Length Slot Name Signature
2 1 0 $i$f$bar I
6 14 1 $i$f$foo I
4 16 0 getString$iv Lkotlin/jvm/functions/Function0;
```
The `getString$iv` local should not be there. It has been inlined away.
Leaving it in the local variable table leads to inconsistent locals
info. Local 0 contains an int but we declare a local of type
Function0.
This commit is contained in:
@@ -130,7 +130,9 @@ fun <T, R : DefaultLambda> expandMaskConditionsAndUpdateVariableNodes(
|
||||
node.instructions.insert(position, newInsn)
|
||||
}
|
||||
|
||||
node.localVariables.removeIf { it.start in toDelete && it.end in toDelete }
|
||||
node.localVariables.removeIf {
|
||||
(it.start in toDelete && it.end in toDelete) || defaultLambdas.contains(it.index)
|
||||
}
|
||||
|
||||
node.remove(toDelete)
|
||||
|
||||
|
||||
Generated
+5
@@ -9843,6 +9843,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/covariantOverrideGeneric.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultLambdaInline.kt")
|
||||
public void testDefaultLambdaInline() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/defaultLambdaInline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionFunctionManyArgs.kt")
|
||||
public void testExtensionFunctionManyArgs() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/extensionFunctionManyArgs.kt");
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
// Need to ignore dexing for now. This generates invalid inner-class attributes on the IR backend.
|
||||
//
|
||||
// java.lang.AssertionError: D8 dexing error: D8 dexing info: Malformed inner-class attribute:
|
||||
// outerTypeInternal: C$result$1
|
||||
// innerTypeInternal: C$no_name_in_PSI_3d19d79d_1ba9_4cd0_b7f5_b46aa3cd5d40$WhenMappings
|
||||
// innerName: WhenMappings
|
||||
//
|
||||
// IGNORE_DEXING
|
||||
|
||||
import kotlin.coroutines.*
|
||||
|
||||
fun launch(block: suspend () -> String): String {
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
inline fun f(getString: () -> String = { "OK" }) = getString()
|
||||
inline fun g() { }
|
||||
|
||||
fun box(): String {
|
||||
g()
|
||||
return f()
|
||||
}
|
||||
-3
@@ -1,6 +1,3 @@
|
||||
// Enable for dexing once we have a D8 version with a fix for
|
||||
// https://issuetracker.google.com/148661132
|
||||
// IGNORE_DEXING
|
||||
// NO_CHECK_LAMBDA_INLINING
|
||||
// FILE: 1.kt
|
||||
package test
|
||||
|
||||
-3
@@ -1,6 +1,3 @@
|
||||
// Enable for dexing once we have a D8 version with a fix for
|
||||
// https://issuetracker.google.com/148661132
|
||||
// IGNORE_DEXING
|
||||
// FILE: 1.kt
|
||||
// SKIP_INLINE_CHECK_IN: inlineFun$default
|
||||
package test
|
||||
|
||||
@@ -40,9 +40,27 @@ public class D8Checker {
|
||||
});
|
||||
}
|
||||
|
||||
// Compilation with D8 should proceed with no output. There should be no info, warnings, or errors.
|
||||
static class TestDiagnosticsHandler implements DiagnosticsHandler {
|
||||
@Override
|
||||
public void error(Diagnostic diagnostic) {
|
||||
Assert.fail("D8 dexing error: " + diagnostic.getDiagnosticMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warning(Diagnostic diagnostic) {
|
||||
Assert.fail("D8 dexing warning: " + diagnostic.getDiagnosticMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(Diagnostic diagnostic) {
|
||||
Assert.fail("D8 dexing info: " + diagnostic.getDiagnosticMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void runD8(Consumer<D8Command.Builder> addInput) {
|
||||
ProgramConsumer ignoreOutputConsumer = new DexIndexedConsumer.ForwardingConsumer(null);
|
||||
D8Command.Builder builder = D8Command.builder()
|
||||
D8Command.Builder builder = D8Command.builder(new TestDiagnosticsHandler())
|
||||
.setMinApiLevel(28)
|
||||
.setMode(CompilationMode.DEBUG)
|
||||
.setProgramConsumer(ignoreOutputConsumer);
|
||||
|
||||
+5
@@ -11243,6 +11243,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/covariantOverrideGeneric.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultLambdaInline.kt")
|
||||
public void testDefaultLambdaInline() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/defaultLambdaInline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionFunctionManyArgs.kt")
|
||||
public void testExtensionFunctionManyArgs() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/extensionFunctionManyArgs.kt");
|
||||
|
||||
+5
@@ -11243,6 +11243,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/covariantOverrideGeneric.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultLambdaInline.kt")
|
||||
public void testDefaultLambdaInline() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/defaultLambdaInline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionFunctionManyArgs.kt")
|
||||
public void testExtensionFunctionManyArgs() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/extensionFunctionManyArgs.kt");
|
||||
|
||||
+5
@@ -9843,6 +9843,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/covariantOverrideGeneric.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultLambdaInline.kt")
|
||||
public void testDefaultLambdaInline() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/defaultLambdaInline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionFunctionManyArgs.kt")
|
||||
public void testExtensionFunctionManyArgs() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/extensionFunctionManyArgs.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+5
@@ -8353,6 +8353,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/covariantOverrideGeneric.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultLambdaInline.kt")
|
||||
public void testDefaultLambdaInline() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/defaultLambdaInline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionFunctionManyArgs.kt")
|
||||
public void testExtensionFunctionManyArgs() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/extensionFunctionManyArgs.kt");
|
||||
|
||||
Generated
+5
@@ -8353,6 +8353,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/covariantOverrideGeneric.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultLambdaInline.kt")
|
||||
public void testDefaultLambdaInline() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/defaultLambdaInline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionFunctionManyArgs.kt")
|
||||
public void testExtensionFunctionManyArgs() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/extensionFunctionManyArgs.kt");
|
||||
|
||||
Generated
+5
@@ -8353,6 +8353,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/covariantOverrideGeneric.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultLambdaInline.kt")
|
||||
public void testDefaultLambdaInline() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/defaultLambdaInline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionFunctionManyArgs.kt")
|
||||
public void testExtensionFunctionManyArgs() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/extensionFunctionManyArgs.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java
Generated
+5
@@ -4033,6 +4033,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/covariantOverrideGeneric.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultLambdaInline.kt")
|
||||
public void testDefaultLambdaInline() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/defaultLambdaInline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionFunctionManyArgs.kt")
|
||||
public void testExtensionFunctionManyArgs() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/extensionFunctionManyArgs.kt");
|
||||
|
||||
Reference in New Issue
Block a user