Fix OOM when there are several lambdas with extension function types

#KT-41335 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2020-08-26 10:43:55 +03:00
parent 085e0dc1de
commit 567e6ca9ca
9 changed files with 78 additions and 1 deletions
@@ -12622,6 +12622,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
}
@TestMetadata("lambdasWithExtensionFunctionType.kt")
public void testLambdasWithExtensionFunctionType() throws Exception {
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
}
@TestMetadata("lastExpressionOfLambdaWithNothingConstraint.kt")
public void testLastExpressionOfLambdaWithNothingConstraint() throws Exception {
runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt");
@@ -94,7 +94,7 @@ class PostponedArgumentInputTypesResolver(
getDeclaredParametersFromRelatedLambdas(argument, postponedArguments, variableDependencyProvider)
val annotationsFromConstraints = functionalTypesFromConstraints?.run {
Annotations.create(flatMap { it.type.annotations })
Annotations.create(flatMapTo(SmartSet.create()) { it.type.annotations }.toList())
} ?: Annotations.EMPTY
val annotations = if (isThereExtensionFunctionAmongRelatedLambdas) {
@@ -0,0 +1,42 @@
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
interface Stroke
interface Fill
data class Rectangle(val width: Int, val height: Int)
open class Ellipse()
data class Circle(val radius: Int) : Ellipse()
interface Canvas {
fun rect(rectangle: Rectangle, fill: Fill)
fun rect(rectangle: Rectangle, stroke: Stroke, fill: Fill?)
fun rect(rectangle: Rectangle, radius: Double, fill: Fill)
fun rect(rectangle: Rectangle, radius: Double, stroke: Stroke, fill: Fill?)
fun circle(circle: Circle, fill: Fill)
fun circle(circle: Circle, stroke: Stroke, fill: Fill?)
}
fun test() {
val rect = Rectangle(100, 100)
val circle = Circle(100)
listOf<Canvas.(Stroke, Fill) -> Unit>(
{ _, fill -> rect(rect, fill) },
{ _, fill -> rect(rect, 10.0, fill) },
{ stroke, fill -> rect(rect, stroke, fill) },
{ stroke, fill -> rect(rect, 10.0, stroke, fill) },
{ _, fill -> circle(circle, fill) },
{ stroke, fill -> circle(circle, stroke, fill) },
).forEach {
check(it)
}
}
fun check(block: Canvas.(Stroke, Fill) -> Unit) {}
fun box(): String {
test()
return "OK"
}
@@ -13847,6 +13847,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
}
@TestMetadata("lambdasWithExtensionFunctionType.kt")
public void testLambdasWithExtensionFunctionType() throws Exception {
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
}
@TestMetadata("lastExpressionOfLambdaWithNothingConstraint.kt")
public void testLastExpressionOfLambdaWithNothingConstraint() throws Exception {
runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt");
@@ -13847,6 +13847,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
}
@TestMetadata("lambdasWithExtensionFunctionType.kt")
public void testLambdasWithExtensionFunctionType() throws Exception {
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
}
@TestMetadata("lastExpressionOfLambdaWithNothingConstraint.kt")
public void testLastExpressionOfLambdaWithNothingConstraint() throws Exception {
runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt");
@@ -12622,6 +12622,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
}
@TestMetadata("lambdasWithExtensionFunctionType.kt")
public void testLambdasWithExtensionFunctionType() throws Exception {
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
}
@TestMetadata("lastExpressionOfLambdaWithNothingConstraint.kt")
public void testLastExpressionOfLambdaWithNothingConstraint() throws Exception {
runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt");
@@ -10802,6 +10802,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
}
@TestMetadata("lambdasWithExtensionFunctionType.kt")
public void testLambdasWithExtensionFunctionType() throws Exception {
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
}
@TestMetadata("lastExpressionOfLambdaWithNothingConstraint.kt")
public void testLastExpressionOfLambdaWithNothingConstraint() throws Exception {
runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt");
@@ -10802,6 +10802,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
}
@TestMetadata("lambdasWithExtensionFunctionType.kt")
public void testLambdasWithExtensionFunctionType() throws Exception {
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
}
@TestMetadata("lastExpressionOfLambdaWithNothingConstraint.kt")
public void testLastExpressionOfLambdaWithNothingConstraint() throws Exception {
runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt");
@@ -10867,6 +10867,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
}
@TestMetadata("lambdasWithExtensionFunctionType.kt")
public void testLambdasWithExtensionFunctionType() throws Exception {
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
}
@TestMetadata("lastExpressionOfLambdaWithNothingConstraint.kt")
public void testLastExpressionOfLambdaWithNothingConstraint() throws Exception {
runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt");