[JS IR] Improve debug info for callable references and lambdas

#KT-46276
This commit is contained in:
Sergej Jaskiewicz
2022-10-28 14:22:38 +02:00
committed by Space Team
parent fe0e9db3aa
commit 512a2bfd7a
6 changed files with 33 additions and 21 deletions
@@ -304,8 +304,8 @@ class CallableReferenceLowering(private val context: CommonBackendContext) : Bod
when (callee) {
is IrConstructor ->
IrConstructorCallImpl(
startOffset,
endOffset,
UNDEFINED_OFFSET,
UNDEFINED_OFFSET,
callee.parentAsClass.defaultType,
callee.symbol,
callee.countContextTypeParameters(),
@@ -315,8 +315,8 @@ class CallableReferenceLowering(private val context: CommonBackendContext) : Bod
)
is IrSimpleFunction ->
IrCallImpl(
startOffset,
endOffset,
UNDEFINED_OFFSET,
UNDEFINED_OFFSET,
callee.returnType,
callee.symbol,
callee.typeParameters.size,
@@ -393,14 +393,17 @@ class CallableReferenceLowering(private val context: CommonBackendContext) : Bod
}
}
body = factory.createBlockBody(reference.startOffset, reference.endOffset, listOf(reference.run {
IrReturnImpl(
startOffset,
endOffset, nothingType,
symbol,
buildInvoke()
body = factory.createBlockBody(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, listOf(
IrReturnImpl(
UNDEFINED_OFFSET,
UNDEFINED_OFFSET,
nothingType,
symbol,
buildInvoke()
)
)
}))
)
}
private fun createNameProperty(clazz: IrClass) {
@@ -527,8 +527,8 @@ class InteropCallableReferenceLowering(val context: JsIrBackendContext) : BodyLo
val lambdaType = lambdaInfo.lambdaClass.defaultType
val instanceVal = JsIrBuilder.buildVar(lambdaType, factoryFunction, "i").apply {
val newCtorCall = IrConstructorCallImpl(
lambdaInfo.lambdaClass.startOffset,
lambdaInfo.lambdaClass.endOffset,
UNDEFINED_OFFSET,
UNDEFINED_OFFSET,
lambdaType,
constructor.symbol,
lambdaInfo.lambdaClass.typeParameters.size,
@@ -598,7 +598,7 @@ class InteropCallableReferenceLowering(val context: JsIrBackendContext) : BodyLo
statements.add(JsIrBuilder.buildReturn(factoryFunction.symbol, functionExpression, context.irBuiltIns.nothingType))
}
return context.irFactory.createBlockBody(lambdaInfo.lambdaClass.startOffset, lambdaInfo.lambdaClass.endOffset, statements)
return context.irFactory.createBlockBody(UNDEFINED_OFFSET, UNDEFINED_OFFSET, statements)
}
private fun createLambdaDeclaration(
@@ -621,7 +621,15 @@ class InteropCallableReferenceLowering(val context: JsIrBackendContext) : BodyLo
lambdaDeclaration.parent = parent
lambdaDeclaration.valueParameters = superInvokeFun.valueParameters.mapIndexed { id, vp ->
vp.copyTo(lambdaDeclaration, type = anyNType, name = invokeFun.valueParameters[id].name)
val originalValueParameter = invokeFun.valueParameters[id]
vp.copyTo(
irFunction = lambdaDeclaration,
origin = originalValueParameter.origin,
startOffset = originalValueParameter.startOffset,
endOffset = originalValueParameter.endOffset,
name = originalValueParameter.name,
type = anyNType,
)
}
return lambdaDeclaration
}
+2 -1
View File
@@ -23,9 +23,10 @@ fun f(block: () -> Unit) {
// EXPECTATIONS JS_IR
// test.kt:3 box
// test.kt:4 box
// test.kt:4 box$lambda
// test.kt:4 box
// test.kt:10 f
// test.kt:5 box$lambda$lambda
// test.kt:6 box$lambda$lambda
// test.kt:11 f
// test.kt:7 box
// test.kt:7 box
+2 -1
View File
@@ -60,10 +60,11 @@ fun box() {
// test.kt:3 <init>
// test.kt:22 box
// test.kt:9 foo
// test.kt:7 E$foo$lambda
// test.kt:15 E2_initEntries
// test.kt:14 <init>
// test.kt:14 <init>
// test.kt:17 E2_initEntries
// test.kt:14 <init>
// test.kt:14 <init>
// test.kt:24 box
// test.kt:24 box
+2 -3
View File
@@ -32,10 +32,9 @@ fun g() {}
// EXPECTATIONS JS_IR
// test.kt:3 box
// test.kt:4 box
// test.kt:4 g$ref
// test.kt:4 box
// test.kt:8 f
// test.kt:4 g$ref$lambda
// test.kt:11 g
// test.kt:4 g$ref$lambda
// test.kt:9 f
// test.kt:5 box
// test.kt:5 box
+1 -1
View File
@@ -5,4 +5,4 @@ fun foo(x: Int): () -> Unit = {
fun bar() = 23
// LINES(JS): 1 1 1 3 2 2 3 3 1 1 1 5 5 5
// LINES(JS_IR): 1 1 3 3 1 5 5 5 5 1 1 1 2 2 3 3
// LINES(JS_IR): 1 1 3 3 1 5 5 5 5 1 1 2 2 3 3