Don't delete nested default lambda classes during inline transformation

This commit is contained in:
Mikhael Bogdanov
2017-12-21 10:04:02 +01:00
parent b65dcf27ee
commit 50608d0844
14 changed files with 350 additions and 2 deletions
@@ -166,7 +166,7 @@ class DefaultLambda(
classReader.b,
invokeMethod.name,
invokeMethod.descriptor,
lambdaClassType)!!
lambdaClassType) ?: error("Can't find method '${invokeMethod.name}${invokeMethod.descriptor}' in '${classReader.className}'")
if (needReification) {
//nested classes could also require reification
@@ -165,7 +165,9 @@ class MethodInliner(
result.merge(transformResult)
result.addChangedType(oldClassName, newClassName)
if (inliningContext.isInliningLambda && transformationInfo!!.canRemoveAfterTransformation()) {
if (inliningContext.isInliningLambda &&
inliningContext.lambdaInfo !is DefaultLambda && //never delete default lambda classes
transformationInfo!!.canRemoveAfterTransformation()) {
// this class is transformed and original not used so we should remove original one after inlining
result.addClassToRemove(oldClassName)
}
@@ -0,0 +1,17 @@
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
inline fun test(p: String, s: () -> () -> String = { { p } }) =
s()
val same = test("O")
// FILE: 2.kt
import test.*
fun box(): String {
val inlined = test("K")
return same() + inlined()
}
@@ -0,0 +1,17 @@
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
inline fun test(p: String, s: () -> () -> () -> String = { { { p } } }) =
s()
val same = test("O")
// FILE: 2.kt
import test.*
fun box(): String {
val inlined = test("K")
return same()() + inlined()()
}
@@ -0,0 +1,24 @@
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
interface Call {
fun run(): String
}
inline fun test(p: String, s: () -> Call = {
object : Call {
override fun run() = p
} as Call
}) = s()
val same = test("O")
// FILE: 2.kt
import test.*
fun box(): String {
val inlined = test("K")
return same.run() + inlined.run()
}
@@ -0,0 +1,18 @@
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
inline fun test(s: () -> () -> String = { { "OK" } }) =
s()
val same = test()
// FILE: 2.kt
import test.*
fun box(): String {
val inlined = test()
if (same() != "OK") return "fail 1: ${same()}"
return inlined()
}
@@ -0,0 +1,18 @@
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
inline fun test(s: () -> () -> () -> String = { { { "OK" } } }) =
s()
val same = test()
// FILE: 2.kt
import test.*
fun box(): String {
val inlined = test()
if (same()() != "OK") return "fail 1: ${same()()}"
return inlined()()
}
@@ -0,0 +1,25 @@
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
interface Call {
fun run(): String
}
inline fun test(s: () -> Call = {
object : Call {
override fun run() = "OK"
} as Call
}) = s()
val same = test()
// FILE: 2.kt
import test.*
fun box(): String {
val inlined = test()
if (same.run() != "OK") return "fail 1: ${same.run()}"
return inlined.run()
}
@@ -0,0 +1,17 @@
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
inline fun <T> test(p: T, s: () -> () -> T = { { p } }) =
s()
val same = test("O")
// FILE: 2.kt
import test.*
fun box(): String {
val inlined = test("K")
return same() + inlined()
}
@@ -1210,6 +1210,42 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("checkLambdaClassIsPresent.kt")
public void testCheckLambdaClassIsPresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkLambdaClassIsPresent.kt");
doTest(fileName);
}
@TestMetadata("checkLambdaClassesArePresent.kt")
public void testCheckLambdaClassesArePresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkLambdaClassesArePresent.kt");
doTest(fileName);
}
@TestMetadata("checkObjectClassIsPresent.kt")
public void testCheckObjectClassIsPresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkObjectClassIsPresent.kt");
doTest(fileName);
}
@TestMetadata("checkStaticLambdaClassIsPresent.kt")
public void testCheckStaticLambdaClassIsPresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkStaticLambdaClassIsPresent.kt");
doTest(fileName);
}
@TestMetadata("checkStaticLambdaClassesArePresent.kt")
public void testCheckStaticLambdaClassesArePresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkStaticLambdaClassesArePresent.kt");
doTest(fileName);
}
@TestMetadata("checkStaticObjectClassIsPresent.kt")
public void testCheckStaticObjectClassIsPresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkStaticObjectClassIsPresent.kt");
doTest(fileName);
}
@TestMetadata("defaultCallInDefaultLambda.kt")
public void testDefaultCallInDefaultLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/defaultCallInDefaultLambda.kt");
@@ -1222,6 +1258,12 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli
doTest(fileName);
}
@TestMetadata("genericLambda.kt")
public void testGenericLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/genericLambda.kt");
doTest(fileName);
}
@TestMetadata("instanceCapuredInClass.kt")
public void testInstanceCapuredInClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/instanceCapuredInClass.kt");
@@ -1210,6 +1210,42 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("checkLambdaClassIsPresent.kt")
public void testCheckLambdaClassIsPresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkLambdaClassIsPresent.kt");
doTest(fileName);
}
@TestMetadata("checkLambdaClassesArePresent.kt")
public void testCheckLambdaClassesArePresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkLambdaClassesArePresent.kt");
doTest(fileName);
}
@TestMetadata("checkObjectClassIsPresent.kt")
public void testCheckObjectClassIsPresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkObjectClassIsPresent.kt");
doTest(fileName);
}
@TestMetadata("checkStaticLambdaClassIsPresent.kt")
public void testCheckStaticLambdaClassIsPresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkStaticLambdaClassIsPresent.kt");
doTest(fileName);
}
@TestMetadata("checkStaticLambdaClassesArePresent.kt")
public void testCheckStaticLambdaClassesArePresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkStaticLambdaClassesArePresent.kt");
doTest(fileName);
}
@TestMetadata("checkStaticObjectClassIsPresent.kt")
public void testCheckStaticObjectClassIsPresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkStaticObjectClassIsPresent.kt");
doTest(fileName);
}
@TestMetadata("defaultCallInDefaultLambda.kt")
public void testDefaultCallInDefaultLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/defaultCallInDefaultLambda.kt");
@@ -1222,6 +1258,12 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC
doTest(fileName);
}
@TestMetadata("genericLambda.kt")
public void testGenericLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/genericLambda.kt");
doTest(fileName);
}
@TestMetadata("instanceCapuredInClass.kt")
public void testInstanceCapuredInClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/instanceCapuredInClass.kt");
@@ -1210,6 +1210,42 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("checkLambdaClassIsPresent.kt")
public void testCheckLambdaClassIsPresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkLambdaClassIsPresent.kt");
doTest(fileName);
}
@TestMetadata("checkLambdaClassesArePresent.kt")
public void testCheckLambdaClassesArePresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkLambdaClassesArePresent.kt");
doTest(fileName);
}
@TestMetadata("checkObjectClassIsPresent.kt")
public void testCheckObjectClassIsPresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkObjectClassIsPresent.kt");
doTest(fileName);
}
@TestMetadata("checkStaticLambdaClassIsPresent.kt")
public void testCheckStaticLambdaClassIsPresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkStaticLambdaClassIsPresent.kt");
doTest(fileName);
}
@TestMetadata("checkStaticLambdaClassesArePresent.kt")
public void testCheckStaticLambdaClassesArePresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkStaticLambdaClassesArePresent.kt");
doTest(fileName);
}
@TestMetadata("checkStaticObjectClassIsPresent.kt")
public void testCheckStaticObjectClassIsPresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkStaticObjectClassIsPresent.kt");
doTest(fileName);
}
@TestMetadata("defaultCallInDefaultLambda.kt")
public void testDefaultCallInDefaultLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/defaultCallInDefaultLambda.kt");
@@ -1222,6 +1258,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
doTest(fileName);
}
@TestMetadata("genericLambda.kt")
public void testGenericLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/genericLambda.kt");
doTest(fileName);
}
@TestMetadata("instanceCapuredInClass.kt")
public void testInstanceCapuredInClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/instanceCapuredInClass.kt");
@@ -1210,6 +1210,42 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("checkLambdaClassIsPresent.kt")
public void testCheckLambdaClassIsPresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkLambdaClassIsPresent.kt");
doTest(fileName);
}
@TestMetadata("checkLambdaClassesArePresent.kt")
public void testCheckLambdaClassesArePresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkLambdaClassesArePresent.kt");
doTest(fileName);
}
@TestMetadata("checkObjectClassIsPresent.kt")
public void testCheckObjectClassIsPresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkObjectClassIsPresent.kt");
doTest(fileName);
}
@TestMetadata("checkStaticLambdaClassIsPresent.kt")
public void testCheckStaticLambdaClassIsPresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkStaticLambdaClassIsPresent.kt");
doTest(fileName);
}
@TestMetadata("checkStaticLambdaClassesArePresent.kt")
public void testCheckStaticLambdaClassesArePresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkStaticLambdaClassesArePresent.kt");
doTest(fileName);
}
@TestMetadata("checkStaticObjectClassIsPresent.kt")
public void testCheckStaticObjectClassIsPresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkStaticObjectClassIsPresent.kt");
doTest(fileName);
}
@TestMetadata("defaultCallInDefaultLambda.kt")
public void testDefaultCallInDefaultLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/defaultCallInDefaultLambda.kt");
@@ -1222,6 +1258,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
doTest(fileName);
}
@TestMetadata("genericLambda.kt")
public void testGenericLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/genericLambda.kt");
doTest(fileName);
}
@TestMetadata("instanceCapuredInClass.kt")
public void testInstanceCapuredInClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/instanceCapuredInClass.kt");
@@ -158,6 +158,42 @@ public class InlineDefaultValuesTestsGenerated extends AbstractInlineDefaultValu
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
}
@TestMetadata("checkLambdaClassIsPresent.kt")
public void testCheckLambdaClassIsPresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkLambdaClassIsPresent.kt");
doTest(fileName);
}
@TestMetadata("checkLambdaClassesArePresent.kt")
public void testCheckLambdaClassesArePresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkLambdaClassesArePresent.kt");
doTest(fileName);
}
@TestMetadata("checkObjectClassIsPresent.kt")
public void testCheckObjectClassIsPresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkObjectClassIsPresent.kt");
doTest(fileName);
}
@TestMetadata("checkStaticLambdaClassIsPresent.kt")
public void testCheckStaticLambdaClassIsPresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkStaticLambdaClassIsPresent.kt");
doTest(fileName);
}
@TestMetadata("checkStaticLambdaClassesArePresent.kt")
public void testCheckStaticLambdaClassesArePresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkStaticLambdaClassesArePresent.kt");
doTest(fileName);
}
@TestMetadata("checkStaticObjectClassIsPresent.kt")
public void testCheckStaticObjectClassIsPresent() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/checkStaticObjectClassIsPresent.kt");
doTest(fileName);
}
@TestMetadata("defaultCallInDefaultLambda.kt")
public void testDefaultCallInDefaultLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/defaultCallInDefaultLambda.kt");
@@ -170,6 +206,12 @@ public class InlineDefaultValuesTestsGenerated extends AbstractInlineDefaultValu
doTest(fileName);
}
@TestMetadata("genericLambda.kt")
public void testGenericLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/genericLambda.kt");
doTest(fileName);
}
@TestMetadata("instanceCapuredInClass.kt")
public void testInstanceCapuredInClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/instanceCapuredInClass.kt");