From 567e6ca9ca575a54aee95c4df4929283c35ef191 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Wed, 26 Aug 2020 10:43:55 +0300 Subject: [PATCH] Fix OOM when there are several lambdas with extension function types #KT-41335 Fixed --- .../ir/FirBlackBoxCodegenTestGenerated.java | 5 +++ .../PostponedArgumentInputTypesResolver.kt | 2 +- .../lambdasWithExtensionFunctionType.kt | 42 +++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 5 +++ .../LightAnalysisModeTestGenerated.java | 5 +++ .../ir/IrBlackBoxCodegenTestGenerated.java | 5 +++ .../IrJsCodegenBoxES6TestGenerated.java | 5 +++ .../IrJsCodegenBoxTestGenerated.java | 5 +++ .../semantics/JsCodegenBoxTestGenerated.java | 5 +++ 9 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 2bd5c9f58d1..1e849212564 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -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"); diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/PostponedArgumentInputTypesResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/PostponedArgumentInputTypesResolver.kt index 4a288a28568..4474b792e4d 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/PostponedArgumentInputTypesResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/PostponedArgumentInputTypesResolver.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) { diff --git a/compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt b/compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt new file mode 100644 index 00000000000..27d910785cd --- /dev/null +++ b/compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt @@ -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 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" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index aff052eb00a..802eb2ed777 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -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"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 8ee7e1ae5fb..b1b35a35afc 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -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"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index c2e32202077..25affe9786c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -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"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index cea8f086238..fa372bf5154 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -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"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index d3c59cdb49c..3f1b348aebb 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -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"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index c5ea5ad2ad1..695ffba8619 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -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");