From 3e502032837ef07a86423b755efe2b0a7d545ac9 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Fri, 12 May 2017 13:08:57 +0200 Subject: [PATCH] Add source mapping tests for default lambda inlining --- .../kotlin/codegen/MemberCodegen.java | 2 +- .../codegen/boxInline/smap/defaultFunction.kt | 41 +++++++++ .../boxInline/smap/defaultLambda/nested.kt | 91 +++++++++++++++++++ .../boxInline/smap/defaultLambda/simple.kt | 64 +++++++++++++ .../BlackBoxInlineCodegenTestGenerated.java | 27 ++++++ ...otlinAgainstInlineKotlinTestGenerated.java | 27 ++++++ 6 files changed, 251 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/boxInline/smap/defaultFunction.kt create mode 100644 compiler/testData/codegen/boxInline/smap/defaultLambda/nested.kt create mode 100644 compiler/testData/codegen/boxInline/smap/defaultLambda/simple.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java index d50acf38e51..8d820bdd37b 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java @@ -657,7 +657,7 @@ public abstract class MemberCodegen String = { capturedParam }): String { + return lambda() +} + +// FILE: 2.kt +//NO_CHECK_LAMBDA_INLINING +import test.* + +fun box(): String { + return inlineFun("OK") +} + +// FILE: 1.smap +//TODO maybe do smth with default method body mapping +SMAP +1.kt +Kotlin +*S Kotlin +*F ++ 1 1.kt +test/_1Kt +*L +1#1,8:1 +5#1:9 +*E + +SMAP +1.kt +Kotlin +*S Kotlin +*F ++ 1 1.kt +test/_1Kt$inlineFun$1 +*L +1#1,8:1 +*E + +// FILE: 2.TODO \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/smap/defaultLambda/nested.kt b/compiler/testData/codegen/boxInline/smap/defaultLambda/nested.kt new file mode 100644 index 00000000000..b1bd8116a17 --- /dev/null +++ b/compiler/testData/codegen/boxInline/smap/defaultLambda/nested.kt @@ -0,0 +1,91 @@ +// FILE: 1.kt +// SKIP_INLINE_CHECK_IN: inlineFun$default +package test + +@Suppress("NOT_YET_SUPPORTED_IN_INLINE") +inline fun inlineFun(capturedParam: String, crossinline lambda: () -> String = { capturedParam }): String { + return { + lambda() + }() +} + +// FILE: 2.kt + +import test.* + +fun box(): String { + return inlineFun("OK") +} + +// FILE: 1.smap +//TODO maybe do smth with default method body mapping +SMAP +1.kt +Kotlin +*S Kotlin +*F ++ 1 1.kt +test/_1Kt +*L +1#1,12:1 +7#1:13 +*E + +SMAP +1.kt +Kotlin +*S Kotlin +*F ++ 1 1.kt +test/_1Kt$inlineFun$2 +*L +1#1,12:1 +*E + +SMAP +1.kt +Kotlin +*S Kotlin +*F ++ 1 1.kt +test/_1Kt$inlineFun$1 +*L +1#1,12:1 +*E + +// FILE: 2.smap + +SMAP +2.kt +Kotlin +*S Kotlin +*F ++ 1 2.kt +_2Kt ++ 2 1.kt +test/_1Kt +*L +1#1,9:1 +6#2,2:10 +*E +*S KotlinDebug +*F ++ 1 2.kt +_2Kt +*L +6#1,2:10 +*E + +SMAP +1.kt +Kotlin +*S Kotlin +*F ++ 1 1.kt +test/_1Kt$inlineFun$2 ++ 2 1.kt +test/_1Kt$inlineFun$1 +*L +1#1,12:1 +6#2:13 +*E \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/smap/defaultLambda/simple.kt b/compiler/testData/codegen/boxInline/smap/defaultLambda/simple.kt new file mode 100644 index 00000000000..2d069314067 --- /dev/null +++ b/compiler/testData/codegen/boxInline/smap/defaultLambda/simple.kt @@ -0,0 +1,64 @@ +// FILE: 1.kt +// SKIP_INLINE_CHECK_IN: inlineFun$default +package test + +@Suppress("NOT_YET_SUPPORTED_IN_INLINE") +inline fun inlineFun(capturedParam: String, lambda: () -> String = { capturedParam }): String { + return lambda() +} + +// FILE: 2.kt + +import test.* + +fun box(): String { + return inlineFun("OK") +} + +// FILE: 1.smap +//TODO maybe do smth with default method body mapping +SMAP +1.kt +Kotlin +*S Kotlin +*F ++ 1 1.kt +test/_1Kt +*L +1#1,10:1 +7#1:11 +*E + +SMAP +1.kt +Kotlin +*S Kotlin +*F ++ 1 1.kt +test/_1Kt$inlineFun$1 +*L +1#1,10:1 +*E + +// FILE: 2.smap + +SMAP +2.kt +Kotlin +*S Kotlin +*F ++ 1 2.kt +_2Kt ++ 2 1.kt +test/_1Kt +*L +1#1,9:1 +6#2,2:10 +*E +*S KotlinDebug +*F ++ 1 2.kt +_2Kt +*L +6#1,2:10 +*E \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index 52e699ba649..796320348c9 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -2375,6 +2375,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo doTest(fileName); } + @TestMetadata("defaultFunction.kt") + public void testDefaultFunction() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/smap/defaultFunction.kt"); + doTest(fileName); + } + @TestMetadata("oneFile.kt") public void testOneFile() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/smap/oneFile.kt"); @@ -2450,6 +2456,27 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo } } + @TestMetadata("compiler/testData/codegen/boxInline/smap/defaultLambda") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class DefaultLambda extends AbstractBlackBoxInlineCodegenTest { + public void testAllFilesPresentInDefaultLambda() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/smap/defaultLambda"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("nested.kt") + public void testNested() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/smap/defaultLambda/nested.kt"); + doTest(fileName); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/smap/defaultLambda/simple.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/boxInline/smap/inlineOnly") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index 0e8c8c82a2c..8ce1230eef7 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -2375,6 +2375,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi doTest(fileName); } + @TestMetadata("defaultFunction.kt") + public void testDefaultFunction() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/smap/defaultFunction.kt"); + doTest(fileName); + } + @TestMetadata("oneFile.kt") public void testOneFile() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/smap/oneFile.kt"); @@ -2450,6 +2456,27 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi } } + @TestMetadata("compiler/testData/codegen/boxInline/smap/defaultLambda") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class DefaultLambda extends AbstractCompileKotlinAgainstInlineKotlinTest { + public void testAllFilesPresentInDefaultLambda() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/smap/defaultLambda"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("nested.kt") + public void testNested() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/smap/defaultLambda/nested.kt"); + doTest(fileName); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/smap/defaultLambda/simple.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/boxInline/smap/inlineOnly") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)