From 563130616570d1a8bd73c8e533d9f1e9567cf087 Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Tue, 21 May 2019 18:54:36 +0300 Subject: [PATCH] Wrap result method node with max stack calculator in inliner #KT-31347 Fixed --- .../kotlin/codegen/inline/MethodInliner.kt | 2 +- .../suspend/maxStackWithCrossinline.kt | 35 +++++++++++++++++++ .../BlackBoxInlineCodegenTestGenerated.java | 10 ++++++ ...otlinAgainstInlineKotlinTestGenerated.java | 10 ++++++ .../IrBlackBoxInlineCodegenTestGenerated.java | 10 ++++++ .../IrInlineSuspendTestsGenerated.java | 5 +++ .../InlineSuspendTestsGenerated.java | 10 ++++++ 7 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/boxInline/suspend/maxStackWithCrossinline.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt index 75034261c9e..95ebb113869 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt @@ -153,7 +153,7 @@ class MethodInliner( LocalVariablesSorter( resultNode.access, resultNode.desc, - resultNode + wrapWithMaxLocalCalc(resultNode) ), AsmTypeRemapper(remapper, result) ) diff --git a/compiler/testData/codegen/boxInline/suspend/maxStackWithCrossinline.kt b/compiler/testData/codegen/boxInline/suspend/maxStackWithCrossinline.kt new file mode 100644 index 00000000000..d7b168c62fa --- /dev/null +++ b/compiler/testData/codegen/boxInline/suspend/maxStackWithCrossinline.kt @@ -0,0 +1,35 @@ +// IGNORE_BACKEND: JVM_IR +// FILE: inlined.kt +// WITH_RUNTIME +// NO_CHECK_LAMBDA_INLINING +// WITH_RUNTIME +// WITH_COROUTINES +// COMMON_COROUTINES_TEST + +fun handle(f: suspend () -> Unit) {} + +open class Foo { + inline fun foo(crossinline body: suspend (Baz) -> Unit, crossinline createContext: () -> Baz) { + handle { + body(createContext()) + } + } +} + +class Bar : Foo() { + inline fun bar(crossinline body: suspend (Baz) -> Unit) { + this.foo(body) { + Baz(Unit) + } + } +} + +class Baz(unit: Unit) + +// FILE: inlineSite.kt +// COMMON_COROUTINES_TEST + +fun box(): String { + Bar().bar {} + return "OK" +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index fa94b3a32e2..d23243936ae 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -3545,6 +3545,16 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo runTest("compiler/testData/codegen/boxInline/suspend/kt26658.kt"); } + @TestMetadata("maxStackWithCrossinline.kt") + public void testMaxStackWithCrossinline_1_2() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/maxStackWithCrossinline.kt", "kotlin.coroutines.experimental"); + } + + @TestMetadata("maxStackWithCrossinline.kt") + public void testMaxStackWithCrossinline_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/maxStackWithCrossinline.kt", "kotlin.coroutines"); + } + @TestMetadata("multipleLocals.kt") public void testMultipleLocals_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/multipleLocals.kt", "kotlin.coroutines.experimental"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index 506c2a07dcc..0262cbfc877 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -3545,6 +3545,16 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi runTest("compiler/testData/codegen/boxInline/suspend/kt26658.kt"); } + @TestMetadata("maxStackWithCrossinline.kt") + public void testMaxStackWithCrossinline_1_2() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/maxStackWithCrossinline.kt", "kotlin.coroutines.experimental"); + } + + @TestMetadata("maxStackWithCrossinline.kt") + public void testMaxStackWithCrossinline_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/maxStackWithCrossinline.kt", "kotlin.coroutines"); + } + @TestMetadata("multipleLocals.kt") public void testMultipleLocals_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/multipleLocals.kt", "kotlin.coroutines.experimental"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java index e4c58166a23..b5875cfc3a2 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -3545,6 +3545,16 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli runTest("compiler/testData/codegen/boxInline/suspend/kt26658.kt"); } + @TestMetadata("maxStackWithCrossinline.kt") + public void testMaxStackWithCrossinline_1_2() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/maxStackWithCrossinline.kt", "kotlin.coroutines.experimental"); + } + + @TestMetadata("maxStackWithCrossinline.kt") + public void testMaxStackWithCrossinline_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/maxStackWithCrossinline.kt", "kotlin.coroutines"); + } + @TestMetadata("multipleLocals.kt") public void testMultipleLocals_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/multipleLocals.kt", "kotlin.coroutines.experimental"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrInlineSuspendTestsGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrInlineSuspendTestsGenerated.java index c3a05946cd3..d13e5a91d7d 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrInlineSuspendTestsGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrInlineSuspendTestsGenerated.java @@ -88,6 +88,11 @@ public class IrInlineSuspendTestsGenerated extends AbstractIrInlineSuspendTests runTest("compiler/testData/codegen/boxInline/suspend/kt26658.kt"); } + @TestMetadata("maxStackWithCrossinline.kt") + public void testMaxStackWithCrossinline_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/maxStackWithCrossinline.kt", "kotlin.coroutines"); + } + @TestMetadata("multipleLocals.kt") public void testMultipleLocals_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/multipleLocals.kt", "kotlin.coroutines"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineSuspendTestsGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineSuspendTestsGenerated.java index 466e3a71d64..5356dc15881 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineSuspendTestsGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineSuspendTestsGenerated.java @@ -138,6 +138,16 @@ public class InlineSuspendTestsGenerated extends AbstractInlineSuspendTests { runTest("compiler/testData/codegen/boxInline/suspend/kt26658.kt"); } + @TestMetadata("maxStackWithCrossinline.kt") + public void testMaxStackWithCrossinline_1_2() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/maxStackWithCrossinline.kt", "kotlin.coroutines.experimental"); + } + + @TestMetadata("maxStackWithCrossinline.kt") + public void testMaxStackWithCrossinline_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/maxStackWithCrossinline.kt", "kotlin.coroutines"); + } + @TestMetadata("multipleLocals.kt") public void testMultipleLocals_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/multipleLocals.kt", "kotlin.coroutines.experimental");