From 01e2f8e32cdc39410c3d97f9e53e2cba1bb11904 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Mon, 3 Jul 2017 15:37:12 +0200 Subject: [PATCH] Preventively allocate slots for additional default parameters Otherwise they are corrupted by inline --- .../kotlin/codegen/FunctionCodegen.java | 13 +++-- .../boxInline/defaultValues/33Parameters.kt | 53 +++++++++++++++++++ .../33ParametersInConstructor.kt | 51 ++++++++++++++++++ .../IrBlackBoxInlineCodegenTestGenerated.java | 12 +++++ ...otlinAgainstInlineKotlinTestGenerated.java | 12 +++++ .../BlackBoxInlineCodegenTestGenerated.java | 12 +++++ ...otlinAgainstInlineKotlinTestGenerated.java | 12 +++++ .../InlineDefaultValuesTestsGenerated.java | 12 +++++ 8 files changed, 174 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/codegen/boxInline/defaultValues/33Parameters.kt create mode 100644 compiler/testData/codegen/boxInline/defaultValues/33ParametersInConstructor.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java index b75d810296c..4d60198825c 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java @@ -1002,12 +1002,19 @@ public class FunctionCodegen { capturedArgumentsCount++; } - int maskIndex = 0; List valueParameters = functionDescriptor.getValueParameters(); - for (int index = 0; index < valueParameters.size(); index++) { + assert valueParameters.size() > 0 : "Expecting value parameters to generate default function " + functionDescriptor; + int firstMaskIndex = frameMap.enterTemp(Type.INT_TYPE); + for (int index = 1; index < valueParameters.size(); index++) { if (index % Integer.SIZE == 0) { - maskIndex = frameMap.enterTemp(Type.INT_TYPE); + frameMap.enterTemp(Type.INT_TYPE); } + } + //default handler or constructor marker + frameMap.enterTemp(AsmTypes.OBJECT_TYPE); + + for (int index = 0; index < valueParameters.size(); index++) { + int maskIndex = firstMaskIndex + index / Integer.SIZE; ValueParameterDescriptor parameterDescriptor = valueParameters.get(index); Type type = mappedParameters.get(capturedArgumentsCount + index).getAsmType(); diff --git a/compiler/testData/codegen/boxInline/defaultValues/33Parameters.kt b/compiler/testData/codegen/boxInline/defaultValues/33Parameters.kt new file mode 100644 index 00000000000..50a8bbc1fa4 --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/33Parameters.kt @@ -0,0 +1,53 @@ +// FILE: 1.kt + +package test + +fun calc() = "OK" + +inline fun String.test() = this + +fun test( + p1: String = "1", + p2: String = "2", + p3: String = "3", + p4: String = "4", + p5: String = "5", + p6: String = "6", + p7: String = "7", + p8: String = "8", + p9: String = "9", + p10: String = "10", + p11: String = "11", + p12: String = "12", + p13: String = "13", + p14: String = "O".test(), + p15: String = "15", + p16: String = "16", + p17: String = "17", + p18: String = "18", + p19: String = "19", + p20: String = "20", + p21: String = "21", + p22: String = "22", + p23: String = "23", + p24: String = "24", + p25: String = "25", + p26: String = "26", + p27: String = "27", + p28: String = "28", + p29: String = "29", + p30: String = "30", + p31: String = "31", + p32: String = "32", + p33: String = "K".test() +): String { + return p14 + p33 +} + +// FILE: 2.kt + +import test.* + +fun box(): String { + return test() +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/defaultValues/33ParametersInConstructor.kt b/compiler/testData/codegen/boxInline/defaultValues/33ParametersInConstructor.kt new file mode 100644 index 00000000000..e0d10b91911 --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/33ParametersInConstructor.kt @@ -0,0 +1,51 @@ +// FILE: 1.kt + +package test + +fun calc() = "OK" + +inline fun String.test() = this + +class Test( + p1: String = "1", + p2: String = "2", + p3: String = "3", + p4: String = "4", + p5: String = "5", + p6: String = "6", + p7: String = "7", + p8: String = "8", + p9: String = "9", + p10: String = "10", + p11: String = "11", + p12: String = "12", + p13: String = "13", + val p14: String = "O".test(), + p15: String = "15", + p16: String = "16", + p17: String = "17", + p18: String = "18", + p19: String = "19", + p20: String = "20", + p21: String = "21", + p22: String = "22", + p23: String = "23", + p24: String = "24", + p25: String = "25", + p26: String = "26", + p27: String = "27", + p28: String = "28", + p29: String = "29", + p30: String = "30", + p31: String = "31", + p32: String = "32", + val p33: String = "K".test() +) +// FILE: 2.kt + +import test.* + +fun box(): String { + val test = Test() + return test.p14 + test.p33 +} \ No newline at end of file diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java index b0a13a2d3ef..efff0edd70a 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -949,6 +949,18 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class DefaultValues extends AbstractIrBlackBoxInlineCodegenTest { + @TestMetadata("33Parameters.kt") + public void test33Parameters() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/33Parameters.kt"); + doTest(fileName); + } + + @TestMetadata("33ParametersInConstructor.kt") + public void test33ParametersInConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/33ParametersInConstructor.kt"); + doTest(fileName); + } + public void testAllFilesPresentInDefaultValues() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/defaultValues"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java index 2e47cdfb076..7fee8a33f97 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java @@ -949,6 +949,18 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class DefaultValues extends AbstractIrCompileKotlinAgainstInlineKotlinTest { + @TestMetadata("33Parameters.kt") + public void test33Parameters() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/33Parameters.kt"); + doTest(fileName); + } + + @TestMetadata("33ParametersInConstructor.kt") + public void test33ParametersInConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/33ParametersInConstructor.kt"); + doTest(fileName); + } + public void testAllFilesPresentInDefaultValues() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/defaultValues"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index 054c8ab02ef..95868a8afe6 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -949,6 +949,18 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class DefaultValues extends AbstractBlackBoxInlineCodegenTest { + @TestMetadata("33Parameters.kt") + public void test33Parameters() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/33Parameters.kt"); + doTest(fileName); + } + + @TestMetadata("33ParametersInConstructor.kt") + public void test33ParametersInConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/33ParametersInConstructor.kt"); + doTest(fileName); + } + public void testAllFilesPresentInDefaultValues() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/defaultValues"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index 2a934173bf8..4bebf16b5ae 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -949,6 +949,18 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class DefaultValues extends AbstractCompileKotlinAgainstInlineKotlinTest { + @TestMetadata("33Parameters.kt") + public void test33Parameters() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/33Parameters.kt"); + doTest(fileName); + } + + @TestMetadata("33ParametersInConstructor.kt") + public void test33ParametersInConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/33ParametersInConstructor.kt"); + doTest(fileName); + } + public void testAllFilesPresentInDefaultValues() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/defaultValues"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineDefaultValuesTestsGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineDefaultValuesTestsGenerated.java index 332ca34b7be..fa492454ea1 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineDefaultValuesTestsGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineDefaultValuesTestsGenerated.java @@ -32,6 +32,18 @@ import java.util.regex.Pattern; @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public class InlineDefaultValuesTestsGenerated extends AbstractInlineDefaultValuesTests { + @TestMetadata("33Parameters.kt") + public void test33Parameters() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/33Parameters.kt"); + doTest(fileName); + } + + @TestMetadata("33ParametersInConstructor.kt") + public void test33ParametersInConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/33ParametersInConstructor.kt"); + doTest(fileName); + } + public void testAllFilesPresentInDefaultValues() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/defaultValues"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); }