Scala Compiler 2.13.16 - scala.tools.nsc.transform.SpecializeTypes
Keywords: Scala Compiler 2.13.16 scala.tools.nsc.transform.SpecializeTypes

Scala Compiler2.13.16 < Back


# 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
-  package async
  Definition Classes
    transform
-  package patmat
  Definition Classes
    transform
- AccessorSynthesis
- CleanUp
- Constructors
- Delambdafy
- Erasure
- ExplicitOuter
- ExtensionMethods
- Fields
- Flatten
- InfoTransform
- LambdaLift
- Mixin
- OverridingPairs
- PostErasure
- SampleTransform
- SpecializeTypes
- Statics
- TailCalls
- Transform
- TypeAdaptingTransformer
- TypingTransformers
- UnCurry

c

scala.tools.nsc.transform

# SpecializeTypes

###

#### abstract class SpecializeTypes extends SubComponent with InfoTransform with TypingTransformers

Specialize code on types.

Make sure you've read the thesis:

Iulian Dragos: Compiling Scala for Performance (chapter 4)

There are some things worth noting, (possibly) not mentioned there: 0) Make sure you understand the meaning of various `SpecializedInfo` descriptors defined below.

1) Specializing traits by introducing bridges in specialized methods of the specialized trait may introduce problems during mixin composition. Concretely, it may cause cyclic calls and result in a stack overflow. See ticket #4351. This was solved by introducing an `Abstract` specialized info descriptor. Instead of generating a bridge in the trait, an abstract method is generated.

2) Specialized private members sometimes have to be switched to protected. In some cases, even this is not enough. Example:

    class A[@specialized T](protected val d: T) {
      def foo(that: A[T]) = that.d
    }

Specialization will generate a specialized class and a specialized method:

    class A$mcI$sp(protected val d: Int) extends A[Int] {
      def foo(that: A[Int]) = foo$mcI$sp(that)
      def foo(that: A[Int]) = that.d
    }

Above, `A$mcI$sp` cannot access `d`, so the method cannot be typechecked.

Source
  SpecializeTypes.scala

Linear Supertypes
TypingTransformers, InfoTransform, Transform, SubComponent, AnyRef, Any
Known Subclasses
specializeTypes
Type Hierarchy

Ordering

1. Alphabetic
2. By Inheritance

Inherited

1. SpecializeTypes
2. TypingTransformers
3. InfoTransform
4. Transform
5. SubComponent
6. AnyRef
7. Any

Implicitly

1. by any2stringadd
2. by StringFormat
3. by Ensuring
4. by ArrowAssoc

1. Hide All
2. Show All

Visibility

1. Public
2. Protected

### Instance Constructors

1.  new SpecializeTypes()

### Type Members

1.  abstract class StdPhase extends GlobalPhase

   A standard phase template

   A standard phase template

   Definition Classes
     SubComponent
2.  case class Abstract(t: Global.Symbol) extends SpecializedInfo with Product with Serializable

   Symbol is a specialized abstract method, either specialized or original.

   Symbol is a specialized abstract method, either specialized or original. The original `t` is abstract.

3.  class Duplicator extends Duplicators

   This duplicator additionally performs casts of expressions if that is allowed by the `casts` map.

4.  case class Forward(t: Global.Symbol) extends SpecializedInfo with Product with Serializable

   Symbol is a method that should be forwarded to 't'

5.  case class Implementation(target: Global.Symbol) extends SpecializedInfo with Product with Serializable

   Symbol is a specialized method whose body should be the target's method body.

6.  class ImplementationAdapter extends Global.TreeSymSubstituter

   A tree symbol substituter that substitutes on type skolems.

   A tree symbol substituter that substitutes on type skolems. If a type parameter is a skolem, it looks for the original symbol in the 'from' and maps it to the corresponding new symbol. The new symbol should probably be a type skolem as well (not enforced).

   All private members are made protected in order to be accessible from specialized classes.

