JVM IR: Fix line numbers in callable reference classes
This commit is contained in:
committed by
max-kammerer
parent
59f2aa7add
commit
e261b1e2de
+5
-4
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.backend.common.BackendContext
|
|||||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||||
import org.jetbrains.kotlin.backend.common.IrElementVisitorVoidWithContext
|
import org.jetbrains.kotlin.backend.common.IrElementVisitorVoidWithContext
|
||||||
import org.jetbrains.kotlin.backend.common.ScopeWithIr
|
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.backend.common.ir.*
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
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.descriptors.Visibility
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.IrStatement
|
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.builders.Scope
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
||||||
@@ -411,9 +412,9 @@ class LocalDeclarationsLowering(
|
|||||||
0,
|
0,
|
||||||
localClassContext.capturedValueToField.map { (capturedValue, field) ->
|
localClassContext.capturedValueToField.map { (capturedValue, field) ->
|
||||||
IrSetFieldImpl(
|
IrSetFieldImpl(
|
||||||
irClass.startOffset, irClass.endOffset, field.symbol,
|
UNDEFINED_OFFSET, UNDEFINED_OFFSET, field.symbol,
|
||||||
IrGetValueImpl(irClass.startOffset, irClass.endOffset, irClass.thisReceiver!!.symbol),
|
IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irClass.thisReceiver!!.symbol),
|
||||||
constructorContext.irGet(irClass.startOffset, irClass.endOffset, capturedValue)!!,
|
constructorContext.irGet(UNDEFINED_OFFSET, UNDEFINED_OFFSET, capturedValue)!!,
|
||||||
context.irBuiltIns.unitType,
|
context.irBuiltIns.unitType,
|
||||||
STATEMENT_ORIGIN_INITIALIZER_OF_FIELD_FOR_CAPTURED_VALUE
|
STATEMENT_ORIGIN_INITIALIZER_OF_FIELD_FOR_CAPTURED_VALUE
|
||||||
)
|
)
|
||||||
|
|||||||
+4
-3
@@ -185,7 +185,6 @@ internal class CallableReferenceLowering(private val context: JvmBackendContext)
|
|||||||
|
|
||||||
private fun createConstructor(): IrConstructor =
|
private fun createConstructor(): IrConstructor =
|
||||||
functionReferenceClass.addConstructor {
|
functionReferenceClass.addConstructor {
|
||||||
setSourceRange(irFunctionReference)
|
|
||||||
origin = JvmLoweredDeclarationOrigin.GENERATED_MEMBER_IN_CALLABLE_REFERENCE
|
origin = JvmLoweredDeclarationOrigin.GENERATED_MEMBER_IN_CALLABLE_REFERENCE
|
||||||
returnType = functionReferenceClass.defaultType
|
returnType = functionReferenceClass.defaultType
|
||||||
isPrimary = true
|
isPrimary = true
|
||||||
@@ -227,6 +226,7 @@ internal class CallableReferenceLowering(private val context: JvmBackendContext)
|
|||||||
|
|
||||||
private fun createInvokeMethod(receiverVar: IrValueDeclaration?): IrSimpleFunction =
|
private fun createInvokeMethod(receiverVar: IrValueDeclaration?): IrSimpleFunction =
|
||||||
functionReferenceClass.addFunction {
|
functionReferenceClass.addFunction {
|
||||||
|
setSourceRange(if (isLambda) callee else irFunctionReference)
|
||||||
name = superMethod.owner.name
|
name = superMethod.owner.name
|
||||||
returnType = callee.returnType
|
returnType = callee.returnType
|
||||||
isSuspend = callee.isSuspend
|
isSuspend = callee.isSuspend
|
||||||
@@ -244,8 +244,9 @@ internal class CallableReferenceLowering(private val context: JvmBackendContext)
|
|||||||
}
|
}
|
||||||
valueParameters += valueParameterMap.values
|
valueParameters += valueParameterMap.values
|
||||||
|
|
||||||
body = context.createIrBuilder(symbol).irBlockBody(startOffset, endOffset) {
|
val calleeBody = callee.body as IrBlockBody
|
||||||
callee.body?.statements?.forEach { statement ->
|
body = context.createIrBuilder(symbol).irBlockBody(calleeBody.startOffset, calleeBody.endOffset) {
|
||||||
|
calleeBody.statements.forEach { statement ->
|
||||||
+statement.transform(object : IrElementTransformerVoid() {
|
+statement.transform(object : IrElementTransformerVoid() {
|
||||||
override fun visitGetValue(expression: IrGetValue): IrExpression {
|
override fun visitGetValue(expression: IrGetValue): IrExpression {
|
||||||
val replacement = valueParameterMap[expression.symbol.owner]
|
val replacement = valueParameterMap[expression.symbol.owner]
|
||||||
|
|||||||
@@ -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()
|
f()
|
||||||
}
|
}
|
||||||
|
|
||||||
// IGNORE_BACKEND: JVM_IR
|
|
||||||
// 2 6 9 12 13 3 4 7 8
|
// 2 6 9 12 13 3 4 7 8
|
||||||
|
|||||||
+24
@@ -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);
|
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
|
@Test
|
||||||
@TestMetadata("conjunction.kt")
|
@TestMetadata("conjunction.kt")
|
||||||
public void testConjunction() throws Exception {
|
public void testConjunction() throws Exception {
|
||||||
@@ -55,6 +61,24 @@ public class IrSteppingTestGenerated extends AbstractIrSteppingTest {
|
|||||||
runTest("compiler/testData/debug/stepping/IfTrueThenFalse.kt");
|
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
|
@Test
|
||||||
@TestMetadata("recursion.kt")
|
@TestMetadata("recursion.kt")
|
||||||
public void testRecursion() throws Exception {
|
public void testRecursion() throws Exception {
|
||||||
|
|||||||
+24
@@ -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);
|
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
|
@Test
|
||||||
@TestMetadata("conjunction.kt")
|
@TestMetadata("conjunction.kt")
|
||||||
public void testConjunction() throws Exception {
|
public void testConjunction() throws Exception {
|
||||||
@@ -55,6 +61,24 @@ public class SteppingTestGenerated extends AbstractSteppingTest {
|
|||||||
runTest("compiler/testData/debug/stepping/IfTrueThenFalse.kt");
|
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
|
@Test
|
||||||
@TestMetadata("recursion.kt")
|
@TestMetadata("recursion.kt")
|
||||||
public void testRecursion() throws Exception {
|
public void testRecursion() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user