IR: create shared variables for val-variables when needed

This is possible when a lambda's contract guarantees initialization of a
variable.
This commit is contained in:
Alexander Udalov
2019-11-04 20:13:25 +01:00
parent 5c4b47c336
commit 66e19b13ce
18 changed files with 116 additions and 48 deletions
@@ -0,0 +1,18 @@
// WITH_RUNTIME
// IGNORE_BACKEND: JVM_IR
// In JVM IR, SharedVariablesLowering transforms `x` into a shared variable to be able to update it from a lambda,
// which is a separate function (...$lambda-0).
// If we keep the existing representation of lambda bodies as separate functions in JVM IR, the only viable option to fix this test
// seems to support this case in the bytecode optimization pass CapturedVarsOptimizationMethodTransformer.
fun box(): String {
val x: String
run {
x = "OK"
val y = x
}
return x
}
// 0 ObjectRef
@@ -0,0 +1,10 @@
fun box(): String {
val x: String
x = "OK"
{
val y = x
}()
return x
}
// 0 ObjectRef