7.  final type InfoPhase = Phase
   Definition Classes
     InfoTransform
   Annotations
     @nowarn()
8.  case class NormalizedMember(target: Global.Symbol) extends SpecializedInfo with Product with Serializable

   Symbol is a normalized member obtained by specializing 'target'.

9.  case class Overload(sym: Global.Symbol, env: TypeEnv) extends Product with Serializable
10.  case class SpecialOverload(original: Global.Symbol, env: TypeEnv) extends SpecializedInfo with Product with Serializable

    Symbol is a special overloaded method of 'original', in the environment env.

11.  case class SpecialOverride(target: Global.Symbol) extends SpecializedInfo with Product with Serializable

    Symbol is a specialized override paired with `target`.

12.  case class SpecialSuperAccessor(t: Global.Symbol) extends SpecializedInfo with Product with Serializable

    Symbol is a special overload of the super accessor.

    Symbol is a special overload of the super accessor. Treated like an abstract method with no specialized overload.

13.  class SpecializationDuplicator extends Duplicator

    Introduced to fix scala/bug#7343: Phase ordering problem between Duplicators and Specialization.

    Introduced to fix scala/bug#7343: Phase ordering problem between Duplicators and Specialization. brief explanation: specialization rewires class parents during info transformation, and the new info then guides the tree changes. But if a symbol is created during duplication, which runs after specialization, its info is not visited and thus the corresponding tree is not specialized. One manifestation is the following:

        object Test {
          class Parent[@specialized(Int) T]

          def spec_method[@specialized(Int) T](t: T, expectedXSuper: String) = {
            class X extends Parent[T]()
            // even in the specialized variant, the local X class
            // doesn't extend Parent$mcI$sp, since its symbol has
            // been created after specialization and was not seen
            // by specialization's info transformer.
            ...
          }
        }

    We fix this by forcing duplication to take place before specialization.

    Note: The constructors phase (which also uses duplication) comes after erasure and uses the post-erasure typer => we must protect it from the beforeSpecialization phase shifting.

14.  class SpecializationPhase extends InfoPhase
15.  class SpecializationTransformer extends TypingTransformer
16.  case class SpecializedAccessor(target: Global.Symbol) extends SpecializedInfo with Product with Serializable

    Symbol is a specialized accessor for the `target` field.

17.  sealed abstract class SpecializedInfo extends AnyRef
18.  case class SpecializedInnerClass(target: Global.Symbol, env: TypeEnv) extends SpecializedInfo with Product with Serializable

    A specialized inner class that specializes original inner class `target` on a type parameter of the enclosing class, in the typeenv `env`.

19.  type TypeEnv = Map[Global.Symbol, Global.Type]
20.  abstract class ThicketTransformer extends TypingTransformer

    A base class for typing transformers that need to perform "thicket expansion".

    A base class for typing transformers that need to perform "thicket expansion". A thicket is the output of a transformation that is flattened into the enclosing block.

    Definition Classes
      TypingTransformers
21.  abstract class TypingTransformer extends Global.AstTransformer
    Definition Classes
      TypingTransformers

### Deprecated Type Members

1.  class Phase extends InfoTransform.Phase
   Definition Classes
     InfoTransform
   Annotations
     @nowarn() @deprecated
   Deprecated

     (Since version 2.13.4) use InfoPhase instead

### 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.  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 SpecializeTypes toany2stringadd[SpecializeTypes] performed by method any2stringadd in scala.Predef.
   Definition Classes
     any2stringadd
4.  def ->[B](y: B): (SpecializeTypes, B)
   Implicit
     This member is added by an implicit conversion from SpecializeTypes toArrowAssoc[SpecializeTypes] performed by method ArrowAssoc in scala.Predef.
   Definition Classes
     ArrowAssoc
   Annotations
     @inline()
5.  final def ==(arg0: Any): Boolean
   Definition Classes
     AnyRef → Any
