Closed
Description
Compiling the following code with -optimise
object Test {
def main(args: Array[String]): Unit = {
lazy val foo = 1
}
}
currently produces
class Test$ extends Object {
def <init>(): Unit =
{
super()
()
}
def main(args: String[]): Unit =
{
lazy var foo$lzy1: dotty.runtime.LazyInt = new dotty.runtime.LazyInt()
()
}
private def foo$lzyINIT1$1(foo$lzy1$1: dotty.runtime.LazyInt): Int =
scala.Int.unbox(
foo$lzy1$1.synchronized(
scala.Int.box(
if foo$lzy1$1.initialized() then foo$lzy1$1.value() else
{
foo$lzy1$1.initialized_=(true)
foo$lzy1$1.value_=(1)
foo$lzy1$1.value()
}
)
)
)
private lazy <accessor> def foo$1(foo$lzy1$2: dotty.runtime.LazyInt): Int =
if foo$lzy1$2.initialized() then foo$lzy1$2.value() else
Test.foo$lzyINIT1$1(foo$lzy1$2)
}
The optimizer should be able to eliminate the declaration of foo$lzy1
. Hopefully before the creation of foo$lzyINIT1$1
and foo$1
.