JVM IR: Fix line numbers in callable reference classes

This commit is contained in:
Steven Schäfer
2019-12-19 11:38:58 +01:00
committed by max-kammerer
parent 59f2aa7add
commit e261b1e2de
9 changed files with 143 additions and 8 deletions
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.backend.common.BackendContext
import org.jetbrains.kotlin.backend.common.FileLoweringPass
import org.jetbrains.kotlin.backend.common.IrElementVisitorVoidWithContext
import org.jetbrains.kotlin.backend.common.ScopeWithIr
import org.jetbrains.kotlin.backend.common.descriptors.*
import org.jetbrains.kotlin.backend.common.descriptors.synthesizedName
import org.jetbrains.kotlin.backend.common.ir.*
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.builders.Scope
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
@@ -411,9 +412,9 @@ class LocalDeclarationsLowering(
0,
localClassContext.capturedValueToField.map { (capturedValue, field) ->
IrSetFieldImpl(
irClass.startOffset, irClass.endOffset, field.symbol,
IrGetValueImpl(irClass.startOffset, irClass.endOffset, irClass.thisReceiver!!.symbol),
constructorContext.irGet(irClass.startOffset, irClass.endOffset, capturedValue)!!,
UNDEFINED_OFFSET, UNDEFINED_OFFSET, field.symbol,
IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irClass.thisReceiver!!.symbol),
constructorContext.irGet(UNDEFINED_OFFSET, UNDEFINED_OFFSET, capturedValue)!!,
context.irBuiltIns.unitType,
STATEMENT_ORIGIN_INITIALIZER_OF_FIELD_FOR_CAPTURED_VALUE
)
@@ -185,7 +185,6 @@ internal class CallableReferenceLowering(private val context: JvmBackendContext)
private fun createConstructor(): IrConstructor =
functionReferenceClass.addConstructor {
setSourceRange(irFunctionReference)
origin = JvmLoweredDeclarationOrigin.GENERATED_MEMBER_IN_CALLABLE_REFERENCE
returnType = functionReferenceClass.defaultType
isPrimary = true
@@ -227,6 +226,7 @@ internal class CallableReferenceLowering(private val context: JvmBackendContext)
private fun createInvokeMethod(receiverVar: IrValueDeclaration?): IrSimpleFunction =
functionReferenceClass.addFunction {
setSourceRange(if (isLambda) callee else irFunctionReference)
name = superMethod.owner.name
returnType = callee.returnType
isSuspend = callee.isSuspend
@@ -244,8 +244,9 @@ internal class CallableReferenceLowering(private val context: JvmBackendContext)
}
valueParameters += valueParameterMap.values
body = context.createIrBuilder(symbol).irBlockBody(startOffset, endOffset) {
callee.body?.statements?.forEach { statement ->
val calleeBody = callee.body as IrBlockBody
body = context.createIrBuilder(symbol).irBlockBody(calleeBody.startOffset, calleeBody.endOffset) {
calleeBody.statements.forEach { statement ->
+statement.transform(object : IrElementTransformerVoid() {
override fun visitGetValue(expression: IrGetValue): IrExpression {
val replacement = valueParameterMap[expression.symbol.owner]
+23
View File
@@ -0,0 +1,23 @@
// FILE: test.kt
fun box() {
var x = false
f {
x = true
}
}
fun f(block: () -> Unit) {
block()
}
// LINENUMBERS
// TestKt.box():3
// TestKt.box():4
// TestKt.f(kotlin.jvm.functions.Function0):10
// TestKt$box$1.invoke():5
// TestKt$box$1.invoke():6
// TestKt$box$1.invoke():-1
// TestKt$box$1.invoke():-1
// TestKt.f(kotlin.jvm.functions.Function0):10
// TestKt.f(kotlin.jvm.functions.Function0):11
// TestKt.box():7
@@ -0,0 +1,20 @@
// FILE: test.kt
fun box() {
var x = false
f {
x = true
}
}
inline fun f(block: () -> Unit) {
block()
}
// LINENUMBERS
// TestKt.box():3
// TestKt.box():4
// TestKt.box():10
// TestKt.box():5
// TestKt.box():6
// TestKt.box():11
// TestKt.box():7
@@ -0,0 +1,20 @@
// FILE: test.kt
fun box() {
var x = false
f(::g)
}
inline fun f(block: () -> Unit) {
block()
}
fun g() {}
// LINENUMBERS
// TestKt.box():3
// TestKt.box():4
// TestKt.box():8
// TestKt.box():4
// TestKt.g():11
// TestKt.box():9
// TestKt.box():5
@@ -0,0 +1,23 @@
// FILE: test.kt
fun box() {
var x = false
f(::g)
}
fun f(block: () -> Unit) {
block()
}
fun g() {}
// LINENUMBERS
// TestKt.box():3
// TestKt.box():4
// TestKt.f(kotlin.jvm.functions.Function0):8
// TestKt.g():11
// TestKt$box$1.invoke():4
// TestKt$box$1.invoke():-1
// TestKt$box$1.invoke():-1
// TestKt.f(kotlin.jvm.functions.Function0):8
// TestKt.f(kotlin.jvm.functions.Function0):9
// TestKt.box():5
@@ -12,5 +12,4 @@ fun foo(f: () -> Unit) {
f()
}
// IGNORE_BACKEND: JVM_IR
// 2 6 9 12 13 3 4 7 8
@@ -31,6 +31,12 @@ public class IrSteppingTestGenerated extends AbstractIrSteppingTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/debug/stepping"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("callableReference.kt")
public void testCallableReference() throws Exception {
runTest("compiler/testData/debug/stepping/callableReference.kt");
}
@Test
@TestMetadata("conjunction.kt")
public void testConjunction() throws Exception {
@@ -55,6 +61,24 @@ public class IrSteppingTestGenerated extends AbstractIrSteppingTest {
runTest("compiler/testData/debug/stepping/IfTrueThenFalse.kt");
}
@Test
@TestMetadata("inlineCallableReference.kt")
public void testInlineCallableReference() throws Exception {
runTest("compiler/testData/debug/stepping/inlineCallableReference.kt");
}
@Test
@TestMetadata("inlineNamedCallableReference.kt")
public void testInlineNamedCallableReference() throws Exception {
runTest("compiler/testData/debug/stepping/inlineNamedCallableReference.kt");
}
@Test
@TestMetadata("namedCallableReference.kt")
public void testNamedCallableReference() throws Exception {
runTest("compiler/testData/debug/stepping/namedCallableReference.kt");
}
@Test
@TestMetadata("recursion.kt")
public void testRecursion() throws Exception {
@@ -31,6 +31,12 @@ public class SteppingTestGenerated extends AbstractSteppingTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/debug/stepping"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@Test
@TestMetadata("callableReference.kt")
public void testCallableReference() throws Exception {
runTest("compiler/testData/debug/stepping/callableReference.kt");
}
@Test
@TestMetadata("conjunction.kt")
public void testConjunction() throws Exception {
@@ -55,6 +61,24 @@ public class SteppingTestGenerated extends AbstractSteppingTest {
runTest("compiler/testData/debug/stepping/IfTrueThenFalse.kt");
}
@Test
@TestMetadata("inlineCallableReference.kt")
public void testInlineCallableReference() throws Exception {
runTest("compiler/testData/debug/stepping/inlineCallableReference.kt");
}
@Test
@TestMetadata("inlineNamedCallableReference.kt")
public void testInlineNamedCallableReference() throws Exception {
runTest("compiler/testData/debug/stepping/inlineNamedCallableReference.kt");
}
@Test
@TestMetadata("namedCallableReference.kt")
public void testNamedCallableReference() throws Exception {
runTest("compiler/testData/debug/stepping/namedCallableReference.kt");
}
@Test
@TestMetadata("recursion.kt")
public void testRecursion() throws Exception {