JVM: optimize temporary kotlin.jvm.internal.Refs as well

i.e. remove the condition that there must be an LVT entry. Such
temporary `Ref`s can be created, for example, by the JVM_IR backend
if a lambda inlined at an IR level (e.g. argument to `assert`/`Array`)
is the target of a non-local return from a function inlined at bytecode
level (e.g. `run`):

    IntArray(n) { i ->
        intOrNull?.let { return@IntArray it }
        someInt
    }

->

    val `tmp$0` = IntArray(n)
    for (i in 0 until `tmp$0`.size) {
        var `tmp$1`: Int
        do {
            intOrNull?.let {
                `tmp$1` = it // causes `tmp$1` to become an IntRef
                break
            }
            `tmp$1` = someInt
        } while (false)
        `tmp$0`[i] = `tmp$1`
    }
This commit is contained in:
pyos
2020-05-12 14:53:18 +02:00
committed by max-kammerer
parent 0f2ca5d84c
commit ad53fc931e
5 changed files with 78 additions and 114 deletions
@@ -0,0 +1,5 @@
fun f() = IntArray(1) { run { return@IntArray 1 } }
// On JVM_IR, the return is an assignment to a captured var followed by
// a non-local `break` from a `do ... while (false)`. The var should be optimized.
// 0 IntRef