abstract class Fields extends SubComponent with InfoTransform with TreeDSL with TypingTransformers with AccessorSynthesis

Synthesize accessors, fields (and bitmaps) for (lazy) vals and modules.

During Namers, a ValDef that is lazy, deferred and/or defined in a trait carries its getter's symbol. The underlying field symbol does not exist until this phase.

For vals defined in classes, we still emit a field immediately. TODO: uniformly assign getter symbol to all ValDefs, stop using accessed.

This phase synthesizes accessors, fields and bitmaps (for lazy or init-checked vals under -Xcheckinit) in the first (closest in the subclassing lattice) subclass (not a trait) of a trait.

For lazy vals and modules, we emit accessors that using double-checked locking (DCL) to balance thread safety and performance. For both lazy vals and modules, the a compute method contains the DCL's slow path.

Local lazy vals do not receive bitmaps, but use a Lazy*Holder that has the volatile init bit and the computed value. See mkLazyLocalDef.

Constructors will move the rhs to an assignment in the template body. Those statements then move to the template into the constructor, which means it will initialize the fields defined in this template (and execute the corresponding side effects). We need to maintain the connection between getter and rhs until after specialization so that it can duplicate vals.

A ModuleDef is desugared to a ClassDef, an accessor (which reuses the module's term symbol) and a module var (unless the module is static and does not implement a member of a supertype, or we're in a trait).

For subclasses of traits that define modules, a module var is mixed in, as well as the required module accessors.

Phase ordering:

  • Runs after uncurry to deal with classes that implement SAM traits with ValDefs.
  • Runs before erasure (to get bridges), and thus before lambdalift/flatten, so that nested functions/definitions must be considered.
  • Lambdalift introduces new paramaccessors for captured vals, but runs too late in the pipeline, so mixins still synthesizes implementations for these accessors when a local trait that captures is subclassed.

In the future, would like to get closer to dotty, which lifts a val's RHS (a similar thing is done for template-level statements) to a method $_initialize_$1$x instead of a block, which is used in the constructor to initialize the val. This makes for a nice unification of strict and lazy vals, in that the RHS is lifted to a method for both, with the corresponding compute method called at the appropriate time.)

This only reduces the required number of methods per field declaration in traits, if we encode the name (and place in initialisation order) of the field in the name of its initializing method, to allow separate compilation. (The name mangling must include ordering, and thus complicate incremental compilation: ideally, we'd avoid renumbering unchanged methods, but that would result in different bytecode between clean recompiles and incremental ones).

In the even longer term (Scala 3?), I agree with @DarkDimius that it would make sense to hide the difference between strict and lazy vals. All vals are lazy, but the memoization overhead is removed when we statically know they are forced during initialization. We could still expose the low-level field semantics through private[this] vals.

In any case, the current behavior of overriding vals is pretty surprising. An overridden val's side-effect is still performed. The only change due to overriding is that its value is never written to the field (the overridden val's value is, of course, stored in the field in addition to its side-effect being performed).

