diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AbstractClassBuilder.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AbstractClassBuilder.java index a4535dbb94c..8074a258795 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AbstractClassBuilder.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AbstractClassBuilder.java @@ -20,6 +20,7 @@ import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.codegen.inline.FileMapping; +import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil; import org.jetbrains.kotlin.codegen.inline.SMAPBuilder; import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin; import org.jetbrains.org.objectweb.asm.*; @@ -103,7 +104,7 @@ public abstract class AbstractClassBuilder implements ClassBuilder { @Override public void done() { - if (!fileMappings.isEmpty()) { + if (!fileMappings.isEmpty() && InlineCodegenUtil.GENERATE_SMAP) { FileMapping origin = fileMappings.get(0); assert sourceName == null || origin.getName().equals(sourceName) : "Error " + origin.getName() + " != " + sourceName; getVisitor().visitSource(origin.getName(), new SMAPBuilder(origin.getName(), origin.getPath(), fileMappings).build()); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.java index 2c793659426..08fd0fb1020 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.java @@ -167,9 +167,14 @@ public class AnonymousObjectTransformer { //seems we can't do any clever mapping cause we don't know any about original class name sourceMapper = IdenticalSourceMapper.INSTANCE$; } + if (sourceInfo != null && !InlineCodegenUtil.GENERATE_SMAP) { + classBuilder.visitSource(sourceInfo, debugInfo); + } } else { - classBuilder.visitSource(sourceInfo, debugInfo); + if (sourceInfo != null) { + classBuilder.visitSource(sourceInfo, debugInfo); + } sourceMapper = IdenticalSourceMapper.INSTANCE$; } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineAdapter.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineAdapter.java index 8025030deaf..776f92a66e1 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineAdapter.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineAdapter.java @@ -87,7 +87,12 @@ public class InlineAdapter extends InstructionAdapter { @Override public void visitLineNumber(int line, Label start) { - sourceMapper.visitLineNumber(mv, line, start); + if (InlineCodegenUtil.GENERATE_SMAP) { + sourceMapper.visitLineNumber(mv, line, start); + } + else { + super.visitLineNumber(line, start); + } } @Override diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegenUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegenUtil.java index 4f627d046de..b78445b5df3 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegenUtil.java @@ -63,6 +63,7 @@ import static org.jetbrains.kotlin.resolve.DescriptorUtils.getFqName; import static org.jetbrains.kotlin.resolve.DescriptorUtils.isTrait; public class InlineCodegenUtil { + public static final boolean GENERATE_SMAP = false; public static final int API = Opcodes.ASM5; public static final String INVOKE = "invoke"; @@ -124,7 +125,7 @@ public class InlineCodegenUtil { } return null; } - }, ClassReader.SKIP_FRAMES); + }, ClassReader.SKIP_FRAMES | (GENERATE_SMAP ? 0 : ClassReader.SKIP_DEBUG)); SMAP smap = SMAPParser.parseOrCreateDefault(debugInfo[1], debugInfo[0], classId.toString(), lines[0], lines[1]); return new SMAPAndMethodNode(node[0], smap); 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 57e07fc69c9..9849ff3f5a3 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java @@ -329,6 +329,13 @@ public class MethodInliner { super.visitMaxs(maxStack, maxLocals + capturedParamsSize); } + @Override + public void visitLineNumber(int line, @NotNull Label start) { + if(isInliningLambda || InlineCodegenUtil.GENERATE_SMAP) { + super.visitLineNumber(line, start); + } + } + @Override public void visitLocalVariable( @NotNull String name, @NotNull String desc, String signature, @NotNull Label start, @NotNull Label end, int index diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP.kt index 4a5783d2df7..143a7a9eb20 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP.kt @@ -367,5 +367,4 @@ data open public class RangeMapping(val source: Int, val dest: Int, var range: I return -1 } } -} - +} \ No newline at end of file diff --git a/compiler/testData/lineNumber/custom/callWithReceiver.kt b/compiler/testData/lineNumber/custom/callWithReceiver.kt index acf769512aa..c073c8a0895 100644 --- a/compiler/testData/lineNumber/custom/callWithReceiver.kt +++ b/compiler/testData/lineNumber/custom/callWithReceiver.kt @@ -12,4 +12,4 @@ fun foo() { .bar() } -// 2 3 7 8 9 11 12 17 13 +// 2 3 7 8 9 11 12 13 diff --git a/compiler/testData/lineNumber/custom/chainCall.kt b/compiler/testData/lineNumber/custom/chainCall.kt index 991ed7c35eb..2d49981361e 100644 --- a/compiler/testData/lineNumber/custom/chainCall.kt +++ b/compiler/testData/lineNumber/custom/chainCall.kt @@ -12,4 +12,4 @@ fun foo() { .bar() } -// 2 3 7 8 9 11 17 12 17 13 +// 2 3 7 8 9 11 12 13 diff --git a/compiler/testData/lineNumber/custom/functionCallWithDefault.kt b/compiler/testData/lineNumber/custom/functionCallWithDefault.kt index 9f57ad21f88..01e61026258 100644 --- a/compiler/testData/lineNumber/custom/functionCallWithDefault.kt +++ b/compiler/testData/lineNumber/custom/functionCallWithDefault.kt @@ -9,4 +9,4 @@ fun foo(i: Int = 1) { inline fun bar(i: Int = 1) { } -// 2 3 9 4 7 6 10 9 10 +// 2 3 4 7 6 10 9 diff --git a/compiler/testData/lineNumber/custom/functionCallWithInlinedLambdaParam.kt b/compiler/testData/lineNumber/custom/functionCallWithInlinedLambdaParam.kt index 95cad2a2f6c..ddf5913f7be 100644 --- a/compiler/testData/lineNumber/custom/functionCallWithInlinedLambdaParam.kt +++ b/compiler/testData/lineNumber/custom/functionCallWithInlinedLambdaParam.kt @@ -13,4 +13,4 @@ inline fun foo(f: () -> Unit) { f() } -// 2 12 3 6 12 7 9 12 13 14 +// 2 3 6 7 9 12 13 14 diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractSMAPBaseTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractSMAPBaseTest.kt index 54caebe7739..ef5613210e9 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractSMAPBaseTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractSMAPBaseTest.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.jvm.compiler import com.intellij.openapi.util.io.FileUtil import org.jetbrains.kotlin.backend.common.output.OutputFile +import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil import org.jetbrains.kotlin.load.kotlin.PackageClassUtils import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi.JetFile @@ -65,6 +66,10 @@ public trait AbstractSMAPBaseTest { } fun checkSMAP(inputFiles: List, outputFiles: List) { + if (!InlineCodegenUtil.GENERATE_SMAP) { + return + } + val sourceData = inputFiles.map { extractSmapFromSource(it) }.filterNotNull() val compiledData = extractSMAPFromClasses(outputFiles).groupBy { it.sourceFile diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.java index 21b94681b0a..9e500c77357 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.java @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.cli.common.messages.MessageCollectorPlainTextToStrea import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler; import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles; import org.jetbrains.kotlin.cli.jvm.compiler.JetCoreEnvironment; +import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil; import org.jetbrains.kotlin.config.CompilerConfiguration; import org.jetbrains.kotlin.descriptors.DeclarationDescriptor; import org.jetbrains.kotlin.descriptors.PackageViewDescriptor; @@ -222,15 +223,21 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir { "-d", tmpdir.getPath() )); + ClassWriter cw; File inlineFunClass = new File(tmpdir.getAbsolutePath(), "test/A.class"); - ClassReader reader = new ClassReader(new FileInputStream(inlineFunClass)); - ClassWriter cw = new ClassWriter(Opcodes.ASM5); - reader.accept(new ClassVisitor(Opcodes.ASM5, cw) { - @Override - public void visitSource(String source, String debug) { - //skip debug info - } - }, 0); + FileInputStream is = new FileInputStream(inlineFunClass); + try { + ClassReader reader = new ClassReader(is); + cw = new ClassWriter(Opcodes.ASM5); + reader.accept(new ClassVisitor(Opcodes.ASM5, cw) { + @Override + public void visitSource(String source, String debug) { + //skip debug info + } + }, 0); + } finally { + is.close(); + } assert inlineFunClass.delete(); assert !inlineFunClass.exists(); @@ -250,16 +257,21 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir { "-d", tmpdir.getPath() )); - File resultFile = new File(tmpdir.getAbsolutePath(), "test/B.class"); - reader = new ClassReader(new FileInputStream(resultFile)); final Ref debugInfo = new Ref(); - reader.accept(new ClassVisitor(Opcodes.ASM5) { - @Override - public void visitSource(String source, String debug) { - //skip debug info - debugInfo.set(debug); - } - }, 0); + File resultFile = new File(tmpdir.getAbsolutePath(), "test/B.class"); + FileInputStream resultStream = new FileInputStream(resultFile); + try { + ClassReader reader = new ClassReader(resultStream); + reader.accept(new ClassVisitor(Opcodes.ASM5) { + @Override + public void visitSource(String source, String debug) { + //skip debug info + debugInfo.set(debug); + } + }, 0); + } finally { + resultStream.close(); + } String expected = "SMAP\n" + "source.kt\n" + @@ -272,6 +284,10 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir { "1#1,13:1\n" + "*E\n"; - assertEquals(expected, debugInfo.get()); + if (InlineCodegenUtil.GENERATE_SMAP) { + assertEquals(expected, debugInfo.get()); + } else { + assertEquals(null, debugInfo.get()); + } } } diff --git a/idea/testData/debugger/tinyApp/outs/stepIntoFromInlineFun.out b/idea/testData/debugger/tinyApp/outs/stepIntoFromInlineFun.out index 66e28ac77f7..ab604f69190 100644 --- a/idea/testData/debugger/tinyApp/outs/stepIntoFromInlineFun.out +++ b/idea/testData/debugger/tinyApp/outs/stepIntoFromInlineFun.out @@ -1,8 +1,6 @@ LineBreakpoint created at stepIntoFromInlineFun.kt:13 !JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !APP_PATH!\classes;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! stepIntoFromInlineFun.StepIntoFromInlineFunPackage Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' -stepIntoFromInlineFun.kt:13 -stepIntoFromInlineFun.kt:7 Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' Process finished with exit code 0 diff --git a/idea/testData/debugger/tinyApp/outs/stepIntoInlineFun.out b/idea/testData/debugger/tinyApp/outs/stepIntoInlineFun.out index 4a6ab6e8ef6..dafec770b60 100644 --- a/idea/testData/debugger/tinyApp/outs/stepIntoInlineFun.out +++ b/idea/testData/debugger/tinyApp/outs/stepIntoInlineFun.out @@ -2,8 +2,8 @@ LineBreakpoint created at stepIntoInlineFun.kt:8 !JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !APP_PATH!\classes;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! stepIntoInlineFun.StepIntoInlineFunPackage Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' stepIntoInlineFun.kt:8 -stepIntoInlineFun.kt:13 stepIntoInlineFun.kt:8 +stepIntoInlineFun.kt:9 Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' Process finished with exit code 0 diff --git a/idea/testData/debugger/tinyApp/outs/stepIntoStdLibInlineFun.out b/idea/testData/debugger/tinyApp/outs/stepIntoStdLibInlineFun.out index 993cb3d5e01..9fb47428536 100644 --- a/idea/testData/debugger/tinyApp/outs/stepIntoStdLibInlineFun.out +++ b/idea/testData/debugger/tinyApp/outs/stepIntoStdLibInlineFun.out @@ -2,7 +2,7 @@ LineBreakpoint created at stepIntoStdLibInlineFun.kt:6 !JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !APP_PATH!\classes;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! stepIntoStdLibInlineFun.StepIntoStdLibInlineFunPackage Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' stepIntoStdLibInlineFun.kt:6 -_Mapping.!EXT! +ArrayList.!EXT! resuming stepIntoStdLibInlineFun.kt:5 Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'