From 1d17bee6cc3b8ab7d7ebeb6b4a052f55181b5ccb Mon Sep 17 00:00:00 2001 From: Michael Bogdanov Date: Wed, 17 Feb 2016 15:05:32 +0300 Subject: [PATCH] Don't generate source mapping on inlining 'InlineOnly' functions --- .../kotlin/codegen/inline/InlineCodegen.java | 4 +++- .../kotlin/codegen/inline/MethodInliner.java | 9 ++++++-- .../codegen/inline/RootInliningContext.java | 5 ++++- .../boxInline/smap/inlineOnly/noSmap.1.kt | 14 ++++++++++++ .../boxInline/smap/inlineOnly/noSmap.2.kt | 4 ++++ .../boxInline/smap/inlineOnly/reified.1.kt | 22 +++++++++++++++++++ .../boxInline/smap/inlineOnly/reified.2.kt | 3 +++ .../inlineOnly/inlineOnly.compile.expected | 1 + .../smoke/inlineOnly/inlineOnly.kt | 5 +++++ .../smoke/inlineOnly/inlineOnly.run.expected | 6 +++++ .../smoke/scriptException/script.expected | 2 +- .../BlackBoxInlineCodegenTestGenerated.java | 21 ++++++++++++++++++ .../kotlin/integration/CompilerSmokeTest.java | 8 +++++++ ...otlinAgainstInlineKotlinTestGenerated.java | 21 ++++++++++++++++++ .../debugger/tinyApp/outs/inlineOnly.out | 9 ++++++++ .../src/stepping/stepInto/inlineOnly.kt | 8 +++++++ .../debugger/KotlinSteppingTestGenerated.java | 6 +++++ 17 files changed, 143 insertions(+), 5 deletions(-) create mode 100644 compiler/testData/codegen/boxInline/smap/inlineOnly/noSmap.1.kt create mode 100644 compiler/testData/codegen/boxInline/smap/inlineOnly/noSmap.2.kt create mode 100644 compiler/testData/codegen/boxInline/smap/inlineOnly/reified.1.kt create mode 100644 compiler/testData/codegen/boxInline/smap/inlineOnly/reified.2.kt create mode 100644 compiler/testData/integration/smoke/inlineOnly/inlineOnly.compile.expected create mode 100644 compiler/testData/integration/smoke/inlineOnly/inlineOnly.kt create mode 100644 compiler/testData/integration/smoke/inlineOnly/inlineOnly.run.expected create mode 100644 idea/testData/debugger/tinyApp/outs/inlineOnly.out create mode 100644 idea/testData/debugger/tinyApp/src/stepping/stepInto/inlineOnly.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java index 942e9627f35..291cdaea137 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java @@ -38,6 +38,7 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer; import org.jetbrains.kotlin.resolve.BindingContext; import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils; import org.jetbrains.kotlin.resolve.DescriptorUtils; +import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt; import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt; import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall; import org.jetbrains.kotlin.resolve.inline.InlineUtil; @@ -276,7 +277,8 @@ public class InlineCodegen extends CallGenerator { InliningContext info = new RootInliningContext( expressionMap, state, codegen.getInlineNameGenerator().subGenerator(jvmSignature.getAsmMethod().getName()), - codegen.getContext(), callElement, getInlineCallSiteInfo(), reifiedTypeInliner, typeParameterMappings, isDefaultCompilation + codegen.getContext(), callElement, getInlineCallSiteInfo(), reifiedTypeInliner, typeParameterMappings, isDefaultCompilation, + AnnotationUtilKt.hasInlineOnlyAnnotation(functionDescriptor) ); MethodInliner inliner = new MethodInliner(node, parameters, info, new FieldRemapper(null, null, parameters), isSameModule, diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java index ff865c2623b..2758b42604b 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java @@ -71,6 +71,8 @@ public class MethodInliner { private int lambdasFinallyBlocks; + private final boolean skipSmap; + /* * * @param node @@ -98,6 +100,7 @@ public class MethodInliner { this.inlineCallSiteInfo = inlineCallSiteInfo; this.typeMapper = inliningContext.state.getTypeMapper(); this.result = InlineResult.create(); + skipSmap = inliningContext instanceof RootInliningContext && ((RootInliningContext) inliningContext).skipSmap; } public InlineResult doInline( @@ -339,6 +342,8 @@ public class MethodInliner { node.instructions.resetLabels(); MethodNode transformedNode = new MethodNode(InlineCodegenUtil.API, node.access, node.name, Type.getMethodDescriptor(returnType, allTypes), node.signature, null) { + private final boolean GENERATE_DEBUG_INFO = InlineCodegenUtil.GENERATE_SMAP && !skipSmap; + private final boolean isInliningLambda = nodeRemapper.isInsideInliningLambda(); private int getNewIndex(int var) { @@ -362,7 +367,7 @@ public class MethodInliner { @Override public void visitLineNumber(int line, @NotNull Label start) { - if(isInliningLambda || InlineCodegenUtil.GENERATE_SMAP) { + if(isInliningLambda || GENERATE_DEBUG_INFO) { super.visitLineNumber(line, start); } } @@ -371,7 +376,7 @@ public class MethodInliner { public void visitLocalVariable( @NotNull String name, @NotNull String desc, String signature, @NotNull Label start, @NotNull Label end, int index ) { - if (isInliningLambda || InlineCodegenUtil.GENERATE_SMAP) { + if (isInliningLambda || GENERATE_DEBUG_INFO) { String varSuffix = inliningContext.isRoot() && !isDefaultCompilation() && !InlineCodegenUtil.isFakeLocalVariableForInline(name) ? diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/RootInliningContext.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/RootInliningContext.java index ebd44db9186..cc4a0f7b4a7 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/RootInliningContext.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/RootInliningContext.java @@ -29,6 +29,7 @@ public class RootInliningContext extends InliningContext { private final InlineCallSiteInfo inlineCallSiteInfo; public final TypeParameterMappings typeParameterMappings; public final boolean isDefaultCompilation; + public final boolean skipSmap; public final KtElement callElement; public RootInliningContext( @@ -40,7 +41,8 @@ public class RootInliningContext extends InliningContext { @NotNull InlineCallSiteInfo classNameToInline, @NotNull ReifiedTypeInliner inliner, @Nullable TypeParameterMappings typeParameterMappings, - boolean isDefaultCompilation + boolean isDefaultCompilation, + boolean skipSmap ) { super(null, map, state, nameGenerator, TypeRemapper.createRoot(typeParameterMappings), inliner, false, false); this.callElement = callElement; @@ -48,6 +50,7 @@ public class RootInliningContext extends InliningContext { this.inlineCallSiteInfo = classNameToInline; this.typeParameterMappings = typeParameterMappings; this.isDefaultCompilation = isDefaultCompilation; + this.skipSmap = skipSmap; } @Override diff --git a/compiler/testData/codegen/boxInline/smap/inlineOnly/noSmap.1.kt b/compiler/testData/codegen/boxInline/smap/inlineOnly/noSmap.1.kt new file mode 100644 index 00000000000..c481e978f5e --- /dev/null +++ b/compiler/testData/codegen/boxInline/smap/inlineOnly/noSmap.1.kt @@ -0,0 +1,14 @@ +fun box(): String { + return "KO".reversed() +} + +//SMAP +//noSmap.1.kt +//Kotlin +//*S Kotlin +//*F +//+ 1 noSmap.1.kt +//NoSmap_1Kt +//*L +//1#1,14:1 +//*E \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/smap/inlineOnly/noSmap.2.kt b/compiler/testData/codegen/boxInline/smap/inlineOnly/noSmap.2.kt new file mode 100644 index 00000000000..d99c37ca857 --- /dev/null +++ b/compiler/testData/codegen/boxInline/smap/inlineOnly/noSmap.2.kt @@ -0,0 +1,4 @@ +package test +inline fun stub() { + +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/smap/inlineOnly/reified.1.kt b/compiler/testData/codegen/boxInline/smap/inlineOnly/reified.1.kt new file mode 100644 index 00000000000..45e90aec445 --- /dev/null +++ b/compiler/testData/codegen/boxInline/smap/inlineOnly/reified.1.kt @@ -0,0 +1,22 @@ +import test.* + +fun box(): String { + val z = className() + if (z != "String") return "fail: $z" + + return "OK" +} + +//SMAP +//reified.1.kt +//Kotlin +//*S Kotlin +//*F +//+ 1 reified.1.kt +//Reified_1Kt +//+ 2 reified.2.kt +//test/Reified_2Kt +//*L +//1#1,22:1 +//3#2:23 +//*E \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/smap/inlineOnly/reified.2.kt b/compiler/testData/codegen/boxInline/smap/inlineOnly/reified.2.kt new file mode 100644 index 00000000000..a695d4662f5 --- /dev/null +++ b/compiler/testData/codegen/boxInline/smap/inlineOnly/reified.2.kt @@ -0,0 +1,3 @@ +package test + +inline fun className() = T::class.simpleName \ No newline at end of file diff --git a/compiler/testData/integration/smoke/inlineOnly/inlineOnly.compile.expected b/compiler/testData/integration/smoke/inlineOnly/inlineOnly.compile.expected new file mode 100644 index 00000000000..a14ac74940f --- /dev/null +++ b/compiler/testData/integration/smoke/inlineOnly/inlineOnly.compile.expected @@ -0,0 +1 @@ +Return code: 0 diff --git a/compiler/testData/integration/smoke/inlineOnly/inlineOnly.kt b/compiler/testData/integration/smoke/inlineOnly/inlineOnly.kt new file mode 100644 index 00000000000..399fed593d1 --- /dev/null +++ b/compiler/testData/integration/smoke/inlineOnly/inlineOnly.kt @@ -0,0 +1,5 @@ +package InlineOnly + +fun main(args : Array) { + error("my error") +} diff --git a/compiler/testData/integration/smoke/inlineOnly/inlineOnly.run.expected b/compiler/testData/integration/smoke/inlineOnly/inlineOnly.run.expected new file mode 100644 index 00000000000..cad7d6cd4a9 --- /dev/null +++ b/compiler/testData/integration/smoke/inlineOnly/inlineOnly.run.expected @@ -0,0 +1,6 @@ + +ERR: +Exception in thread "main" java.lang.IllegalStateException: my error + at InlineOnly.InlineOnlyKt.main(inlineOnly.kt:4) + +Return code: 1 diff --git a/compiler/testData/integration/smoke/scriptException/script.expected b/compiler/testData/integration/smoke/scriptException/script.expected index 338c9e3ae51..7b2719a6aac 100644 --- a/compiler/testData/integration/smoke/scriptException/script.expected +++ b/compiler/testData/integration/smoke/scriptException/script.expected @@ -1,7 +1,7 @@ ERR: java.lang.IllegalStateException: my error - at Script.main(script.kts:12) + at Script.main(script.kts:2) at Script.a(script.kts:6) at Script.(script.kts:9) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java index 22202dfedf5..b6ff303ffa9 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java @@ -1834,6 +1834,27 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo } } + @TestMetadata("compiler/testData/codegen/boxInline/smap/inlineOnly") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class InlineOnly extends AbstractBlackBoxInlineCodegenTest { + public void testAllFilesPresentInInlineOnly() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/smap/inlineOnly"), Pattern.compile("^(.+)\\.1.kt$"), true); + } + + @TestMetadata("noSmap.1.kt") + public void testNoSmap() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/smap/inlineOnly/noSmap.1.kt"); + doTestMultiFileWithInlineCheck(fileName); + } + + @TestMetadata("reified.1.kt") + public void testReified() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/smap/inlineOnly/reified.1.kt"); + doTestMultiFileWithInlineCheck(fileName); + } + } + @TestMetadata("compiler/testData/codegen/boxInline/smap/resolve") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/integration/CompilerSmokeTest.java b/compiler/tests/org/jetbrains/kotlin/integration/CompilerSmokeTest.java index 2d4ebe46549..bfe1533e4ab 100644 --- a/compiler/tests/org/jetbrains/kotlin/integration/CompilerSmokeTest.java +++ b/compiler/tests/org/jetbrains/kotlin/integration/CompilerSmokeTest.java @@ -70,4 +70,12 @@ public class CompilerSmokeTest extends CompilerSmokeTestBase { runCompiler("script", "script.kts", "-d", jar); } + + public void testInlineOnly() throws Exception { + String jar = tmpdir.getAbsolutePath() + File.separator + "inlineOnly.jar"; + + assertEquals("compilation failed", 0, runCompiler("inlineOnly.compile", "-include-runtime", "inlineOnly.kt", "-d", jar)); + run("inlineOnly.run", "-cp", jar, "InlineOnly.InlineOnlyKt"); + } } + diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java index 9720f31fccd..df35dcc59ca 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -1834,6 +1834,27 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi } } + @TestMetadata("compiler/testData/codegen/boxInline/smap/inlineOnly") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class InlineOnly extends AbstractCompileKotlinAgainstInlineKotlinTest { + public void testAllFilesPresentInInlineOnly() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/smap/inlineOnly"), Pattern.compile("^(.+)\\.1.kt$"), true); + } + + @TestMetadata("noSmap.1.kt") + public void testNoSmap() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/smap/inlineOnly/noSmap.1.kt"); + doBoxTestWithInlineCheck(fileName); + } + + @TestMetadata("reified.1.kt") + public void testReified() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/smap/inlineOnly/reified.1.kt"); + doBoxTestWithInlineCheck(fileName); + } + } + @TestMetadata("compiler/testData/codegen/boxInline/smap/resolve") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/idea/testData/debugger/tinyApp/outs/inlineOnly.out b/idea/testData/debugger/tinyApp/outs/inlineOnly.out new file mode 100644 index 00000000000..2fe147125c7 --- /dev/null +++ b/idea/testData/debugger/tinyApp/outs/inlineOnly.out @@ -0,0 +1,9 @@ +LineBreakpoint created at inlineOnly.kt:5 +!JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !OUTPUT_PATH!;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! inlineOnly.InlineOnlyKt +Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' +inlineOnly.kt:5 +PrintStream.!EXT! +Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' + +Process finished with exit code 0 +OK diff --git a/idea/testData/debugger/tinyApp/src/stepping/stepInto/inlineOnly.kt b/idea/testData/debugger/tinyApp/src/stepping/stepInto/inlineOnly.kt new file mode 100644 index 00000000000..ecc00fde4ef --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/stepping/stepInto/inlineOnly.kt @@ -0,0 +1,8 @@ +package inlineOnly + +fun main(args: Array) { + //Breakpoint! + println("OK") +} + +// TRACING_FILTERS_ENABLED: false \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java index ffa3daa998d..13c8fbc85dd 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java @@ -235,6 +235,12 @@ public class KotlinSteppingTestGenerated extends AbstractKotlinSteppingTest { doStepIntoTest(fileName); } + @TestMetadata("inlineOnly.kt") + public void testInlineOnly() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/stepInto/inlineOnly.kt"); + doStepIntoTest(fileName); + } + @TestMetadata("returnVoid.kt") public void testReturnVoid() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/stepInto/returnVoid.kt");