[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:
Vladimir Sukharev
2023-09-18 15:27:19 +00:00
committed by Space Team
parent f4df4f8007
commit 9a2eff6487
61 changed files with 601 additions and 1102 deletions
@@ -23,12 +23,13 @@ FILE fqName:<root> fileName:/breakContinueInWhen.kt
VAR FOR_LOOP_VARIABLE name:x type:kotlin.Int [val]
CALL 'public final fun next (): kotlin.Int declared in kotlin.collections.IntIterator' type=kotlin.Int origin=FOR_LOOP_NEXT
$this: GET_VAR 'val tmp_0: kotlin.collections.IntIterator declared in <root>.testBreakFor' type=kotlin.collections.IntIterator origin=null
WHEN type=kotlin.Unit origin=WHEN
BRANCH
if: CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
arg0: GET_VAR 'var k: kotlin.Int declared in <root>.testBreakFor' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=2
then: BREAK label=null loop.label=null
BLOCK type=kotlin.Unit origin=null
WHEN type=kotlin.Unit origin=WHEN
BRANCH
if: CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
arg0: GET_VAR 'var k: kotlin.Int declared in <root>.testBreakFor' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=2
then: BREAK label=null loop.label=null
FUN name:testBreakWhile visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
VAR name:k type:kotlin.Int [var]
@@ -37,24 +38,26 @@ FILE fqName:<root> fileName:/breakContinueInWhen.kt
condition: CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT
arg0: GET_VAR 'var k: kotlin.Int declared in <root>.testBreakWhile' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=10
body: WHEN type=kotlin.Unit origin=WHEN
BRANCH
if: CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
arg0: GET_VAR 'var k: kotlin.Int declared in <root>.testBreakWhile' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=2
then: BREAK label=null loop.label=null
body: BLOCK type=kotlin.Unit origin=null
WHEN type=kotlin.Unit origin=WHEN
BRANCH
if: CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
arg0: GET_VAR 'var k: kotlin.Int declared in <root>.testBreakWhile' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=2
then: BREAK label=null loop.label=null
FUN name:testBreakDoWhile visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
VAR name:k type:kotlin.Int [var]
CONST Int type=kotlin.Int value=0
BLOCK type=kotlin.Unit origin=null
DO_WHILE label=null origin=DO_WHILE_LOOP
body: WHEN type=kotlin.Unit origin=WHEN
BRANCH
if: CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
arg0: GET_VAR 'var k: kotlin.Int declared in <root>.testBreakDoWhile' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=2
then: BREAK label=null loop.label=null
body: COMPOSITE type=kotlin.Unit origin=null
WHEN type=kotlin.Unit origin=WHEN
BRANCH
if: CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
arg0: GET_VAR 'var k: kotlin.Int declared in <root>.testBreakDoWhile' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=2
then: BREAK label=null loop.label=null
condition: CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT
arg0: GET_VAR 'var k: kotlin.Int declared in <root>.testBreakDoWhile' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=10
@@ -82,12 +85,13 @@ FILE fqName:<root> fileName:/breakContinueInWhen.kt
VAR FOR_LOOP_VARIABLE name:x type:kotlin.Int [val]
CALL 'public final fun next (): kotlin.Int declared in kotlin.collections.IntIterator' type=kotlin.Int origin=FOR_LOOP_NEXT
$this: GET_VAR 'val tmp_1: kotlin.collections.IntIterator declared in <root>.testContinueFor' type=kotlin.collections.IntIterator origin=null
WHEN type=kotlin.Unit origin=WHEN
BRANCH
if: CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
arg0: GET_VAR 'var k: kotlin.Int declared in <root>.testContinueFor' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=2
then: CONTINUE label=null loop.label=null
BLOCK type=kotlin.Unit origin=null
WHEN type=kotlin.Unit origin=WHEN
BRANCH
if: CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
arg0: GET_VAR 'var k: kotlin.Int declared in <root>.testContinueFor' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=2
then: CONTINUE label=null loop.label=null
FUN name:testContinueWhile visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
VAR name:k type:kotlin.Int [var]
@@ -96,12 +100,13 @@ FILE fqName:<root> fileName:/breakContinueInWhen.kt
condition: CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT
arg0: GET_VAR 'var k: kotlin.Int declared in <root>.testContinueWhile' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=10
body: WHEN type=kotlin.Unit origin=WHEN
BRANCH
if: CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
arg0: GET_VAR 'var k: kotlin.Int declared in <root>.testContinueWhile' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=2
then: CONTINUE label=null loop.label=null
body: BLOCK type=kotlin.Unit origin=null
WHEN type=kotlin.Unit origin=WHEN
BRANCH
if: CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
arg0: GET_VAR 'var k: kotlin.Int declared in <root>.testContinueWhile' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=2
then: CONTINUE label=null loop.label=null
FUN name:testContinueDoWhile visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
VAR name:k type:kotlin.Int [var]
@@ -110,7 +115,7 @@ FILE fqName:<root> fileName:/breakContinueInWhen.kt
CONST String type=kotlin.String value=""
BLOCK type=kotlin.Unit origin=null
DO_WHILE label=null origin=DO_WHILE_LOOP
body: COMPOSITE type=kotlin.Unit origin=DO_WHILE_LOOP
body: COMPOSITE type=kotlin.Unit origin=null
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
BLOCK type=kotlin.Int origin=null
SET_VAR 'var k: kotlin.Int declared in <root>.testContinueDoWhile' type=kotlin.Unit origin=PREFIX_INCR