Skip to content

Eliminate unnecessary module loads #16

Open
@retronym

Description

@retronym

After inlining the module instance field loads remain - they have to, the static initializer of the module class may have side effects:

object T {
  println("hui")
  @inline def f = 1
}

class C {
  def foo = T.f + T.f
}

generates

  public foo()I
    GETSTATIC T$.MODULE$ : LT$;
    DUP
    IFNONNULL L0
    ACONST_NULL
    ATHROW
   L0
   FRAME SAME1 T$
    ASTORE 1
    ICONST_1
    ISTORE 2
    ILOAD 2
    GETSTATIC T$.MODULE$ : LT$;
    DUP
    IFNONNULL L1
    ACONST_NULL
    ATHROW
   L1
   FRAME FULL [C T$ I] [I T$]
    ASTORE 3
    ICONST_1
    ISTORE 4
    ILOAD 4
    IADD
    IRETURN

The first GETSTATIC is required for the side effect. The second is not. The null checks are not required, module instances are always non-null, but that will be handled by scala-opt/scala#8.

Idea: for module classes we could add a bit to the ScalaInlineInfo attribute which tells whether the module constructor is known to have no side-effects (the module has only defs, for example).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions