scala-dev icon indicating copy to clipboard operation
scala-dev copied to clipboard

Remove deserializeLambda and $deserializeLambdaCache$ if all closures are eliminated

Open lrytz opened this issue 10 years ago • 0 comments
trafficstars

If all closure instantiations in a class are eliminated, also eliminate (or don't emit) the deserializeLambda method and the $deserializeLambdaCache$ field.

class C {
  def f = {
    val fun = (x: Int) => x + 1
    fun(100)
  }
}

compiled with -Yopt:l:classpath

  // access flags 0x100A
  private static synthetic Ljava/util/Map; $deserializeLambdaCache$

  // access flags 0x1
  public f()I
   L0
    LINENUMBER 4 L0
    BIPUSH 100
    INVOKESTATIC C.C$$$anonfun$1 (I)I
    IRETURN
   L1
    LOCALVARIABLE this LC; L0 L1 0
    MAXSTACK = 1
    MAXLOCALS = 1

  // access flags 0x1019
  public final static synthetic C$$$anonfun$1(I)I
   L0
    LINENUMBER 3 L0
    ILOAD 0
    ICONST_1
    IADD
    IRETURN
   L1
    LOCALVARIABLE x I L0 L1 0
    MAXSTACK = 2
    MAXLOCALS = 1

  // access flags 0x1
  public <init>()V
    ...

  // access flags 0x100A
  private static synthetic $deserializeLambda$(Ljava/lang/invoke/SerializedLambda;)Ljava/lang/Object;
    ...
}

lrytz avatar Nov 12 '15 10:11 lrytz