From a789fd92fe5a30406cc342dac95aafca063f775b Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Thu, 13 Sep 2018 13:22:29 +0200 Subject: [PATCH] Properly parse smap information #KT-23369 Fixed --- .../kotlin/codegen/inline/SMAPParser.kt | 29 +++++++------- .../codegen/boxInline/smap/kt23369.kt | 39 +++++++++++++++++++ .../codegen/boxInline/smap/kt23369_2.kt | 39 +++++++++++++++++++ .../codegen/boxInline/smap/kt23369_3.kt | 39 +++++++++++++++++++ .../codegen/boxInline/smap/kt23369_E.kt | 39 +++++++++++++++++++ .../codegen/boxInline/smap/kt23369_F.kt | 39 +++++++++++++++++++ .../codegen/boxInline/smap/kt23369_L.kt | 39 +++++++++++++++++++ .../BlackBoxInlineCodegenTestGenerated.java | 30 ++++++++++++++ ...otlinAgainstInlineKotlinTestGenerated.java | 30 ++++++++++++++ .../IrBlackBoxInlineCodegenTestGenerated.java | 30 ++++++++++++++ 10 files changed, 338 insertions(+), 15 deletions(-) create mode 100644 compiler/testData/codegen/boxInline/smap/kt23369.kt create mode 100644 compiler/testData/codegen/boxInline/smap/kt23369_2.kt create mode 100644 compiler/testData/codegen/boxInline/smap/kt23369_3.kt create mode 100644 compiler/testData/codegen/boxInline/smap/kt23369_E.kt create mode 100644 compiler/testData/codegen/boxInline/smap/kt23369_F.kt create mode 100644 compiler/testData/codegen/boxInline/smap/kt23369_L.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAPParser.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAPParser.kt index 18b489c2e77..be82f1d879c 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAPParser.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAPParser.kt @@ -42,25 +42,24 @@ object SMAPParser { fun parse(mappingInfo: String): SMAP { val fileMappings = linkedMapOf() - val fileSectionStart = mappingInfo.indexOf(SMAP.FILE_SECTION) + SMAP.FILE_SECTION.length - val lineSectionAnchor = mappingInfo.indexOf(SMAP.LINE_SECTION) - val files = mappingInfo.substring(fileSectionStart, lineSectionAnchor) + val iterator = mappingInfo.lineSequence().dropWhile { it.trim() != SMAP.FILE_SECTION }.drop(1).iterator() + while (iterator.hasNext()) { + val fileDeclaration = iterator.next().trim() + if (fileDeclaration == SMAP.LINE_SECTION) break - val fileEntries = files.trim().split('+') + if (!fileDeclaration.startsWith('+')) { + throw AssertionError("File declaration should be in extended form, but: $fileDeclaration in $mappingInfo") + } - for (fileDeclaration in fileEntries) { - if (fileDeclaration == "") continue - val fileInternalName = fileDeclaration.trim() - - val indexEnd = fileInternalName.indexOf(' ') - val fileIndex = fileInternalName.substring(0, indexEnd).toInt() - val newLine = fileInternalName.indexOf('\n') - val fileName = fileInternalName.substring(indexEnd + 1, newLine) - fileMappings[fileIndex] = FileMapping(fileName, fileInternalName.substring(newLine + 1).trim()) + val indexAndFileInternalName = fileDeclaration.substringAfter("+ ").trim() + val fileIndex = indexAndFileInternalName.substringBefore(' ').toInt() + val fileName = indexAndFileInternalName.substringAfter(' ') + val path = iterator.next().trim() + fileMappings[fileIndex] = FileMapping(fileName, path) } - val lines = mappingInfo.substring(lineSectionAnchor + SMAP.LINE_SECTION.length, mappingInfo.indexOf(SMAP.END)).trim().split('\n') - for (lineMapping in lines) { + for (lineMapping in iterator) { + if (lineMapping.trim() == SMAP.END) break /*only simple mapping now*/ val targetSplit = lineMapping.indexOf(':') val originalPart = lineMapping.substring(0, targetSplit) diff --git a/compiler/testData/codegen/boxInline/smap/kt23369.kt b/compiler/testData/codegen/boxInline/smap/kt23369.kt new file mode 100644 index 00000000000..7cf487d372d --- /dev/null +++ b/compiler/testData/codegen/boxInline/smap/kt23369.kt @@ -0,0 +1,39 @@ +// FILE: 1+a.kt + +package test + +inline fun inlineFun(lambda: () -> String): String { + return lambda() +} + +// FILE: 2.kt +import test.* + +fun box(): String { + return inlineFun { "OK" } +} + +// FILE: 1+a.smap + +// FILE: 2.smap + +SMAP +2.kt +Kotlin +*S Kotlin +*F ++ 1 2.kt +_2Kt ++ 2 1+a.kt +test/_1_aKt +*L +1#1,8:1 +6#2:9 +*E +*S KotlinDebug +*F ++ 1 2.kt +_2Kt +*L +5#1:9 +*E \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/smap/kt23369_2.kt b/compiler/testData/codegen/boxInline/smap/kt23369_2.kt new file mode 100644 index 00000000000..93fc2e017f8 --- /dev/null +++ b/compiler/testData/codegen/boxInline/smap/kt23369_2.kt @@ -0,0 +1,39 @@ +// FILE: 1+ a.kt + +package test + +inline fun inlineFun(lambda: () -> String): String { + return lambda() +} + +// FILE: 2.kt +import test.* + +fun box(): String { + return inlineFun { "OK" } +} + +// FILE: 1+ a.smap + +// FILE: 2.smap + +SMAP +2.kt +Kotlin +*S Kotlin +*F ++ 1 2.kt +_2Kt ++ 2 1+ a.kt +test/_1__aKt +*L +1#1,8:1 +6#2:9 +*E +*S KotlinDebug +*F ++ 1 2.kt +_2Kt +*L +5#1:9 +*E \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/smap/kt23369_3.kt b/compiler/testData/codegen/boxInline/smap/kt23369_3.kt new file mode 100644 index 00000000000..d60d1177acc --- /dev/null +++ b/compiler/testData/codegen/boxInline/smap/kt23369_3.kt @@ -0,0 +1,39 @@ +// FILE: + a.kt + +package test + +inline fun inlineFun(lambda: () -> String): String { + return lambda() +} + +// FILE: 2.kt +import test.* + +fun box(): String { + return inlineFun { "OK" } +} + +// FILE: + a.smap + +// FILE: 2.smap + +SMAP +2.kt +Kotlin +*S Kotlin +*F ++ 1 2.kt +_2Kt ++ 2 + a.kt +test/__aKt +*L +1#1,8:1 +6#2:9 +*E +*S KotlinDebug +*F ++ 1 2.kt +_2Kt +*L +5#1:9 +*E \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/smap/kt23369_E.kt b/compiler/testData/codegen/boxInline/smap/kt23369_E.kt new file mode 100644 index 00000000000..e3fcda6549c --- /dev/null +++ b/compiler/testData/codegen/boxInline/smap/kt23369_E.kt @@ -0,0 +1,39 @@ +// FILE: 1*E.kt + +package test + +inline fun inlineFun(lambda: () -> String): String { + return lambda() +} + +// FILE: 2.kt +import test.* + +fun box(): String { + return inlineFun { "OK" } +} + +// FILE: 1+a.smap + +// FILE: 2.smap + +SMAP +2.kt +Kotlin +*S Kotlin +*F ++ 1 2.kt +_2Kt ++ 2 1*E.kt +test/_1_EKt +*L +1#1,8:1 +6#2:9 +*E +*S KotlinDebug +*F ++ 1 2.kt +_2Kt +*L +5#1:9 +*E \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/smap/kt23369_F.kt b/compiler/testData/codegen/boxInline/smap/kt23369_F.kt new file mode 100644 index 00000000000..cc3c59237a8 --- /dev/null +++ b/compiler/testData/codegen/boxInline/smap/kt23369_F.kt @@ -0,0 +1,39 @@ +// FILE: 1*F.kt + +package test + +inline fun inlineFun(lambda: () -> String): String { + return lambda() +} + +// FILE: 2.kt +import test.* + +fun box(): String { + return inlineFun { "OK" } +} + +// FILE: 1+a.smap + +// FILE: 2.smap + +SMAP +2.kt +Kotlin +*S Kotlin +*F ++ 1 2.kt +_2Kt ++ 2 1*F.kt +test/_1_FKt +*L +1#1,8:1 +6#2:9 +*E +*S KotlinDebug +*F ++ 1 2.kt +_2Kt +*L +5#1:9 +*E \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/smap/kt23369_L.kt b/compiler/testData/codegen/boxInline/smap/kt23369_L.kt new file mode 100644 index 00000000000..64de8dfb826 --- /dev/null +++ b/compiler/testData/codegen/boxInline/smap/kt23369_L.kt @@ -0,0 +1,39 @@ +// FILE: 1*L.kt + +package test + +inline fun inlineFun(lambda: () -> String): String { + return lambda() +} + +// FILE: 2.kt +import test.* + +fun box(): String { + return inlineFun { "OK" } +} + +// FILE: 1+a.smap + +// FILE: 2.smap + +SMAP +2.kt +Kotlin +*S Kotlin +*F ++ 1 2.kt +_2Kt ++ 2 1*L.kt +test/_1_LKt +*L +1#1,8:1 +6#2:9 +*E +*S KotlinDebug +*F ++ 1 2.kt +_2Kt +*L +5#1:9 +*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 4aa926a7504..7deadb0be50 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -2841,6 +2841,36 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo runTest("compiler/testData/codegen/boxInline/smap/defaultFunction.kt"); } + @TestMetadata("kt23369.kt") + public void testKt23369() throws Exception { + runTest("compiler/testData/codegen/boxInline/smap/kt23369.kt"); + } + + @TestMetadata("kt23369_2.kt") + public void testKt23369_2() throws Exception { + runTest("compiler/testData/codegen/boxInline/smap/kt23369_2.kt"); + } + + @TestMetadata("kt23369_3.kt") + public void testKt23369_3() throws Exception { + runTest("compiler/testData/codegen/boxInline/smap/kt23369_3.kt"); + } + + @TestMetadata("kt23369_E.kt") + public void testKt23369_E() throws Exception { + runTest("compiler/testData/codegen/boxInline/smap/kt23369_E.kt"); + } + + @TestMetadata("kt23369_F.kt") + public void testKt23369_F() throws Exception { + runTest("compiler/testData/codegen/boxInline/smap/kt23369_F.kt"); + } + + @TestMetadata("kt23369_L.kt") + public void testKt23369_L() throws Exception { + runTest("compiler/testData/codegen/boxInline/smap/kt23369_L.kt"); + } + @TestMetadata("oneFile.kt") public void testOneFile() throws Exception { runTest("compiler/testData/codegen/boxInline/smap/oneFile.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index f57d50462c2..657930ba0ce 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -2841,6 +2841,36 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi runTest("compiler/testData/codegen/boxInline/smap/defaultFunction.kt"); } + @TestMetadata("kt23369.kt") + public void testKt23369() throws Exception { + runTest("compiler/testData/codegen/boxInline/smap/kt23369.kt"); + } + + @TestMetadata("kt23369_2.kt") + public void testKt23369_2() throws Exception { + runTest("compiler/testData/codegen/boxInline/smap/kt23369_2.kt"); + } + + @TestMetadata("kt23369_3.kt") + public void testKt23369_3() throws Exception { + runTest("compiler/testData/codegen/boxInline/smap/kt23369_3.kt"); + } + + @TestMetadata("kt23369_E.kt") + public void testKt23369_E() throws Exception { + runTest("compiler/testData/codegen/boxInline/smap/kt23369_E.kt"); + } + + @TestMetadata("kt23369_F.kt") + public void testKt23369_F() throws Exception { + runTest("compiler/testData/codegen/boxInline/smap/kt23369_F.kt"); + } + + @TestMetadata("kt23369_L.kt") + public void testKt23369_L() throws Exception { + runTest("compiler/testData/codegen/boxInline/smap/kt23369_L.kt"); + } + @TestMetadata("oneFile.kt") public void testOneFile() throws Exception { runTest("compiler/testData/codegen/boxInline/smap/oneFile.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java index 60f5a774eef..ce8e43fb833 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -2841,6 +2841,36 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli runTest("compiler/testData/codegen/boxInline/smap/defaultFunction.kt"); } + @TestMetadata("kt23369.kt") + public void testKt23369() throws Exception { + runTest("compiler/testData/codegen/boxInline/smap/kt23369.kt"); + } + + @TestMetadata("kt23369_2.kt") + public void testKt23369_2() throws Exception { + runTest("compiler/testData/codegen/boxInline/smap/kt23369_2.kt"); + } + + @TestMetadata("kt23369_3.kt") + public void testKt23369_3() throws Exception { + runTest("compiler/testData/codegen/boxInline/smap/kt23369_3.kt"); + } + + @TestMetadata("kt23369_E.kt") + public void testKt23369_E() throws Exception { + runTest("compiler/testData/codegen/boxInline/smap/kt23369_E.kt"); + } + + @TestMetadata("kt23369_F.kt") + public void testKt23369_F() throws Exception { + runTest("compiler/testData/codegen/boxInline/smap/kt23369_F.kt"); + } + + @TestMetadata("kt23369_L.kt") + public void testKt23369_L() throws Exception { + runTest("compiler/testData/codegen/boxInline/smap/kt23369_L.kt"); + } + @TestMetadata("oneFile.kt") public void testOneFile() throws Exception { runTest("compiler/testData/codegen/boxInline/smap/oneFile.kt");