TODO: Java 9 support for vals defined in traits. They are currently emitted as final, but the write (putfield) to the val does not occur syntactically within the <init> method (it's done by the trait setter, which is called from the trait's mixin constructor, which is called from the subclass's constructor...)

Source
Fields.scala
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Fields
  2. AccessorSynthesis
  3. TypingTransformers
  4. TreeDSL
  5. InfoTransform
  6. Transform
  7. SubComponent
  8. AnyRef
  9. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Fields()

Type Members

  1. abstract class StdPhase extends GlobalPhase

    A standard phase template

    A standard phase template

    Definition Classes
    SubComponent
  2. trait AccessorTreeSynthesis extends AnyRef
    Definition Classes
    AccessorSynthesis
  3. case class BitmapInfo (symbol: Global.Symbol, mask: Global.Literal) extends Product with Serializable
    Definition Classes
    AccessorSynthesis
  4. trait CheckInitAccessorSymbolSynth extends CheckedAccessorSymbolSynth
    Definition Classes
    AccessorSynthesis
  5. trait CheckedAccessorSymbolSynth extends AnyRef
    Definition Classes
    AccessorSynthesis
  6. trait CheckedAccessorTreeSynthesis extends AccessorTreeSynthesis
    Definition Classes
    AccessorSynthesis
  7. class FieldMemoization extends AnyRef
  8. class FieldsTransformer extends TypingTransformer with CheckedAccessorTreeSynthesis
  9. class Phase extends InfoTransform.Phase
    Definition Classes
    InfoTransform
  10. abstract class TypingTransformer extends Global.Transformer
    Definition Classes
    TypingTransformers

Abstract Value Members

  1. abstract val global: Global
    Definition Classes
    TypingTransformers
  2. abstract val runsAfter: List[String]

    Names of phases that must run before this phase.

    Names of phases that must run before this phase.

    Definition Classes
    SubComponent
  3. abstract val runsRightAfter: Option[String]

    Name of the phase that this phase must follow immediately.

    Name of the phase that this phase must follow immediately.

    Definition Classes
    SubComponent

Concrete Value Members

  1. object CODE
    Definition Classes
    TreeDSL
  2. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  3. final def ##(): Int
    Definition Classes
    AnyRef → Any
  4. def +(other: String): String
    Implicit
    This member is added by an implicit conversion from Fields to any2stringadd[Fields] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  5. def ->[B](y: B): (Fields, B)
    Implicit
    This member is added by an implicit conversion from Fields to ArrowAssoc[Fields] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  6. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  7. val EmptyThicket: Global.EmptyTree.type
    Definition Classes
    AccessorSynthesis
  8. final val TRAIT_SETTER_FLAGS: Long
  9. def Thicket(trees: List[Global.Tree]): Global.TermTree with Serializable
    Definition Classes
    AccessorSynthesis
  10. final def afterOwnPhase[T](op: ⇒ T): T
    Definition Classes
    SubComponent
    Annotations
    @inline()
  11. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  12. final def beforeOwnPhase[T](op: ⇒ T): T
    Definition Classes
    SubComponent
    Annotations
    @inline()
  13. def castHack(tree: Global.Tree, pt: Global.Type): Global.Tree
  14. def changesBaseClasses: Boolean
    Attributes
    protected
    Definition Classes
    InfoTransform
  15. def checkAndClear(flag: Long)(sym: Global.Symbol): Boolean
  16. def checkAndClearNeedsTrees(setter: Global.Symbol): Boolean
  17. def checkAndClearOverriddenTraitSetter(setter: Global.Symbol): Boolean
  18. def checkedAccessorSymbolSynth(clz: Global.Symbol): CheckedAccessorSymbolSynth
    Definition Classes
    AccessorSynthesis
  19. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. def dropFieldAnnotationsFromGetter(sym: Global.Symbol): Global.Symbol
  21. def enabled: Boolean

    Is this component enabled? Default is true.

    Is this component enabled? Default is true.

    Definition Classes
    SubComponent
  22. def ensuring(cond: (Fields) ⇒ Boolean, msg: ⇒ Any): Fields
    Implicit
    This member is added by an implicit conversion from Fields to Ensuring[Fields] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  23. def ensuring(cond: (Fields) ⇒ Boolean): Fields
    Implicit
    This member is added by an implicit conversion from Fields to Ensuring[Fields] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  24. def ensuring(cond: Boolean, msg: ⇒ Any): Fields
    Implicit
    This member is added by an implicit conversion from Fields to Ensuring[Fields] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  25. def ensuring(cond: Boolean): Fields
    Implicit
    This member is added by an implicit conversion from Fields to Ensuring[Fields] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  26. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  27. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  28. def explodeThicket(tree: Global.Tree): List[Global.Tree]
    Definition Classes
    AccessorSynthesis
  29. def fieldMemoizationIn(accessorOrField: Global.Symbol, site: Global.Symbol): FieldMemoization
  30. def fieldTypeOfAccessorIn(accessor: Global.Symbol, pre: Global.Type): Global.Type
  31. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  32. def formatted(fmtstr: String): String
    Implicit
    This member is added by an implicit conversion from Fields to StringFormat[Fields] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  33. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  34. def getterTreeAnnotationsTargetFieldAndGetter(owner: Global.Symbol, mods: Global.Modifiers): Boolean
  35. def hashCode(): Int

    SubComponent are added to a HashSet and two phases are the same if they have the same name

    SubComponent are added to a HashSet and two phases are the same if they have the same name

    Definition Classes
    SubComponent → AnyRef → Any
  36. val initial: Boolean

    True if this phase runs before all other phases.

    True if this phase runs before all other phases. Usually, parser.

    Definition Classes
    SubComponent
  37. val internal: Boolean

    True if this phase is not provided by a plug-in.

    True if this phase is not provided by a plug-in.

    Definition Classes
    SubComponent
  38. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  39. def keepsTypeParams: Boolean
    Attributes
    protected
    Definition Classes
    InfoTransform
  40. def lazyVarOf(sym: Global.Symbol): Global.Symbol
  41. def matchingAccessor(pre: Global.Type, member: Global.Symbol, clazz: Global.Symbol): Global.Symbol
  42. def mustExplodeThicket(tree: Global.Tree): Boolean
    Definition Classes
    AccessorSynthesis
  43. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  44. def newPhase(prev: nsc.Phase): StdPhase

    Create a new phase which applies transformer

    Create a new phase which applies transformer

    Definition Classes
    InfoTransformTransformSubComponent
  45. def newTransformer(unit: Global.CompilationUnit): Global.Transformer

    The transformer factory

    The transformer factory

    Attributes
    protected
    Definition Classes
    FieldsTransform
  46. def nonStaticModuleToMethod(module: Global.Symbol): Unit
  47. final def notDeferredOrSynthImpl(sym: Global.Symbol): Boolean
    Annotations
    @inline()
  48. final def notify(): Unit
    Definition Classes
    AnyRef
  49. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  50. def ownPhase: nsc.Phase

    The phase corresponding to this subcomponent in the current compiler run

    The phase corresponding to this subcomponent in the current compiler run

    Definition Classes
    SubComponent
  51. val phaseName: String

    the following two members override abstract members in Transform

    the following two members override abstract members in Transform

    Definition Classes
    FieldsSubComponent
  52. def phaseNewFlags: Long

    New flags defined by the phase which are not valid before

    New flags defined by the phase which are not valid before

    Definition Classes
    FieldsSubComponent
  53. def phaseNextFlags: Long

    New flags defined by the phase which are not valid until immediately after it

    New flags defined by the phase which are not valid until immediately after it

    Definition Classes
    SubComponent
  54. val requires: List[String]

    Names of phases required by this component.

    Names of phases required by this component. Default is Nil.

    Definition Classes
    SubComponent
  55. val runsBefore: List[String]

    Names of phases that must run after this phase.

    Names of phases that must run after this phase. Default is Nil.

    Definition Classes
    SubComponent
  56. def symbolAnnotationsTargetFieldAndGetter(sym: Global.Symbol): Boolean
  57. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  58. val terminal: Boolean

    True if this phase runs after all other phases.

    True if this phase runs after all other phases. Usually, terminal.

    Definition Classes
    SubComponent
  59. def toString(): String
    Definition Classes
    AnyRef → Any
  60. def transformInfo(sym: Global.Symbol, tp: Global.Type): Global.Type
    Definition Classes
    FieldsInfoTransform
  61. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  62. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  63. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  64. def [B](y: B): (Fields, B)
    Implicit
    This member is added by an implicit conversion from Fields to ArrowAssoc[Fields] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Inherited from AccessorSynthesis

Inherited from TypingTransformers

Inherited from TreeDSL

Inherited from InfoTransform

Inherited from Transform

Inherited from SubComponent

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd from Fields to any2stringadd[Fields]

Inherited by implicit conversion StringFormat from Fields to StringFormat[Fields]

Inherited by implicit conversion Ensuring from Fields to Ensuring[Fields]

Inherited by implicit conversion ArrowAssoc from Fields to ArrowAssoc[Fields]

Ungrouped