6.  def addConcreteSpecMethod(m: Global.Symbol): Unit

   Add method m to the set of symbols for which we need an implementation tree in the tree transformer.

   Add method m to the set of symbols for which we need an implementation tree in the tree transformer.

   Note

     This field is part of the specializeTypes subcomponent, so any symbols that here are not garbage collected at the end of a compiler run!

7.  final def afterOwnPhase[T](op: => T): T
   Definition Classes
     SubComponent
   Annotations
     @inline()
8.  final def asInstanceOf[T0]: T0
   Definition Classes
     Any
9.  final def beforeOwnPhase[T](op: => T): T
   Definition Classes
     SubComponent
   Annotations
     @inline()
10.  def changesBaseClasses: Boolean

    This phase changes base classes.

    This phase changes base classes.

    Definition Classes
      SpecializeTypes → InfoTransform
11.  def clone(): AnyRef
    Attributes
      protected[lang]
    Definition Classes
      AnyRef
    Annotations
      @throws(classOf[java.lang.CloneNotSupportedException]) @native()
12.  def concreteTypes(sym: Global.Symbol): List[Global.Type]

    Return the types `sym` should be specialized at.

    Return the types `sym` should be specialized at. This may be some of the primitive types or AnyRef. AnyRef means that a new type parameter T will be generated later, known to be a subtype of AnyRef (T <: AnyRef). These are in a meaningful order for stability purposes.

13.  def emptyEnv: TypeEnv
14.  def enabled: Boolean

    Is this component enabled? Default is true.

    Is this component enabled? Default is true.

    Definition Classes
      SubComponent
15.  def ensuring(cond: (SpecializeTypes) => Boolean, msg: => Any): SpecializeTypes
    Implicit
      This member is added by an implicit conversion from SpecializeTypes toEnsuring[SpecializeTypes] performed by method Ensuring in scala.Predef.
    Definition Classes
      Ensuring
16.  def ensuring(cond: (SpecializeTypes) => Boolean): SpecializeTypes
    Implicit
      This member is added by an implicit conversion from SpecializeTypes toEnsuring[SpecializeTypes] performed by method Ensuring in scala.Predef.
    Definition Classes
      Ensuring
17.  def ensuring(cond: Boolean, msg: => Any): SpecializeTypes
    Implicit
      This member is added by an implicit conversion from SpecializeTypes toEnsuring[SpecializeTypes] performed by method Ensuring in scala.Predef.
    Definition Classes
      Ensuring
18.  def ensuring(cond: Boolean): SpecializeTypes
    Implicit
      This member is added by an implicit conversion from SpecializeTypes toEnsuring[SpecializeTypes] performed by method Ensuring in scala.Predef.
    Definition Classes
      Ensuring
19.  final def eq(arg0: AnyRef): Boolean
    Definition Classes
      AnyRef
20.  def equals(other: Any): Boolean
    Definition Classes
      SubComponent → AnyRef → Any
21.  def finalize(): Unit
    Attributes
      protected[lang]
    Definition Classes
      AnyRef
    Annotations
      @throws(classOf[java.lang.Throwable])
22.  final def getClass(): Class[_ <: AnyRef]
    Definition Classes
      AnyRef → Any
    Annotations
      @native()
23.  def hasSpecializedParams(clazz: Global.Symbol): Boolean

    Has `clazz` any type parameters that need be specialized?

24.  def hashCode(): Int

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

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

    Definition Classes
      SubComponent → AnyRef → Any
25.  def illegalSpecializedInheritance(clazz: Global.Symbol): Boolean
26.  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
27.  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
28.  final def isInstanceOf[T0]: Boolean
    Definition Classes
      Any
29.  def isNormalizedMember(m: Global.Symbol): Boolean
30.  def isSpecializedIn(sym: Global.Symbol, site: Global.Type): Boolean

    Refines possiblySpecialized taking into account the instantiation of the specialized type variables at `site`

31.  def keepsTypeParams: Boolean
    Definition Classes
      SpecializeTypes → InfoTransform
32.  final def ne(arg0: AnyRef): Boolean
    Definition Classes
      AnyRef
