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 d07f084c789..a565ad1713a 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java @@ -219,6 +219,12 @@ public class MethodInliner { int valueParamShift = Math.max(getNextLocalIndex(), markerShift);//NB: don't inline cause it changes putStackValuesIntoLocals(info.getInvokeParamsWithoutCaptured(), valueParamShift, this, desc); + if (invokeCall.lambdaInfo.getFunctionDescriptor().getValueParameters().isEmpty()) { + // There won't be no parameters processing and line call can be left without actual instructions. + // Note: if function is called on the line with other instructions like 1 + foo() no will still be generated. + visitInsn(Opcodes.NOP); + } + addInlineMarker(this, true); Parameters lambdaParameters = info.addAllParameters(nodeRemapper); diff --git a/compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/nopInlineFuns.kt b/compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/nopInlineFuns.kt index 17d8063be40..fd0484340e0 100644 --- a/compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/nopInlineFuns.kt +++ b/compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/nopInlineFuns.kt @@ -23,4 +23,4 @@ fun simpleFunVoid(f: () -> Unit): Unit { return f() } -// 3 NOP +// 5 NOP diff --git a/compiler/testData/codegen/bytecodeText/inline/linenumberForNoParametersArgumentCallInExpression.kt b/compiler/testData/codegen/bytecodeText/inline/linenumberForNoParametersArgumentCallInExpression.kt new file mode 100644 index 00000000000..5506819e5e4 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/inline/linenumberForNoParametersArgumentCallInExpression.kt @@ -0,0 +1,14 @@ +fun box() { + lookAtMe { + 12 + } +} + +inline fun lookAtMe(f: () -> Int): Int { + val a = 42 + a + f() // Even this line already has meaningful instraction nop is still generated + return 13 +} + +// TODO: Less NOPs is better +// 2 NOP \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/inline/linenumberForOneParametersArgumentCall.kt b/compiler/testData/codegen/bytecodeText/inline/linenumberForOneParametersArgumentCall.kt new file mode 100644 index 00000000000..47c0850198a --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/inline/linenumberForOneParametersArgumentCall.kt @@ -0,0 +1,12 @@ +fun box() { + lookAtMe { + val c = "c" + } +} + +inline fun lookAtMe(f: (String) -> Unit) { + val a = "a" + f(a) // Should be no unneeded nops on this line, that might be generated for zero-parameters lambda +} + +// 2 NOP \ No newline at end of file diff --git a/compiler/testData/lineNumber/custom/functionCallWithInlinedLambdaParam.kt b/compiler/testData/lineNumber/custom/functionCallWithInlinedLambdaParam.kt index 53b0cf92b11..803dfda8107 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 17 18 +3 4 19 +6 20 21 +7 8 22 +9 12 13 14 \ No newline at end of file +// 2 17 18 3 4 19 +6 20 21 7 8 22 +9 12 13 14 \ No newline at end of file diff --git a/compiler/testData/lineNumber/custom/noParametersArgumentCallInExpression.kt b/compiler/testData/lineNumber/custom/noParametersArgumentCallInExpression.kt new file mode 100644 index 00000000000..3e5cff4c630 --- /dev/null +++ b/compiler/testData/lineNumber/custom/noParametersArgumentCallInExpression.kt @@ -0,0 +1,12 @@ +fun box() { + lookAtMe { + 42 + } +} + +inline fun lookAtMe(f: () -> Int) { + val a = 21 + a + f() +} + +// 2 13 14 3 15 +5 8 9 10 \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index 5855946ca74..fcc2c7c238c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -1063,6 +1063,18 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { doTest(fileName); } + @TestMetadata("linenumberForNoParametersArgumentCallInExpression.kt") + public void testLinenumberForNoParametersArgumentCallInExpression() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/inline/linenumberForNoParametersArgumentCallInExpression.kt"); + doTest(fileName); + } + + @TestMetadata("linenumberForOneParametersArgumentCall.kt") + public void testLinenumberForOneParametersArgumentCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/inline/linenumberForOneParametersArgumentCall.kt"); + doTest(fileName); + } + @TestMetadata("noSynAccessor.kt") public void testNoSynAccessor() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/inline/noSynAccessor.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LineNumberTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LineNumberTestGenerated.java index 6dade8bb30f..80acf3273da 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LineNumberTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LineNumberTestGenerated.java @@ -220,6 +220,12 @@ public class LineNumberTestGenerated extends AbstractLineNumberTest { doTestCustom(fileName); } + @TestMetadata("noParametersArgumentCallInExpression.kt") + public void testNoParametersArgumentCallInExpression() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/lineNumber/custom/noParametersArgumentCallInExpression.kt"); + doTestCustom(fileName); + } + @TestMetadata("smapInlineAsArgument.kt") public void testSmapInlineAsArgument() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/lineNumber/custom/smapInlineAsArgument.kt"); diff --git a/idea/testData/debugger/tinyApp/outs/noParameterLambdaArgumentCallInInline.out b/idea/testData/debugger/tinyApp/outs/noParameterLambdaArgumentCallInInline.out new file mode 100644 index 00000000000..dbff975ea0a --- /dev/null +++ b/idea/testData/debugger/tinyApp/outs/noParameterLambdaArgumentCallInInline.out @@ -0,0 +1,8 @@ +LineBreakpoint created at noParameterLambdaArgumentCallInInline.kt:16 +!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! noParameterLambdaArgumentCallInInline.NoParameterLambdaArgumentCallInInlineKt +Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' +noParameterLambdaArgumentCallInInline.kt:16 +noParameterLambdaArgumentCallInInline.kt:17 +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/src/stepping/stepOver/noParameterLambdaArgumentCallInInline.kt b/idea/testData/debugger/tinyApp/src/stepping/stepOver/noParameterLambdaArgumentCallInInline.kt new file mode 100644 index 00000000000..eb950f3289c --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/stepping/stepOver/noParameterLambdaArgumentCallInInline.kt @@ -0,0 +1,18 @@ +package noParameterLambdaArgumentCallInInline + +/* + KT-6477 Breakpoints do not work in inline functions at line where inlined argument without arguments is invoked + */ + +fun main(args: Array) { + lookAtMe { + val c = "c" + } +} + +inline fun lookAtMe(f: () -> Unit) { + val a = "a" + //Breakpoint! + f() + val b = "b" +} \ 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 fbfb4fba1a1..c7138ec93fb 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java @@ -433,6 +433,12 @@ public class KotlinSteppingTestGenerated extends AbstractKotlinSteppingTest { doStepOverTest(fileName); } + @TestMetadata("noParameterLambdaArgumentCallInInline.kt") + public void testNoParameterLambdaArgumentCallInInline() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/stepOver/noParameterLambdaArgumentCallInInline.kt"); + doStepOverTest(fileName); + } + @TestMetadata("stepOverCatchClause.kt") public void testStepOverCatchClause() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/stepOver/stepOverCatchClause.kt");