[FIR2IR] Don't replace while loop and when branch body blocks with single expression. Skip some empty blocks.
https://youtrack.jetbrains.com/issue/KT-60264/K2-while-loop-body-block-sometimes-replaced-with-single-expression Merge-request: KT-MR-12035 Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
f4df4f8007
commit
9a2eff6487
@@ -12,7 +12,7 @@ FILE fqName:<root> fileName:/coercionInLoop.kt
|
||||
WHILE label=null origin=WHILE_LOOP
|
||||
condition: CALL 'public abstract fun hasNext (): kotlin.Boolean declared in kotlin.collections.DoubleIterator' type=kotlin.Boolean origin=null
|
||||
$this: GET_VAR 'val x: kotlin.collections.DoubleIterator declared in <root>.box' type=kotlin.collections.DoubleIterator origin=null
|
||||
body: BLOCK type=kotlin.Int origin=null
|
||||
body: BLOCK type=kotlin.Unit origin=null
|
||||
WHEN type=kotlin.Unit origin=IF
|
||||
BRANCH
|
||||
if: CALL 'public final fun not (): kotlin.Boolean declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
|
||||
+47
-44
@@ -11,51 +11,54 @@ FILE fqName:<root> fileName:/kt24114.kt
|
||||
BLOCK_BODY
|
||||
WHILE label=null origin=WHILE_LOOP
|
||||
condition: CONST Boolean type=kotlin.Boolean value=true
|
||||
body: BLOCK type=kotlin.Unit origin=WHEN
|
||||
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.Int [val]
|
||||
CALL 'public final fun one (): kotlin.Int declared in <root>' type=kotlin.Int origin=null
|
||||
WHEN type=kotlin.Unit origin=WHEN
|
||||
BRANCH
|
||||
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
|
||||
arg0: GET_VAR 'val tmp_0: kotlin.Int declared in <root>.test1' type=kotlin.Int origin=null
|
||||
arg1: CONST Int type=kotlin.Int value=1
|
||||
then: BLOCK type=kotlin.Unit origin=WHEN
|
||||
VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:kotlin.Int [val]
|
||||
CALL 'public final fun two (): kotlin.Int declared in <root>' type=kotlin.Int origin=null
|
||||
WHEN type=kotlin.Unit origin=WHEN
|
||||
BRANCH
|
||||
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
|
||||
arg0: GET_VAR 'val tmp_1: kotlin.Int declared in <root>.test1' type=kotlin.Int origin=null
|
||||
arg1: CONST Int type=kotlin.Int value=2
|
||||
then: RETURN type=kotlin.Nothing from='public final fun test1 (): kotlin.Int declared in <root>'
|
||||
CONST Int type=kotlin.Int value=2
|
||||
BRANCH
|
||||
if: CONST Boolean type=kotlin.Boolean value=true
|
||||
then: RETURN type=kotlin.Nothing from='public final fun test1 (): kotlin.Int declared in <root>'
|
||||
CONST Int type=kotlin.Int value=3
|
||||
body: BLOCK type=kotlin.Unit origin=null
|
||||
BLOCK type=kotlin.Unit origin=WHEN
|
||||
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.Int [val]
|
||||
CALL 'public final fun one (): kotlin.Int declared in <root>' type=kotlin.Int origin=null
|
||||
WHEN type=kotlin.Unit origin=WHEN
|
||||
BRANCH
|
||||
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
|
||||
arg0: GET_VAR 'val tmp_0: kotlin.Int declared in <root>.test1' type=kotlin.Int origin=null
|
||||
arg1: CONST Int type=kotlin.Int value=1
|
||||
then: BLOCK type=kotlin.Unit origin=null
|
||||
BLOCK type=kotlin.Unit origin=WHEN
|
||||
VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:kotlin.Int [val]
|
||||
CALL 'public final fun two (): kotlin.Int declared in <root>' type=kotlin.Int origin=null
|
||||
WHEN type=kotlin.Unit origin=WHEN
|
||||
BRANCH
|
||||
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
|
||||
arg0: GET_VAR 'val tmp_1: kotlin.Int declared in <root>.test1' type=kotlin.Int origin=null
|
||||
arg1: CONST Int type=kotlin.Int value=2
|
||||
then: RETURN type=kotlin.Nothing from='public final fun test1 (): kotlin.Int declared in <root>'
|
||||
CONST Int type=kotlin.Int value=2
|
||||
BRANCH
|
||||
if: CONST Boolean type=kotlin.Boolean value=true
|
||||
then: RETURN type=kotlin.Nothing from='public final fun test1 (): kotlin.Int declared in <root>'
|
||||
CONST Int type=kotlin.Int value=3
|
||||
FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.Int
|
||||
BLOCK_BODY
|
||||
WHILE label=null origin=WHILE_LOOP
|
||||
condition: CONST Boolean type=kotlin.Boolean value=true
|
||||
body: BLOCK type=kotlin.Unit origin=WHEN
|
||||
VAR IR_TEMPORARY_VARIABLE name:tmp_2 type:kotlin.Int [val]
|
||||
CALL 'public final fun one (): kotlin.Int declared in <root>' type=kotlin.Int origin=null
|
||||
WHEN type=kotlin.Unit origin=WHEN
|
||||
BRANCH
|
||||
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
|
||||
arg0: GET_VAR 'val tmp_2: kotlin.Int declared in <root>.test2' type=kotlin.Int origin=null
|
||||
arg1: CONST Int type=kotlin.Int value=1
|
||||
then: BLOCK type=kotlin.Unit origin=WHEN
|
||||
VAR IR_TEMPORARY_VARIABLE name:tmp_3 type:kotlin.Int [val]
|
||||
CALL 'public final fun two (): kotlin.Int declared in <root>' type=kotlin.Int origin=null
|
||||
WHEN type=kotlin.Unit origin=WHEN
|
||||
BRANCH
|
||||
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
|
||||
arg0: GET_VAR 'val tmp_3: kotlin.Int declared in <root>.test2' type=kotlin.Int origin=null
|
||||
arg1: CONST Int type=kotlin.Int value=2
|
||||
then: RETURN type=kotlin.Nothing from='public final fun test2 (): kotlin.Int declared in <root>'
|
||||
CONST Int type=kotlin.Int value=2
|
||||
BRANCH
|
||||
if: CONST Boolean type=kotlin.Boolean value=true
|
||||
then: RETURN type=kotlin.Nothing from='public final fun test2 (): kotlin.Int declared in <root>'
|
||||
CONST Int type=kotlin.Int value=3
|
||||
body: BLOCK type=kotlin.Unit origin=null
|
||||
BLOCK type=kotlin.Unit origin=WHEN
|
||||
VAR IR_TEMPORARY_VARIABLE name:tmp_2 type:kotlin.Int [val]
|
||||
CALL 'public final fun one (): kotlin.Int declared in <root>' type=kotlin.Int origin=null
|
||||
WHEN type=kotlin.Unit origin=WHEN
|
||||
BRANCH
|
||||
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
|
||||
arg0: GET_VAR 'val tmp_2: kotlin.Int declared in <root>.test2' type=kotlin.Int origin=null
|
||||
arg1: CONST Int type=kotlin.Int value=1
|
||||
then: BLOCK type=kotlin.Unit origin=WHEN
|
||||
VAR IR_TEMPORARY_VARIABLE name:tmp_3 type:kotlin.Int [val]
|
||||
CALL 'public final fun two (): kotlin.Int declared in <root>' type=kotlin.Int origin=null
|
||||
WHEN type=kotlin.Unit origin=WHEN
|
||||
BRANCH
|
||||
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
|
||||
arg0: GET_VAR 'val tmp_3: kotlin.Int declared in <root>.test2' type=kotlin.Int origin=null
|
||||
arg1: CONST Int type=kotlin.Int value=2
|
||||
then: RETURN type=kotlin.Nothing from='public final fun test2 (): kotlin.Int declared in <root>'
|
||||
CONST Int type=kotlin.Int value=2
|
||||
BRANCH
|
||||
if: CONST Boolean type=kotlin.Boolean value=true
|
||||
then: RETURN type=kotlin.Nothing from='public final fun test2 (): kotlin.Int declared in <root>'
|
||||
CONST Int type=kotlin.Int value=3
|
||||
|
||||
+21
-14
@@ -8,30 +8,37 @@ fun two(): Int {
|
||||
|
||||
fun test1(): Int {
|
||||
while (true) { // BLOCK
|
||||
val tmp0_subject: Int = one()
|
||||
when {
|
||||
EQEQ(arg0 = tmp0_subject, arg1 = 1) -> { // BLOCK
|
||||
val tmp1_subject: Int = two()
|
||||
when {
|
||||
EQEQ(arg0 = tmp1_subject, arg1 = 2) -> return 2
|
||||
{ // BLOCK
|
||||
val tmp0_subject: Int = one()
|
||||
when {
|
||||
EQEQ(arg0 = tmp0_subject, arg1 = 1) -> { // BLOCK
|
||||
{ // BLOCK
|
||||
val tmp1_subject: Int = two()
|
||||
when {
|
||||
EQEQ(arg0 = tmp1_subject, arg1 = 2) -> return 2
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> return 3
|
||||
}
|
||||
else -> return 3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun test2(): Int {
|
||||
while (true) { // BLOCK
|
||||
val tmp2_subject: Int = one()
|
||||
when {
|
||||
EQEQ(arg0 = tmp2_subject, arg1 = 1) -> { // BLOCK
|
||||
val tmp3_subject: Int = two()
|
||||
when {
|
||||
EQEQ(arg0 = tmp3_subject, arg1 = 2) -> return 2
|
||||
{ // BLOCK
|
||||
val tmp2_subject: Int = one()
|
||||
when {
|
||||
EQEQ(arg0 = tmp2_subject, arg1 = 1) -> { // BLOCK
|
||||
val tmp3_subject: Int = two()
|
||||
when {
|
||||
EQEQ(arg0 = tmp3_subject, arg1 = 2) -> return 2
|
||||
}
|
||||
}
|
||||
else -> return 3
|
||||
}
|
||||
else -> return 3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user