33.  def newPhase(prev: nsc.Phase): StdPhase

    Just to mark uncheckable

    Just to mark uncheckable

    Definition Classes
      SpecializeTypes → InfoTransform → Transform → SubComponent
34.  def newRootLocalTyper(unit: Global.CompilationUnit): (analyzer)#Typer
    Attributes
      protected
    Definition Classes
      TypingTransformers
35.  def newTransformer(unit: Global.CompilationUnit): Global.AstTransformer

    The transformer factory

    The transformer factory

    Attributes
      protected
    Definition Classes
      SpecializeTypes → Transform
36.  def nonConflicting(env: TypeEnv): Boolean

    Is any type variable in `env` conflicting with any if its type bounds, when type bindings in `env` are taken into account?

    Is any type variable in `env` conflicting with any if its type bounds, when type bindings in `env` are taken into account?

    A conflicting type environment could still be satisfiable.

37.  final def notify(): Unit
    Definition Classes
      AnyRef
    Annotations
      @native()
38.  final def notifyAll(): Unit
    Definition Classes
      AnyRef
    Annotations
      @native()
39.  def originalClass(clazz: Global.Symbol): Global.Symbol

    Return the generic class corresponding to this specialized class.

40.  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
41.  val phaseName: String

    the name of the phase:

    the name of the phase:

    Definition Classes
      SpecializeTypes → SubComponent
42.  def phaseNewFlags: Long

    The following flags may be set by this phase:

    The following flags may be set by this phase:

    Definition Classes
      SpecializeTypes → SubComponent
43.  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
44.  def possiblySpecialized(sym: Global.Symbol): Boolean

    Is `member` potentially affected by specialization? This is a gross overapproximation, but it should be okay for use outside of specialization.

45.  def produceTypeParameters(syms: List[Global.Symbol], nowner: Global.Symbol, env: TypeEnv): collection.immutable.List[Global.Symbol]

    Produces the symbols from type parameters `syms` of the original owner, in the given type environment `env`.

    Produces the symbols from type parameters `syms` of the original owner, in the given type environment `env`. The new owner is `nowner`.

    Non-specialized type parameters are cloned into new ones. Type parameters specialized on AnyRef have preexisting symbols.

    For instance, a @specialized(AnyRef) T, will become T$sp <: AnyRef.

46.  val requires: List[String]

    Names of phases required by this component.

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

    Definition Classes
      SubComponent
47.  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
48.  def satisfiabilityConstraints(env: TypeEnv): Option[TypeEnv]
49.  def satisfiable(env: TypeEnv, warnings: Boolean = false): Boolean

    The type environment is sound w.r.t.

    The type environment is sound w.r.t. to all type bounds or only soft conflicts appear. An environment is sound if all bindings are within the bounds of the given type variable. A soft conflict is a binding that does not fall within the bounds, but whose bounds contain type variables that are @specialized, (that could become satisfiable).

50.  def specializationOf(sym: Global.Symbol): Map[TypeEnv, Global.Symbol]
51.  def specializeClass(clazz: Global.Symbol, outerEnv: TypeEnv): List[Global.Symbol]

    Specialize 'clazz', in the environment `outerEnv`.

    Specialize 'clazz', in the environment `outerEnv`. The outer environment contains bindings for specialized types of enclosing classes.

    A class C is specialized w.r.t to its own specialized type params `stps`, by specializing its members, and creating a new class for each combination of `stps`.

52.  val specializedClass: AnyRefMap[Global.Symbol, HashMap[TypeEnv, Global.Symbol]]

    For a given class and concrete type arguments, give its specialized class

53.  def specializedFunctionName(sym: Global.Symbol, args: List[Global.Type]): reflect.internal.Symbols.Symbol.NameType
54.  def specializedParams(sym: Global.Symbol): List[Global.Symbol]

    Return specialized type parameters.

