[JS IR] Improve debug info for if and when statements
#KT-46276
This commit is contained in:
committed by
Space Team
parent
ccbb2a08a0
commit
4ae03ea74a
@@ -157,9 +157,29 @@ object JsIrBuilder {
|
||||
fun buildBreak(type: IrType, loop: IrLoop) = IrBreakImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, loop)
|
||||
fun buildContinue(type: IrType, loop: IrLoop) = IrContinueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, loop)
|
||||
|
||||
fun buildIfElse(type: IrType, cond: IrExpression, thenBranch: IrExpression, elseBranch: IrExpression? = null): IrWhen = buildIfElse(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, cond, thenBranch, elseBranch, JsStatementOrigins.SYNTHESIZED_STATEMENT
|
||||
)
|
||||
fun buildIfElse(
|
||||
type: IrType,
|
||||
cond: IrExpression,
|
||||
thenBranch: IrExpression,
|
||||
elseBranch: IrExpression? = null,
|
||||
thenBranchStartOffset: Int = cond.startOffset,
|
||||
thenBranchEndOffset: Int = thenBranch.endOffset,
|
||||
elseBranchStartOffset: Int = UNDEFINED_OFFSET,
|
||||
elseBranchEndOffset: Int = elseBranch?.endOffset ?: UNDEFINED_OFFSET,
|
||||
): IrWhen =
|
||||
buildIfElse(
|
||||
startOffset = UNDEFINED_OFFSET,
|
||||
endOffset = UNDEFINED_OFFSET,
|
||||
type = type,
|
||||
cond = cond,
|
||||
thenBranch = thenBranch,
|
||||
elseBranch = elseBranch,
|
||||
origin = JsStatementOrigins.SYNTHESIZED_STATEMENT,
|
||||
thenBranchStartOffset = thenBranchStartOffset,
|
||||
thenBranchEndOffset = thenBranchEndOffset,
|
||||
elseBranchStartOffset = elseBranchStartOffset,
|
||||
elseBranchEndOffset = elseBranchEndOffset
|
||||
)
|
||||
|
||||
fun buildIfElse(
|
||||
startOffset: Int,
|
||||
@@ -168,13 +188,17 @@ object JsIrBuilder {
|
||||
cond: IrExpression,
|
||||
thenBranch: IrExpression,
|
||||
elseBranch: IrExpression? = null,
|
||||
origin: IrStatementOrigin? = null
|
||||
origin: IrStatementOrigin? = null,
|
||||
thenBranchStartOffset: Int = cond.startOffset,
|
||||
thenBranchEndOffset: Int = thenBranch.endOffset,
|
||||
elseBranchStartOffset: Int = UNDEFINED_OFFSET,
|
||||
elseBranchEndOffset: Int = elseBranch?.endOffset ?: UNDEFINED_OFFSET,
|
||||
): IrWhen {
|
||||
val element = IrIfThenElseImpl(startOffset, endOffset, type, origin)
|
||||
element.branches.add(IrBranchImpl(cond, thenBranch))
|
||||
element.branches.add(IrBranchImpl(thenBranchStartOffset, thenBranchEndOffset, cond, thenBranch))
|
||||
if (elseBranch != null) {
|
||||
val irTrue = IrConstImpl.boolean(UNDEFINED_OFFSET, UNDEFINED_OFFSET, cond.type, true)
|
||||
element.branches.add(IrElseBranchImpl(irTrue, elseBranch))
|
||||
val irTrue = IrConstImpl.constTrue(UNDEFINED_OFFSET, UNDEFINED_OFFSET, cond.type)
|
||||
element.branches.add(IrElseBranchImpl(elseBranchStartOffset, elseBranchEndOffset, irTrue, elseBranch))
|
||||
}
|
||||
|
||||
return element
|
||||
|
||||
+12
-7
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.backend.common.ir.isPure
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsCommonBackendContext
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
|
||||
import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder
|
||||
@@ -424,13 +425,17 @@ class BlockDecomposerTransformer(
|
||||
isElseBranch(orig) -> (res as? IrBlock)?.statements ?: listOf(res)
|
||||
else -> listOf(
|
||||
JsIrBuilder.buildIfElse(
|
||||
orig.startOffset,
|
||||
orig.endOffset,
|
||||
unitType,
|
||||
condValue,
|
||||
res,
|
||||
elseBlock,
|
||||
expression.origin
|
||||
startOffset = UNDEFINED_OFFSET,
|
||||
endOffset = UNDEFINED_OFFSET,
|
||||
type = unitType,
|
||||
cond = condValue,
|
||||
thenBranch = res,
|
||||
elseBranch = elseBlock,
|
||||
origin = expression.origin,
|
||||
thenBranchStartOffset = orig.startOffset,
|
||||
thenBranchEndOffset = orig.endOffset,
|
||||
elseBranchStartOffset = UNDEFINED_OFFSET,
|
||||
elseBranchEndOffset = UNDEFINED_OFFSET,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
+1
-1
@@ -26,6 +26,6 @@ inline fun getB(): Int {
|
||||
|
||||
// EXPECTATIONS JS_IR
|
||||
// test.kt:14 box
|
||||
// test.kt:5 box
|
||||
// test.kt:4 box
|
||||
// test.kt:11 getA
|
||||
// test.kt:14 box
|
||||
|
||||
@@ -66,13 +66,13 @@ fun nop() {}
|
||||
// test.kt:8 box
|
||||
// test.kt:24 box
|
||||
// test.kt:9 box
|
||||
// test.kt:10 box
|
||||
// test.kt:7 box
|
||||
// test.kt:11 box
|
||||
// test.kt:30 nop
|
||||
// test.kt:24 box
|
||||
// test.kt:16 box
|
||||
// test.kt:27 box
|
||||
// test.kt:15 box
|
||||
// test.kt:14 box
|
||||
// test.kt:19 box
|
||||
// test.kt:30 nop
|
||||
// test.kt:21 box
|
||||
|
||||
+1
-1
@@ -20,4 +20,4 @@ fun bar() {
|
||||
}
|
||||
|
||||
// LINES(JS): 1 11 3 3 5 5 6 6 8 8 9 9 2 2 * 13 20 15 15 18 18
|
||||
// LINES(JS_IR): 1 1 3 3 5 * 6 6 * 8 9 9 * 13 13 15 15 17 18 18
|
||||
// LINES(JS_IR): 1 1 3 3 5 5 6 6 8 8 9 9 * 13 13 15 15 17 18 18
|
||||
|
||||
+1
-1
@@ -4,4 +4,4 @@ data class A(
|
||||
)
|
||||
|
||||
// LINES(JS): 1 2 3 * 1 2 2 1 3 3 1 1 1 2 3 1 1 1 2 3 1 1 1 2 3 1 1 1 1 1 2 3
|
||||
// LINES(JS_IR): 1 1 2 2 3 3 2 2 2 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 * 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
||||
// LINES(JS_IR): 1 1 2 2 3 3 2 2 2 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 * 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
||||
|
||||
+2
-2
@@ -11,5 +11,5 @@ inline fun foo(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
// LINES(JS): 3 7 4 4 4 10 10 4 11 4 5 5 9 12 10 10 11 11 * 1 * 1
|
||||
// LINES(JS_IR): 1 1 1 1 1 1 1 1 * 3 3 * 4 * 4 * 10 10 11 11 4 4 * 5 5 9 9 10 10 11 11 * 1
|
||||
// LINES(JS): 3 7 4 4 4 10 10 4 11 4 5 5 9 12 10 10 11 11 * 1 * 1
|
||||
// LINES(JS_IR): 1 1 1 1 1 1 1 1 * 3 3 * 4 4 * 4 * 10 10 11 11 4 4 4 5 5 9 9 10 10 11 11 * 1
|
||||
|
||||
@@ -24,5 +24,5 @@ fun baz() = "baz"
|
||||
|
||||
fun boo() = "boo"
|
||||
|
||||
// LINES(JS): 1 17 9 4 6 6 7 7 3 3 3 * 13 12 13 13 14 19 21 20 20 23 23 23 25 25 25
|
||||
// LINES(JS_IR): 1 1 * 2 * 20 * 4 6 * 7 * 3 20 20 * 11 * 20 * 12 12 12 13 14 20 20 19 19 20 20 23 23 23 23 25 25 25 25
|
||||
// LINES(JS): 1 17 9 4 6 6 7 7 3 3 3 * 13 12 13 13 14 19 21 20 20 23 23 23 25 25 25
|
||||
// LINES(JS_IR): 1 1 * 2 * 20 * 4 6 * 6 7 * 3 20 20 * 11 * 20 * 12 12 12 13 14 20 20 19 19 20 20 23 23 23 23 25 25 25 25
|
||||
|
||||
+1
-1
@@ -14,4 +14,4 @@ open class A
|
||||
open class B : A()
|
||||
|
||||
// LINES(JS): 1 10 2 2 2 2 3 3 4 4 5 5 6 6 8 8 12 * 14 14
|
||||
// LINES(JS_IR): 1 1 2 2 3 4 4 5 6 6 8 8 12 12 14 14 14
|
||||
// LINES(JS_IR): 1 1 2 2 3 3 4 4 5 5 6 6 8 8 12 12 14 14 14
|
||||
|
||||
Reference in New Issue
Block a user