Packages

  • package root

    The Scala compiler and reflection APIs.

    The Scala compiler and reflection APIs.

    Definition Classes
    root
  • package scala
    Definition Classes
    root
  • package tools
    Definition Classes
    scala
  • package nsc
    Definition Classes
    tools
  • package transform
    Definition Classes
    nsc
  • abstract class Fields extends SubComponent with InfoTransform with TreeDSL with TypingTransformers with AccessorSynthesis

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

    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...)

    Definition Classes
    transform
  • AccessorTreeSynthesis
  • BitmapInfo
  • CODE
  • CheckedAccessorSymbolSynth
  • CheckedAccessorTreeSynthesis
  • FieldMemoization
  • FieldsTransformer
  • Phase
  • StdPhase
  • TypingTransformer
c

scala.tools.nsc.transform.Fields

FieldsTransformer

class FieldsTransformer extends TypingTransformer with CheckedAccessorTreeSynthesis

Source
Fields.scala
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. FieldsTransformer
  2. CheckedAccessorTreeSynthesis
  3. AccessorTreeSynthesis
  4. TypingTransformer
  5. Transformer
  6. InternalTransformer
  7. Transformer
  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 FieldsTransformer(unit: Global.CompilationUnit)

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. def +(other: String): String
    Implicit
    This member is added by an implicit conversion from FieldsTransformer toany2stringadd[FieldsTransformer] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (FieldsTransformer, B)
    Implicit
    This member is added by an implicit conversion from FieldsTransformer toArrowAssoc[FieldsTransformer] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def atOwner[A](tree: Global.Tree, owner: Global.Symbol)(trans: => A): A
    Definition Classes
    TypingTransformer
  8. final def atOwner[A](owner: Global.Symbol)(trans: => A): A
    Definition Classes
    TypingTransformer → Transformer
  9. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  10. var curTree: Global.Tree
    Attributes
    protected
    Definition Classes
    TypingTransformer
  11. def currentClass: Global.Symbol
    Attributes
    protected
    Definition Classes
    Transformer
  12. def currentMethod: Global.Symbol
    Attributes
    protected
    Definition Classes
    Transformer
  13. var currentOwner: Global.Symbol
    Attributes
    protected[scala]
    Definition Classes
    Transformer
  14. def deriveUnitDef(stat: Global.Tree): Global.DefDef
  15. def ensuring(cond: (FieldsTransformer) => Boolean, msg: => Any): FieldsTransformer
    Implicit
    This member is added by an implicit conversion from FieldsTransformer toEnsuring[FieldsTransformer] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  16. def ensuring(cond: (FieldsTransformer) => Boolean): FieldsTransformer
    Implicit
    This member is added by an implicit conversion from FieldsTransformer toEnsuring[FieldsTransformer] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  17. def ensuring(cond: Boolean, msg: => Any): FieldsTransformer
    Implicit
    This member is added by an implicit conversion from FieldsTransformer toEnsuring[FieldsTransformer] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  18. def ensuring(cond: Boolean): FieldsTransformer
    Implicit
    This member is added by an implicit conversion from FieldsTransformer toEnsuring[FieldsTransformer] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  19. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  20. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  21. def fieldsAndAccessors(clazz: Global.Symbol): List[Global.Tree]
  22. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  23. def formatted(fmtstr: String): String
    Implicit
    This member is added by an implicit conversion from FieldsTransformer toStringFormat[FieldsTransformer] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  24. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  25. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  26. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  27. var localTyper: (analyzer)#Typer
    Definition Classes
    TypingTransformer
  28. def mkAccessor(accessor: Global.Symbol)(body: Global.Tree): Global.DefDef
  29. def mkTypedUnit(pos: Global.Position): Global.Tree
  30. def mkTypedValDef(sym: Global.Symbol, rhs: Global.Tree = EmptyTree): Global.ValDef
  31. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  32. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  33. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  34. def rhsAtOwner(stat: Global.ValOrDefDef, newOwner: Global.Symbol): Global.Tree
  35. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  36. def toString(): String
    Definition Classes
    AnyRef → Any
  37. def transform(stat: Global.Tree): Global.Tree
    Definition Classes
    FieldsTransformerTypingTransformer → InternalTransformer → Transformer
  38. def transformCaseDefs(trees: List[Global.CaseDef]): List[Global.CaseDef]
    Definition Classes
    Transformer
  39. def transformIdents(trees: List[Global.Ident]): List[Global.Ident]
    Definition Classes
    Transformer
  40. def transformMemberDefs(trees: List[Global.MemberDef]): List[Global.MemberDef]
    Definition Classes
    Transformer
  41. def transformModifiers(mods: Global.Modifiers): Global.Modifiers
    Definition Classes
    Transformer
  42. def transformStats(stats: List[Global.Tree], exprOwner: Global.Symbol): List[Global.Tree]
    Definition Classes
    FieldsTransformer → Transformer
  43. def transformTemplate(tree: Global.Template): Global.Template
    Definition Classes
    Transformer
  44. def transformTermsAtExprOwner(exprOwner: Global.Symbol)(stat: Global.Tree): Global.Tree
  45. def transformTrees(trees: List[Global.Tree]): List[Global.Tree]
    Definition Classes
    Transformer
  46. def transformTypeDefs(trees: List[Global.TypeDef]): List[Global.TypeDef]
    Definition Classes
    Transformer
  47. def transformUnit(unit: Global.CompilationUnit): Unit
    Definition Classes
    Transformer
  48. def transformValDef(tree: Global.ValDef): Global.ValDef
    Definition Classes
    Transformer
  49. def transformValDefs(trees: List[Global.ValDef]): List[Global.ValDef]
    Definition Classes
    Transformer
  50. def transformValDefss(treess: List[List[Global.ValDef]]): List[List[Global.ValDef]]
    Definition Classes
    Transformer
  51. val treeCopy: Global.TreeCopier
    Definition Classes
    Transformer
  52. def typedPos(pos: Global.Position)(tree: Global.Tree): Global.Tree
    Attributes
    protected
    Definition Classes
    FieldsTransformerAccessorTreeSynthesis
  53. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  54. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  55. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Deprecated Value Members

  1. def [B](y: B): (FieldsTransformer, B)
    Implicit
    This member is added by an implicit conversion from FieldsTransformer toArrowAssoc[FieldsTransformer] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @deprecated
    Deprecated

    (Since version 2.13.0) Use -> instead. If you still wish to display it as one character, consider using a font with programming ligatures such as Fira Code.

Inherited from Global.Transformer

Inherited from Global.Transformer

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd fromFieldsTransformer to any2stringadd[FieldsTransformer]

Inherited by implicit conversion StringFormat fromFieldsTransformer to StringFormat[FieldsTransformer]

Inherited by implicit conversion Ensuring fromFieldsTransformer to Ensuring[FieldsTransformer]

Inherited by implicit conversion ArrowAssoc fromFieldsTransformer to ArrowAssoc[FieldsTransformer]

Ungrouped