Dotty Documentation


class CollectNullableFields
extends MiniPhase

Collect fields that can be nulled out after use in lazy initialization.

This information is used during lazy val transformation to assign null to private fields that are only used within a lazy val initializer. This is not just an optimization, but is needed for correctness to prevent memory leaks. E.g.

class TestByNameLazy(byNameMsg: => String) {
  lazy val byLazyValMsg = byNameMsg

Here byNameMsg should be null out once byLazyValMsg is initialised.

A field is nullable if all the conditions below hold: - belongs to a non trait-class - is private[this] - is not lazy - its type is nullable - is only used in a lazy val initializer - defined in the same class as the lazy val

[-] Constructors

CollectNullableFields ( )

[-] Members

[+] private sealed trait FieldInfo
[+] private object NotNullable
[+] private case class Nullable
[+] private object Nullable
[+] private var nullability : IdentityHashMap [ Symbol, FieldInfo ]

Whether or not a field is nullable

[+] def lazyValNullables ( implicit ctx: Context ) : IdentityHashMap [ Symbol, ListBuffer [ Symbol ] ]

Map lazy values to the fields they should null after initialization.

[+] override def phaseName : String

A name given to the Phase that can be used to debug the compiler. For instance, it is possible to print trees after a given phase using:

$ ./bin/dotc -Xprint:<phaseNameHere> sourceFile.scala
[+] override def prepareForUnit ( tree: Tree ) ( implicit ctx: Context ) : Context
[+] private def recordUse ( tree: Tree ) ( implicit ctx: Context ) : Tree
[+] override def runsAfter : Set [ String ]

Running after ElimByName to see by names as nullable types.

[+] override def transformIdent ( tree: Ident ) ( implicit ctx: Context ) : Tree
[+] override def transformSelect ( tree: Select ) ( implicit ctx: Context ) : Tree