Compare commits

...

2 Commits

Author SHA1 Message Date
Mads Ager
6ae6dd4c27 [JVM_IR] Fix incorrect name in inner class attributes. 2020-12-03 10:51:33 +01:00
Mads Ager
d6288d785a [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.
2020-12-03 10:51:19 +01:00
14 changed files with 73 additions and 13 deletions

View File

@@ -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)

View File

@@ -9838,6 +9838,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");

View File

@@ -53,6 +53,10 @@ class IrTypeMapper(private val context: JvmBackendContext) : KotlinTypeMapperBas
}
private fun computeClassInternalName(irClass: IrClass): StringBuilder {
context.getLocalClassType(irClass)?.internalName?.let {
return StringBuilder(it)
}
val shortName = SpecialNames.safeIdentifier(irClass.name).identifier
when (val parent = irClass.parent) {
@@ -73,11 +77,6 @@ class IrTypeMapper(private val context: JvmBackendContext) : KotlinTypeMapperBas
}
}
val localClassType = context.getLocalClassType(irClass)
if (localClassType != null) {
return StringBuilder(localClassType.internalName)
}
error(
"Local class should have its name computed in InventNamesForLocalClasses: ${irClass.fqNameWhenAvailable}\n" +
"Ensure that any lowering that transforms elements with local class info (classes, function references) " +

View File

@@ -0,0 +1,7 @@
inline fun f(getString: () -> String = { "OK" }) = getString()
inline fun g() { }
fun box(): String {
g()
return f()
}

View File

@@ -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

View File

@@ -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

View File

@@ -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);

View File

@@ -11238,6 +11238,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");

View File

@@ -11238,6 +11238,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");

View File

@@ -9838,6 +9838,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");

View File

@@ -8348,6 +8348,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");

View File

@@ -8348,6 +8348,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");

View File

@@ -8348,6 +8348,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");

View File

@@ -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");