Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement null / non-null analysis #8

Closed
retronym opened this issue Aug 5, 2015 · 3 comments
Closed

Implement null / non-null analysis #8

retronym opened this issue Aug 5, 2015 · 3 comments

Comments

@retronym
Copy link
Member

retronym commented Aug 5, 2015

Can be used to avoid unnecessary null-checks when inlining an instance method.

Miguel's code: NullnessPropagator

Below there are two null checks in t, none is necessary: t is an instance method, we know in it's body that ALOAD 0 is non-null.

class C {
  @inline final def f = 1
  def t = f + f
}
@lrytz
Copy link
Member

lrytz commented Sep 23, 2015

Nullness analysis is implemented in scala/scala#4519, performance of aliasing analysis improved in scala/scala#4711.

still to do: Peephole opts around null

  • see miguel's NullnessPropagator.transform

also to do: take null tests into account (if (x == null) { [x known null here] })

Miguel's treats module loads as not null. Jason provided a counterexample:

class C(a: Any)
object X { def o = O}
object O extends C(println(X.o)) { println(O) }
object Test extends App { O }
scalac sandbox/test.scala && qscala Test
null
O$@4c873330

A bit simpler:

class C { val b = O }
object O extends C

object Test extends App {
  println(O.b) // null
}

Another example:

object A1 extends {
  val e = B1
} with Object {
  val b1 = B1
}

object B1 {
  val a1 = A1
}

object Test extends App {
  println(A1.b1) // B1
  println(B1.a1) // null
  println(A1.e)  // B1
}

See also #16

@lrytz
Copy link
Member

lrytz commented Nov 9, 2015

PatMat generates null tests that can potentially be eliminated:

  public f(I)I
   L0
    LINENUMBER 3 L0
    NEW C
    DUP
    ILOAD 1
    INVOKESPECIAL C.<init> (I)V
    ASTORE 3
    ALOAD 3
    IFNULL L1
    [...]

@lrytz
Copy link
Member

lrytz commented Jan 25, 2016

Implemented in scala/scala#4858 / scala/scala@80b0660

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants