Skip to content

Too much redundant lazy vals code. #676

Closed
@odersky

Description

@odersky

Have a look at copnstructors.scala (only one example of many). We find:

final lazy var B$lzy1: A.this.B$ = null.asInstanceOf[A.this.B$]
final lazy <accessor> module def B(): A.this.B$ = {
  lazy var result: A.this.B$ = null.asInstanceOf[A.this.B$]
  lazy var retry: Boolean = true
  lazy var flag: Long = 0L
  {
    def while$(): Unit = 
      if retry then {
        flag = dotty.runtime.LazyVals.get(this, A.OFFSET$0)
        dotty.runtime.LazyVals.STATE(flag, 0) match {
          case 0 => 
            if dotty.runtime.LazyVals.CAS(this, A.OFFSET$0, flag, 1, 0) then

            {
              try result = new A.this.B$() catch {
                case ex$ @ ex$ => 
                  dotty.runtime.LazyVals.setFlag(this, A.OFFSET$0, 0, 0)
                  throw ex$
              }
              this.B$lzy1 = result
              dotty.runtime.LazyVals.setFlag(this, A.OFFSET$0, 0, 0)
              retry = false
              ()
            }
             else ()
          case 1 => 
            dotty.runtime.LazyVals.wait4Notification(this, A.OFFSET$0, flag
              , 
            0)
          case 2 => 
            dotty.runtime.LazyVals.wait4Notification(this, A.OFFSET$0, flag
              , 
            0)
          case 3 => 
            retry = false
            result = this.B$lzy1
            ()
          case _ => ()
        }
        while$()
      } else ()
    while$()
  }
  result
}
final module class B$ extends Object { this: A.this.B$ => 
  def <init>(): Unit = {
    super()
    ()
  }
}

This is all for a module that was not mentioned in source and that is in fact empty! This is wrong on many levels

  • empty modules should not generate code at all.
  • non-empty modules should not need bitmaps, since they are treated as non-volatile, and null is good enough as an indication that the module is not initialized.
  • even if this is eliminated later it is still wasteful for compile time. Why generate a code avalanche in the first place?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions