FIR2IR: wrap do-while loop in IrBlock

"so that variables declared in loop body are not visible outside of the
loop" (from commit d096f1d)
This commit is contained in:
Jinseong Jeon
2021-03-18 00:29:09 -07:00
committed by TeamCityServer
parent 08670114c8
commit 7898d167f3
13 changed files with 197 additions and 161 deletions
@@ -728,7 +728,7 @@ class Fir2IrVisitor(
private val loopMap = mutableMapOf<FirLoop, IrLoop>() private val loopMap = mutableMapOf<FirLoop, IrLoop>()
override fun visitDoWhileLoop(doWhileLoop: FirDoWhileLoop, data: Any?): IrElement { override fun visitDoWhileLoop(doWhileLoop: FirDoWhileLoop, data: Any?): IrElement {
return doWhileLoop.convertWithOffsets { startOffset, endOffset -> val irLoop = doWhileLoop.convertWithOffsets { startOffset, endOffset ->
IrDoWhileLoopImpl( IrDoWhileLoopImpl(
startOffset, endOffset, irBuiltIns.unitType, startOffset, endOffset, irBuiltIns.unitType,
IrStatementOrigin.DO_WHILE_LOOP IrStatementOrigin.DO_WHILE_LOOP
@@ -742,6 +742,9 @@ class Fir2IrVisitor(
}.also { }.also {
doWhileLoop.accept(implicitCastInserter, it) doWhileLoop.accept(implicitCastInserter, it)
} }
return IrBlockImpl(irLoop.startOffset, irLoop.endOffset, irBuiltIns.unitType).apply {
statements.add(irLoop)
}
} }
override fun visitWhileLoop(whileLoop: FirWhileLoop, data: Any?): IrElement { override fun visitWhileLoop(whileLoop: FirWhileLoop, data: Any?): IrElement {
@@ -1,5 +1,7 @@
fun foo() { fun foo() {
do// COMPOSITE { { // BLOCK
val x: Int = 42 do// COMPOSITE {
// } while (EQEQ(arg0 = x, arg1 = 42).not()) val x: Int = 42
// } while (EQEQ(arg0 = x, arg1 = 42).not())
}
} }
@@ -1,11 +1,12 @@
FILE fqName:<root> fileName:/localVarInDoWhile.kt FILE fqName:<root> fileName:/localVarInDoWhile.kt
FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY BLOCK_BODY
DO_WHILE label=null origin=DO_WHILE_LOOP BLOCK type=kotlin.Unit origin=null
body: COMPOSITE type=kotlin.Unit origin=DO_WHILE_LOOP DO_WHILE label=null origin=DO_WHILE_LOOP
VAR name:x type:kotlin.Int [val] body: COMPOSITE type=kotlin.Unit origin=DO_WHILE_LOOP
CONST Int type=kotlin.Int value=42 VAR name:x type:kotlin.Int [val]
condition: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ CONST Int type=kotlin.Int value=42
$this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ condition: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ
arg0: GET_VAR 'val x: kotlin.Int [val] declared in <root>.foo' type=kotlin.Int origin=null $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ
arg1: CONST Int type=kotlin.Int value=42 arg0: GET_VAR 'val x: kotlin.Int [val] declared in <root>.foo' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=42
@@ -1,8 +1,12 @@
fun test1() { fun test1() {
while (true) break while (true) break
dobreak while (true) { // BLOCK
dobreak while (true)
}
while (true) continue while (true) continue
docontinue while (true) { // BLOCK
docontinue while (true)
}
} }
fun test2() { fun test2() {
@@ -4,15 +4,17 @@ FILE fqName:<root> fileName:/breakContinue.kt
WHILE label=null origin=WHILE_LOOP WHILE label=null origin=WHILE_LOOP
condition: CONST Boolean type=kotlin.Boolean value=true condition: CONST Boolean type=kotlin.Boolean value=true
body: BREAK label=null loop.label=null body: BREAK label=null loop.label=null
DO_WHILE label=null origin=DO_WHILE_LOOP BLOCK type=kotlin.Unit origin=null
body: BREAK label=null loop.label=null DO_WHILE label=null origin=DO_WHILE_LOOP
condition: CONST Boolean type=kotlin.Boolean value=true body: BREAK label=null loop.label=null
condition: CONST Boolean type=kotlin.Boolean value=true
WHILE label=null origin=WHILE_LOOP WHILE label=null origin=WHILE_LOOP
condition: CONST Boolean type=kotlin.Boolean value=true condition: CONST Boolean type=kotlin.Boolean value=true
body: CONTINUE label=null loop.label=null body: CONTINUE label=null loop.label=null
DO_WHILE label=null origin=DO_WHILE_LOOP BLOCK type=kotlin.Unit origin=null
body: CONTINUE label=null loop.label=null DO_WHILE label=null origin=DO_WHILE_LOOP
condition: CONST Boolean type=kotlin.Boolean value=true body: CONTINUE label=null loop.label=null
condition: CONST Boolean type=kotlin.Boolean value=true
FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.Unit FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY BLOCK_BODY
WHILE label=OUTER origin=WHILE_LOOP WHILE label=OUTER origin=WHILE_LOOP
@@ -64,13 +64,15 @@ fun test5() {
i = i.inc() i = i.inc()
i /*~> Unit */ i /*~> Unit */
var j: Int = 0 var j: Int = 0
Inner@ do// COMPOSITE { { // BLOCK
j = j.inc() Inner@ do// COMPOSITE {
j j = j.inc()
// } while (when { j
greaterOrEqual(arg0 = j, arg1 = 3) -> false // } while (when {
else -> break@Outer greaterOrEqual(arg0 = j, arg1 = 3) -> false
}) else -> break@Outer
})
}
when { when {
EQEQ(arg0 = i, arg1 = 3) -> break@Outer EQEQ(arg0 = i, arg1 = 3) -> break@Outer
} }
@@ -109,21 +109,22 @@ FILE fqName:<root> fileName:/breakContinueInLoopHeader.kt
GET_VAR 'var i: kotlin.Int [var] declared in <root>.test5' type=kotlin.Int origin=null GET_VAR 'var i: kotlin.Int [var] declared in <root>.test5' type=kotlin.Int origin=null
VAR name:j type:kotlin.Int [var] VAR name:j type:kotlin.Int [var]
CONST Int type=kotlin.Int value=0 CONST Int type=kotlin.Int value=0
DO_WHILE label=Inner origin=DO_WHILE_LOOP BLOCK type=kotlin.Unit origin=null
body: COMPOSITE type=kotlin.Int origin=DO_WHILE_LOOP DO_WHILE label=Inner origin=DO_WHILE_LOOP
SET_VAR 'var j: kotlin.Int [var] declared in <root>.test5' type=kotlin.Unit origin=EQ body: COMPOSITE type=kotlin.Int origin=DO_WHILE_LOOP
CALL 'public final fun inc (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null SET_VAR 'var j: kotlin.Int [var] declared in <root>.test5' type=kotlin.Unit origin=EQ
$this: GET_VAR 'var j: kotlin.Int [var] declared in <root>.test5' type=kotlin.Int origin=null CALL 'public final fun inc (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null
GET_VAR 'var j: kotlin.Int [var] declared in <root>.test5' type=kotlin.Int origin=null $this: GET_VAR 'var j: kotlin.Int [var] declared in <root>.test5' type=kotlin.Int origin=null
condition: WHEN type=kotlin.Boolean origin=IF GET_VAR 'var j: kotlin.Int [var] declared in <root>.test5' type=kotlin.Int origin=null
BRANCH condition: WHEN type=kotlin.Boolean origin=IF
if: CALL 'public final fun greaterOrEqual (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GTEQ BRANCH
arg0: GET_VAR 'var j: kotlin.Int [var] declared in <root>.test5' type=kotlin.Int origin=null if: CALL 'public final fun greaterOrEqual (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GTEQ
arg1: CONST Int type=kotlin.Int value=3 arg0: GET_VAR 'var j: kotlin.Int [var] declared in <root>.test5' type=kotlin.Int origin=null
then: CONST Boolean type=kotlin.Boolean value=false arg1: CONST Int type=kotlin.Int value=3
BRANCH then: CONST Boolean type=kotlin.Boolean value=false
if: CONST Boolean type=kotlin.Boolean value=true BRANCH
then: BREAK label=Outer loop.label=Outer if: CONST Boolean type=kotlin.Boolean value=true
then: BREAK label=Outer loop.label=Outer
WHEN type=kotlin.Unit origin=IF WHEN type=kotlin.Unit origin=IF
BRANCH 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 if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
@@ -24,9 +24,11 @@ fun testBreakWhile() {
fun testBreakDoWhile() { fun testBreakDoWhile() {
var k: Int = 0 var k: Int = 0
dowhen { { // BLOCK
greater(arg0 = k, arg1 = 2) -> break dowhen {
} while (less(arg0 = k, arg1 = 10)) greater(arg0 = k, arg1 = 2) -> break
} while (less(arg0 = k, arg1 = 10))
}
} }
fun testContinueFor() { fun testContinueFor() {
@@ -56,14 +58,16 @@ fun testContinueWhile() {
fun testContinueDoWhile() { fun testContinueDoWhile() {
var k: Int = 0 var k: Int = 0
var s: String = "" var s: String = ""
do// COMPOSITE { { // BLOCK
k = k.inc() do// COMPOSITE {
k /*~> Unit */ k = k.inc()
when { k /*~> Unit */
greater(arg0 = k, arg1 = 2) -> continue when {
greater(arg0 = k, arg1 = 2) -> continue
}
s = s.plus(other = k.toString() + ";")
// } while (less(arg0 = k, arg1 = 10))
} }
s = s.plus(other = k.toString() + ";")
// } while (less(arg0 = k, arg1 = 10))
when { when {
EQEQ(arg0 = s, arg1 = "1;2;").not() -> throw AssertionError(p0 = s) EQEQ(arg0 = s, arg1 = "1;2;").not() -> throw AssertionError(p0 = s)
} }
@@ -47,16 +47,17 @@ FILE fqName:<root> fileName:/breakContinueInWhen.kt
BLOCK_BODY BLOCK_BODY
VAR name:k type:kotlin.Int [var] VAR name:k type:kotlin.Int [var]
CONST Int type=kotlin.Int value=0 CONST Int type=kotlin.Int value=0
DO_WHILE label=null origin=DO_WHILE_LOOP BLOCK type=kotlin.Unit origin=null
body: WHEN type=kotlin.Unit origin=WHEN DO_WHILE label=null origin=DO_WHILE_LOOP
BRANCH body: WHEN type=kotlin.Unit origin=WHEN
if: CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT BRANCH
arg0: GET_VAR 'var k: kotlin.Int [var] declared in <root>.testBreakDoWhile' type=kotlin.Int origin=null if: CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
arg1: CONST Int type=kotlin.Int value=2 arg0: GET_VAR 'var k: kotlin.Int [var] declared in <root>.testBreakDoWhile' type=kotlin.Int origin=null
then: BREAK label=null loop.label=null arg1: CONST Int type=kotlin.Int value=2
condition: CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT then: BREAK label=null loop.label=null
arg0: GET_VAR 'var k: kotlin.Int [var] declared in <root>.testBreakDoWhile' type=kotlin.Int origin=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
arg1: CONST Int type=kotlin.Int value=10 arg0: GET_VAR 'var k: kotlin.Int [var] declared in <root>.testBreakDoWhile' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=10
FUN name:testContinueFor visibility:public modality:FINAL <> () returnType:kotlin.Unit FUN name:testContinueFor visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY BLOCK_BODY
VAR name:xs type:kotlin.IntArray [val] VAR name:xs type:kotlin.IntArray [val]
@@ -107,29 +108,30 @@ FILE fqName:<root> fileName:/breakContinueInWhen.kt
CONST Int type=kotlin.Int value=0 CONST Int type=kotlin.Int value=0
VAR name:s type:kotlin.String [var] VAR name:s type:kotlin.String [var]
CONST String type=kotlin.String value="" CONST String type=kotlin.String value=""
DO_WHILE label=null origin=DO_WHILE_LOOP BLOCK type=kotlin.Unit origin=null
body: COMPOSITE type=kotlin.Unit origin=DO_WHILE_LOOP DO_WHILE label=null origin=DO_WHILE_LOOP
SET_VAR 'var k: kotlin.Int [var] declared in <root>.testContinueDoWhile' type=kotlin.Unit origin=EQ body: COMPOSITE type=kotlin.Unit origin=DO_WHILE_LOOP
CALL 'public final fun inc (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null SET_VAR 'var k: kotlin.Int [var] declared in <root>.testContinueDoWhile' type=kotlin.Unit origin=EQ
$this: GET_VAR 'var k: kotlin.Int [var] declared in <root>.testContinueDoWhile' type=kotlin.Int origin=null CALL 'public final fun inc (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit $this: GET_VAR 'var k: kotlin.Int [var] declared in <root>.testContinueDoWhile' type=kotlin.Int origin=null
GET_VAR 'var k: kotlin.Int [var] declared in <root>.testContinueDoWhile' type=kotlin.Int origin=null TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
WHEN type=kotlin.Unit origin=WHEN GET_VAR 'var k: kotlin.Int [var] declared in <root>.testContinueDoWhile' type=kotlin.Int origin=null
BRANCH WHEN type=kotlin.Unit origin=WHEN
if: CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT BRANCH
arg0: GET_VAR 'var k: kotlin.Int [var] declared in <root>.testContinueDoWhile' type=kotlin.Int origin=null if: CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
arg1: CONST Int type=kotlin.Int value=2 arg0: GET_VAR 'var k: kotlin.Int [var] declared in <root>.testContinueDoWhile' type=kotlin.Int origin=null
then: CONTINUE label=null loop.label=null arg1: CONST Int type=kotlin.Int value=2
SET_VAR 'var s: kotlin.String [var] declared in <root>.testContinueDoWhile' type=kotlin.Unit origin=EQ then: CONTINUE label=null loop.label=null
CALL 'public final fun plus (other: kotlin.Any?): kotlin.String [operator] declared in kotlin.String' type=kotlin.String origin=null SET_VAR 'var s: kotlin.String [var] declared in <root>.testContinueDoWhile' type=kotlin.Unit origin=EQ
$this: GET_VAR 'var s: kotlin.String [var] declared in <root>.testContinueDoWhile' type=kotlin.String origin=null CALL 'public final fun plus (other: kotlin.Any?): kotlin.String [operator] declared in kotlin.String' type=kotlin.String origin=null
other: STRING_CONCATENATION type=kotlin.String $this: GET_VAR 'var s: kotlin.String [var] declared in <root>.testContinueDoWhile' type=kotlin.String origin=null
CALL 'public open fun toString (): kotlin.String declared in kotlin.Any' type=kotlin.String origin=null other: STRING_CONCATENATION type=kotlin.String
$this: GET_VAR 'var k: kotlin.Int [var] declared in <root>.testContinueDoWhile' type=kotlin.Int origin=null CALL 'public open fun toString (): kotlin.String declared in kotlin.Any' type=kotlin.String origin=null
CONST String type=kotlin.String value=";" $this: GET_VAR 'var k: kotlin.Int [var] declared in <root>.testContinueDoWhile' type=kotlin.Int origin=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 CONST String type=kotlin.String value=";"
arg0: GET_VAR 'var k: kotlin.Int [var] declared in <root>.testContinueDoWhile' type=kotlin.Int origin=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
arg1: CONST Int type=kotlin.Int value=10 arg0: GET_VAR 'var k: kotlin.Int [var] declared in <root>.testContinueDoWhile' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=10
WHEN type=kotlin.Unit origin=IF WHEN type=kotlin.Unit origin=IF
BRANCH BRANCH
if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ
@@ -12,18 +12,24 @@ fun test() {
x = <unary>.inc() x = <unary>.inc()
<unary> <unary>
} }
do// COMPOSITE { { // BLOCK
// } while (less(arg0 = x, arg1 = 0)) do// COMPOSITE {
do{ // BLOCK // } while (less(arg0 = x, arg1 = 0))
}
{ // BLOCK
do{ // BLOCK
val <unary>: Int = x
x = <unary>.inc()
<unary>
} while (less(arg0 = x, arg1 = 15))
}
{ // BLOCK
do// COMPOSITE {
val <unary>: Int = x val <unary>: Int = x
x = <unary>.inc() x = <unary>.inc()
<unary> <unary>
} while (less(arg0 = x, arg1 = 15)) // } while (less(arg0 = x, arg1 = 20))
do// COMPOSITE { }
val <unary>: Int = x
x = <unary>.inc()
<unary>
// } while (less(arg0 = x, arg1 = 20))
} }
fun testSmartcastInCondition() { fun testSmartcastInCondition() {
@@ -32,8 +38,10 @@ fun testSmartcastInCondition() {
a is Boolean -> { // BLOCK a is Boolean -> { // BLOCK
while (a /*as Boolean */) { // BLOCK while (a /*as Boolean */) { // BLOCK
} }
do// COMPOSITE { { // BLOCK
// } while (a /*as Boolean */) do// COMPOSITE {
// } while (a /*as Boolean */)
}
} }
} }
} }
+35 -31
View File
@@ -30,33 +30,36 @@ FILE fqName:<root> fileName:/whileDoWhile.kt
CALL 'public final fun inc (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null CALL 'public final fun inc (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null
$this: GET_VAR 'val tmp_1: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null $this: GET_VAR 'val tmp_1: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null
GET_VAR 'val tmp_1: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null GET_VAR 'val tmp_1: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null
DO_WHILE label=null origin=DO_WHILE_LOOP BLOCK type=kotlin.Unit origin=null
body: COMPOSITE type=kotlin.Unit origin=DO_WHILE_LOOP DO_WHILE label=null origin=DO_WHILE_LOOP
condition: CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT body: COMPOSITE type=kotlin.Unit origin=DO_WHILE_LOOP
arg0: GET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Int origin=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
arg1: CONST Int type=kotlin.Int value=0 arg0: GET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Int origin=null
DO_WHILE label=null origin=DO_WHILE_LOOP arg1: CONST Int type=kotlin.Int value=0
body: BLOCK type=kotlin.Int origin=null BLOCK type=kotlin.Unit origin=null
VAR IR_TEMPORARY_VARIABLE name:tmp_2 type:kotlin.Int [val] DO_WHILE label=null origin=DO_WHILE_LOOP
GET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Int origin=null body: BLOCK type=kotlin.Int origin=null
SET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Unit origin=EQ VAR IR_TEMPORARY_VARIABLE name:tmp_2 type:kotlin.Int [val]
CALL 'public final fun inc (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null GET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Int origin=null
$this: GET_VAR 'val tmp_2: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null SET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Unit origin=EQ
GET_VAR 'val tmp_2: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null CALL 'public final fun inc (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=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 $this: GET_VAR 'val tmp_2: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null
arg0: GET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Int origin=null GET_VAR 'val tmp_2: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=15 condition: CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT
DO_WHILE label=null origin=DO_WHILE_LOOP arg0: GET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Int origin=null
body: COMPOSITE type=kotlin.Int origin=DO_WHILE_LOOP arg1: CONST Int type=kotlin.Int value=15
VAR IR_TEMPORARY_VARIABLE name:tmp_3 type:kotlin.Int [val] BLOCK type=kotlin.Unit origin=null
GET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Int origin=null DO_WHILE label=null origin=DO_WHILE_LOOP
SET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Unit origin=EQ body: COMPOSITE type=kotlin.Int origin=DO_WHILE_LOOP
CALL 'public final fun inc (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null VAR IR_TEMPORARY_VARIABLE name:tmp_3 type:kotlin.Int [val]
$this: GET_VAR 'val tmp_3: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null GET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Int origin=null
GET_VAR 'val tmp_3: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null SET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Unit origin=EQ
condition: CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT CALL 'public final fun inc (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null
arg0: GET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Int origin=null $this: GET_VAR 'val tmp_3: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=20 GET_VAR 'val tmp_3: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=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 x: kotlin.Int [var] declared in <root>.test' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=20
FUN name:testSmartcastInCondition visibility:public modality:FINAL <> () returnType:kotlin.Unit FUN name:testSmartcastInCondition visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY BLOCK_BODY
VAR name:a type:kotlin.Any? [val] VAR name:a type:kotlin.Any? [val]
@@ -70,7 +73,8 @@ FILE fqName:<root> fileName:/whileDoWhile.kt
condition: TYPE_OP type=kotlin.Boolean origin=IMPLICIT_CAST typeOperand=kotlin.Boolean condition: TYPE_OP type=kotlin.Boolean origin=IMPLICIT_CAST typeOperand=kotlin.Boolean
GET_VAR 'val a: kotlin.Any? [val] declared in <root>.testSmartcastInCondition' type=kotlin.Any? origin=null GET_VAR 'val a: kotlin.Any? [val] declared in <root>.testSmartcastInCondition' type=kotlin.Any? origin=null
body: BLOCK type=kotlin.Unit origin=null body: BLOCK type=kotlin.Unit origin=null
DO_WHILE label=null origin=DO_WHILE_LOOP BLOCK type=kotlin.Unit origin=null
body: COMPOSITE type=kotlin.Unit origin=DO_WHILE_LOOP DO_WHILE label=null origin=DO_WHILE_LOOP
condition: TYPE_OP type=kotlin.Boolean origin=IMPLICIT_CAST typeOperand=kotlin.Boolean body: COMPOSITE type=kotlin.Unit origin=DO_WHILE_LOOP
GET_VAR 'val a: kotlin.Any? [val] declared in <root>.testSmartcastInCondition' type=kotlin.Any? origin=null condition: TYPE_OP type=kotlin.Boolean origin=IMPLICIT_CAST typeOperand=kotlin.Boolean
GET_VAR 'val a: kotlin.Any? [val] declared in <root>.testSmartcastInCondition' type=kotlin.Any? origin=null
+10 -8
View File
@@ -223,14 +223,16 @@ internal class ArrayMapImpl<T : Any> : ArrayMap<T> {
private set private set
protected override fun computeNext() { protected override fun computeNext() {
do// COMPOSITE { { // BLOCK
val <unary>: Int = <this>.<get-index>() do// COMPOSITE {
<this>.<set-index>(<set-?> = <unary>.inc()) val <unary>: Int = <this>.<get-index>()
<unary> <this>.<set-index>(<set-?> = <unary>.inc())
// } while (when { <unary>
less(arg0 = <this>.<get-index>(), arg1 = <this>.<get-data>().<get-size>()) -> EQEQ(arg0 = <this>.<get-data>().get(index = <this>.<get-index>()), arg1 = null) // } while (when {
else -> false less(arg0 = <this>.<get-index>(), arg1 = <this>.<get-data>().<get-size>()) -> EQEQ(arg0 = <this>.<get-data>().get(index = <this>.<get-index>()), arg1 = null)
}) else -> false
})
}
when { when {
greaterOrEqual(arg0 = <this>.<get-index>(), arg1 = <this>.<get-data>().<get-size>()) -> <this>.done() greaterOrEqual(arg0 = <this>.<get-index>(), arg1 = <this>.<get-data>().<get-size>()) -> <this>.done()
else -> <this>.setNext(value = <this>.<get-data>().get(index = <this>.<get-index>()) as T) else -> <this>.setNext(value = <this>.<get-data>().get(index = <this>.<get-index>()) as T)
+27 -26
View File
@@ -535,34 +535,35 @@ FILE fqName:<root> fileName:/ArrayMap.kt
protected abstract fun computeNext (): kotlin.Unit declared in kotlin.collections.AbstractIterator protected abstract fun computeNext (): kotlin.Unit declared in kotlin.collections.AbstractIterator
$this: VALUE_PARAMETER name:<this> type:<root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> $this: VALUE_PARAMETER name:<this> type:<root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl>
BLOCK_BODY BLOCK_BODY
DO_WHILE label=null origin=DO_WHILE_LOOP BLOCK type=kotlin.Unit origin=null
body: COMPOSITE type=kotlin.Int origin=DO_WHILE_LOOP DO_WHILE label=null origin=DO_WHILE_LOOP
VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:kotlin.Int [val] body: COMPOSITE type=kotlin.Int origin=DO_WHILE_LOOP
CALL 'private final fun <get-index> (): kotlin.Int declared in <root>.ArrayMapImpl.iterator.<no name provided>' type=kotlin.Int origin=GET_PROPERTY VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:kotlin.Int [val]
$this: GET_VAR '<this>: <root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> declared in <root>.ArrayMapImpl.iterator.<no name provided>.computeNext' type=<root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> origin=null CALL 'private final fun <get-index> (): kotlin.Int declared in <root>.ArrayMapImpl.iterator.<no name provided>' type=kotlin.Int origin=GET_PROPERTY
CALL 'private final fun <set-index> (<set-?>: kotlin.Int): kotlin.Unit declared in <root>.ArrayMapImpl.iterator.<no name provided>' type=kotlin.Unit origin=EQ
$this: GET_VAR '<this>: <root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> declared in <root>.ArrayMapImpl.iterator.<no name provided>.computeNext' type=<root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> origin=null
<set-?>: CALL 'public final fun inc (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null
$this: GET_VAR 'val tmp_1: kotlin.Int [val] declared in <root>.ArrayMapImpl.iterator.<no name provided>.computeNext' type=kotlin.Int origin=null
GET_VAR 'val tmp_1: kotlin.Int [val] declared in <root>.ArrayMapImpl.iterator.<no name provided>.computeNext' type=kotlin.Int origin=null
condition: WHEN type=kotlin.Boolean origin=ANDAND
BRANCH
if: CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT
arg0: CALL 'private final fun <get-index> (): kotlin.Int declared in <root>.ArrayMapImpl.iterator.<no name provided>' type=kotlin.Int origin=GET_PROPERTY
$this: GET_VAR '<this>: <root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> declared in <root>.ArrayMapImpl.iterator.<no name provided>.computeNext' type=<root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> origin=null $this: GET_VAR '<this>: <root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> declared in <root>.ArrayMapImpl.iterator.<no name provided>.computeNext' type=<root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> origin=null
arg1: CALL 'public final fun <get-size> (): kotlin.Int declared in kotlin.Array' type=kotlin.Int origin=GET_PROPERTY CALL 'private final fun <set-index> (<set-?>: kotlin.Int): kotlin.Unit declared in <root>.ArrayMapImpl.iterator.<no name provided>' type=kotlin.Unit origin=EQ
$this: CALL 'private final fun <get-data> (): kotlin.Array<kotlin.Any?> declared in <root>.ArrayMapImpl' type=kotlin.Array<kotlin.Any?> origin=GET_PROPERTY $this: GET_VAR '<this>: <root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> declared in <root>.ArrayMapImpl.iterator.<no name provided>.computeNext' type=<root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> origin=null
$this: GET_VAR '<this>: <root>.ArrayMapImpl<T of <root>.ArrayMapImpl> declared in <root>.ArrayMapImpl.iterator' type=<root>.ArrayMapImpl<T of <root>.ArrayMapImpl> origin=null <set-?>: CALL 'public final fun inc (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null
then: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ $this: GET_VAR 'val tmp_1: kotlin.Int [val] declared in <root>.ArrayMapImpl.iterator.<no name provided>.computeNext' type=kotlin.Int origin=null
arg0: CALL 'public final fun get (index: kotlin.Int): T of kotlin.Array [operator] declared in kotlin.Array' type=kotlin.Any? origin=null GET_VAR 'val tmp_1: kotlin.Int [val] declared in <root>.ArrayMapImpl.iterator.<no name provided>.computeNext' type=kotlin.Int origin=null
$this: CALL 'private final fun <get-data> (): kotlin.Array<kotlin.Any?> declared in <root>.ArrayMapImpl' type=kotlin.Array<kotlin.Any?> origin=GET_PROPERTY condition: WHEN type=kotlin.Boolean origin=ANDAND
$this: GET_VAR '<this>: <root>.ArrayMapImpl<T of <root>.ArrayMapImpl> declared in <root>.ArrayMapImpl.iterator' type=<root>.ArrayMapImpl<T of <root>.ArrayMapImpl> origin=null BRANCH
index: CALL 'private final fun <get-index> (): kotlin.Int declared in <root>.ArrayMapImpl.iterator.<no name provided>' type=kotlin.Int origin=GET_PROPERTY if: CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT
arg0: CALL 'private final fun <get-index> (): kotlin.Int declared in <root>.ArrayMapImpl.iterator.<no name provided>' type=kotlin.Int origin=GET_PROPERTY
$this: GET_VAR '<this>: <root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> declared in <root>.ArrayMapImpl.iterator.<no name provided>.computeNext' type=<root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> origin=null $this: GET_VAR '<this>: <root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> declared in <root>.ArrayMapImpl.iterator.<no name provided>.computeNext' type=<root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> origin=null
arg1: CONST Null type=kotlin.Nothing? value=null arg1: CALL 'public final fun <get-size> (): kotlin.Int declared in kotlin.Array' type=kotlin.Int origin=GET_PROPERTY
BRANCH $this: CALL 'private final fun <get-data> (): kotlin.Array<kotlin.Any?> declared in <root>.ArrayMapImpl' type=kotlin.Array<kotlin.Any?> origin=GET_PROPERTY
if: CONST Boolean type=kotlin.Boolean value=true $this: GET_VAR '<this>: <root>.ArrayMapImpl<T of <root>.ArrayMapImpl> declared in <root>.ArrayMapImpl.iterator' type=<root>.ArrayMapImpl<T of <root>.ArrayMapImpl> origin=null
then: CONST Boolean type=kotlin.Boolean value=false then: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: CALL 'public final fun get (index: kotlin.Int): T of kotlin.Array [operator] declared in kotlin.Array' type=kotlin.Any? origin=null
$this: CALL 'private final fun <get-data> (): kotlin.Array<kotlin.Any?> declared in <root>.ArrayMapImpl' type=kotlin.Array<kotlin.Any?> origin=GET_PROPERTY
$this: GET_VAR '<this>: <root>.ArrayMapImpl<T of <root>.ArrayMapImpl> declared in <root>.ArrayMapImpl.iterator' type=<root>.ArrayMapImpl<T of <root>.ArrayMapImpl> origin=null
index: CALL 'private final fun <get-index> (): kotlin.Int declared in <root>.ArrayMapImpl.iterator.<no name provided>' type=kotlin.Int origin=GET_PROPERTY
$this: GET_VAR '<this>: <root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> declared in <root>.ArrayMapImpl.iterator.<no name provided>.computeNext' type=<root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CONST Boolean type=kotlin.Boolean value=false
WHEN type=kotlin.Unit origin=IF WHEN type=kotlin.Unit origin=IF
BRANCH BRANCH
if: CALL 'public final fun greaterOrEqual (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GTEQ if: CALL 'public final fun greaterOrEqual (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GTEQ