55.  val specializedType: Global.TypeMap
56.  def specializedTypeVars(tpe: Global.Type): Set[Global.Symbol]

    Return the set of @specialized type variables mentioned by the given type.

    Return the set of @specialized type variables mentioned by the given type. It only counts type variables that appear:

    - naked
    - as arguments to type constructors in @specialized positions (arrays are considered as Array[@specialized T])
57.  def specializedTypeVars(sym: Global.Symbol): Set[Global.Symbol]
58.  def specializedTypeVars(tpes: List[Global.Type]): Set[Global.Symbol]
59.  def specializedTypeVarsBuffer(tpe: Global.Type, result: Buffer[Global.Symbol]): Unit

    Return the set of @specialized type variables mentioned by the given type.

    Return the set of @specialized type variables mentioned by the given type. It only counts type variables that appear:

    - naked
    - as arguments to type constructors in @specialized positions (arrays are considered as Array[@specialized T])
60.  def specializedTypeVarsBuffer(sym: Global.Symbol, result: Buffer[Global.Symbol]): Unit
61.  def specializesClass(sym: Global.Symbol): Global.Symbol

    If the symbol is the companion of a value class, the value class.

    If the symbol is the companion of a value class, the value class. Otherwise, AnyRef.

62.  def survivingArgs(sym: Global.Symbol, args: List[Global.Type]): List[Global.Type]

    Given an original class symbol and a list of types its type parameters are instantiated at returns a list of type parameters that should remain in the TypeRef when instantiating a specialized type.

63.  def survivingParams(params: List[Global.Symbol], env: TypeEnv): collection.immutable.List[Global.Symbol]

    Type parameters that survive when specializing in the specified environment.

64.  final def synchronized[T0](arg0: => T0): T0
    Definition Classes
      AnyRef
65.  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
66.  def toString(): String
    Definition Classes
      AnyRef → Any
67.  def transformInfo(sym: Global.Symbol, tpe: Global.Type): Global.Type

    Type transformation.

    Type transformation. It is applied to all symbols, compiled or loaded. If it is a 'no-specialization' run, it is applied only to loaded symbols.

    Definition Classes
      SpecializeTypes → InfoTransform
68.  final def wait(): Unit
    Definition Classes
      AnyRef
    Annotations
      @throws(classOf[java.lang.InterruptedException])
69.  final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
      AnyRef
    Annotations
      @throws(classOf[java.lang.InterruptedException])
70.  final def wait(arg0: Long): Unit
    Definition Classes
      AnyRef
    Annotations
      @throws(classOf[java.lang.InterruptedException]) @native()
71.  object SpecializedSuperConstructorCallArgument
72.  object TypeEnv
73.  case object UnifyError extends ControlThrowable with Product with Serializable

### Deprecated Value Members

1.  def formatted(fmtstr: String): String
   Implicit
     This member is added by an implicit conversion from SpecializeTypes toStringFormat[SpecializeTypes] performed by method StringFormat in scala.Predef.
   Definition Classes
     StringFormat
   Annotations
     @deprecated @inline()
   Deprecated

     (Since version 2.12.16) Use `formatString.format(value)` instead of `value.formatted(formatString)`, or use the `f""` string interpolator. In Java 15 and later, `formatted` resolves to the new method in String which has reversed parameters.

2.  def →[B](y: B): (SpecializeTypes, B)
   Implicit
     This member is added by an implicit conversion from SpecializeTypes toArrowAssoc[SpecializeTypes] 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 TypingTransformers

### Inherited from InfoTransform

### Inherited from Transform

### Inherited from SubComponent

### Inherited from AnyRef

### Inherited from Any

### Inherited by implicit conversion any2stringadd fromSpecializeTypes to any2stringadd[SpecializeTypes]

### Inherited by implicit conversion StringFormat fromSpecializeTypes to StringFormat[SpecializeTypes]

### Inherited by implicit conversion Ensuring fromSpecializeTypes to Ensuring[SpecializeTypes]

### Inherited by implicit conversion ArrowAssoc fromSpecializeTypes to ArrowAssoc[SpecializeTypes]

### Ungrouped