Definitions

A class defining symbols and types of standard definitions

Companion:
object
class Object
trait Matchable
class Any

Type members

Classlikes

object ArrayOf

An extractor for context function types As ?=> B, possibly with dependent refinements. Optionally returns a triple consisting of the argument types As, the result type B and a whether the type is an erased context function.

An extractor for context function types As ?=> B, possibly with dependent refinements. Optionally returns a triple consisting of the argument types As, the result type B and a whether the type is an erased context function.

object FunctionOf
object MatchCase

An extractor for multi-dimensional arrays. Note that this will also extract the high bound if an element type is a wildcard upper-bounded by an array. E.g.

An extractor for multi-dimensional arrays. Note that this will also extract the high bound if an element type is a wildcard upper-bounded by an array. E.g.

Array[? <: Array[? <: Number]]

would match

MultiArrayOf(<? <: Number>, 2)

class PerRun[T](generate: Context ?=> T)

Value members

Concrete methods

def ClassType(arg: Type)(using Context): Type
def EnumType(sym: Symbol)(using Context): TypeRef

The enumeration type, goven a value of the enumeration

The enumeration type, goven a value of the enumeration

def FunctionClass(n: Int, isContextual: Boolean, isErased: Boolean)(using Context): Symbol
def FunctionType(n: Int, isContextual: Boolean, isErased: Boolean)(using Context): TypeRef
def SpecializedTuple(base: Symbol, args: List[Type])(using Context): Symbol

If it is BoxedUnit, remove java.io.Serializable from parents.

If it is BoxedUnit, remove java.io.Serializable from parents.

def adjustForTuple(cls: ClassSymbol, tparams: List[TypeSymbol], parents: List[Type]): List[Type]

If cls is Tuple1..Tuple22, add the corresponding *: type as last parent to parents

If cls is Tuple1..Tuple22, add the corresponding *: type as last parent to parents

Return underlying context function type (i.e. instance of an ContextFunctionN class) or NoType if none exists. The following types are considered as underlying types:

Return underlying context function type (i.e. instance of an ContextFunctionN class) or NoType if none exists. The following types are considered as underlying types:

  • the alias of an alias type
  • the instance or origin of a TypeVar (i.e. the result of a stripTypeVar)
  • the upper bound of a TypeParamRef in the current constraint
def boxedType(tp: Type)(using Context): TypeRef

The type of the boxed class corresponding to primitive value type tp.

The type of the boxed class corresponding to primitive value type tp.

def functionArity(tp: Type)(using Context): Int

Returns the erased type of the function class cls

Returns the erased type of the function class cls

  • FunctionN for N > 22 becomes FunctionXXL
  • FunctionN for 22 > N >= 0 remains as FunctionN
  • ContextFunctionN for N > 22 becomes FunctionXXL
  • ContextFunctionN for N <= 22 becomes FunctionN
  • ErasedFunctionN becomes Function0
  • ImplicitErasedFunctionN becomes Function0
  • anything else becomes a NoType

When typing a primitive value class or AnyVal, we ignore the getClass member: it's supposed to be an override of the getClass defined on Any, but in dotty Any#getClass is polymorphic so it ends up being an overload. This is especially problematic because it means that when writing:

When typing a primitive value class or AnyVal, we ignore the getClass member: it's supposed to be an override of the getClass defined on Any, but in dotty Any#getClass is polymorphic so it ends up being an overload. This is especially problematic because it means that when writing:

1.asInstanceOf[Int & AnyRef].getClass

the getClass that returns Class[Int] defined in Int can be selected, but this call is specified to return classOf[Integer], see tests/run/t5568.scala.

FIXME: remove all the getClass methods defined in the standard library so we don't have to hot-patch it like this.

def init()(using Context): Unit

A whitelist of Scala-2 classes that are known to be pure

A whitelist of Scala-2 classes that are known to be pure

final def isCompiletime_S(sym: Symbol)(using Context): Boolean

Is an context function class.

Is an context function class.

  • ContextFunctionN for N >= 0
  • ErasedContextFunctionN for N > 0

Is tp an context function type?

Is tp an context function type?

Is an erased function class.

Is an erased function class.

  • ErasedFunctionN for N > 0
  • ErasedContextFunctionN for N > 0

Is any function class where

Is any function class where

  • FunctionXXL
  • FunctionN for N >= 0
  • ContextFunctionN for N >= 0
  • ErasedFunctionN for N > 0
  • ErasedContextFunctionN for N > 0

Is tp a representation of a (possibly dependent) function type or an alias of such?

Is tp a representation of a (possibly dependent) function type or an alias of such?

def isInfix(sym: Symbol)(using Context): Boolean

Is synthesized symbol with alphanumeric name allowed to be used as an infix operator?

Is synthesized symbol with alphanumeric name allowed to be used as an infix operator?

Is tp (an alias) of either a scala.FunctionN or a scala.ContextFunctionN instance?

Is tp (an alias) of either a scala.FunctionN or a scala.ContextFunctionN instance?

Is a function class where

Is a function class where

  • FunctionN for N >= 0 and N != XXL
def isSpecializableFunction(cls: ClassSymbol, paramTypes: List[Type], retType: Type)(using Context): Boolean
def isSpecializableFunctionSAM(paramTypes: List[Type], retType: Type)(using Context): Boolean

If the Single Abstract Method of a Function class has this type, is it specializable?

If the Single Abstract Method of a Function class has this type, is it specializable?

def isSpecializableTuple(base: Symbol, args: List[Type])(using Context): Boolean

Is a synthetic function class

Is a synthetic function class

  • FunctionN for N > 22
  • ContextFunctionN for N >= 0
  • ErasedFunctionN for N > 0
  • ErasedContextFunctionN for N > 0
def isTupleNType(tp: Type)(using Context): Boolean

Is this type a TupleN type?

Is this type a TupleN type?

Returns:

true if the dealiased type of tp is TupleN[T1, T2, ..., Tn]

def isValueSubType(tref1: TypeRef, tref2: TypeRef)(using Context): Boolean

Is either FunctionXXL or a class that will be erased to FunctionXXL

Is either FunctionXXL or a class that will be erased to FunctionXXL

  • FunctionXXL
  • FunctionN for N >= 22
  • ContextFunctionN for N >= 22

The trait FunctionN, ContextFunctionN, ErasedFunctionN or ErasedContextFunction, for some N

The trait FunctionN, ContextFunctionN, ErasedFunctionN or ErasedContextFunction, for some N

Value parameters:
name

The name of the trait to be created FunctionN traits follow this template: trait FunctionN[T0,...T{N-1}, R] extends Object { def apply($x0: T0, ..., $x{N_1}: T{N-1}): R } That is, they follow the template given for Function2..Function22 in the standard library, but without tupled and curried methods and without a toString. ContextFunctionN traits follow this template: trait ContextFunctionN[T0,...,T{N-1}, R] extends Object { def apply(using $x0: T0, ..., $x{N_1}: T{N-1}): R } ErasedFunctionN traits follow this template: trait ErasedFunctionN[T0,...,T{N-1}, R] extends Object { def apply(erased $x0: T0, ..., $x{N_1}: T{N-1}): R } ErasedContextFunctionN traits follow this template: trait ErasedContextFunctionN[T0,...,T{N-1}, R] extends Object { def apply(using erased $x0: T0, ..., $x{N_1}: T{N-1}): R } ErasedFunctionN and ErasedContextFunctionN erase to Function0.

If sym is a patched library class, the source file of its patch class, otherwise NoSource

If sym is a patched library class, the source file of its patch class, otherwise NoSource

A finalizer that patches standard library classes. It copies all non-private, non-synthetic definitions from patchCls to denot while changing their owners to denot. Before that it deletes any definitions of denot that have the same name as one of the copied definitions.

A finalizer that patches standard library classes. It copies all non-private, non-synthetic definitions from patchCls to denot while changing their owners to denot. Before that it deletes any definitions of denot that have the same name as one of the copied definitions.

If an object is present in both the original class and the patch class, it is not overwritten. Instead its members are copied recursively.

To avpid running into cycles on bootstrap, patching happens only if patchCls is read from a classfile.

Lazy references to the root imports

Lazy references to the root imports

Root types imported by default

Root types imported by default

If cls is a class in the scala package, its name, otherwise EmptyTypeName

If cls is a class in the scala package, its name, otherwise EmptyTypeName

If type ref refers to a class in the scala package, its name, otherwise EmptyTypeName

If type ref refers to a class in the scala package, its name, otherwise EmptyTypeName

def tupleType(elems: List[Type]): Type
def tupleTypes(tp: Type, bound: Int)(using Context): Option[List[Type]]
def typeTag(tp: Type)(using Context): Name

The JVM tag for tp if it's a primitive, java.lang.Object otherwise.

The JVM tag for tp if it's a primitive, java.lang.Object otherwise.

def unboxedType(tp: Type)(using Context): TypeRef

Modules whose members are in the default namespace and their module classes

Modules whose members are in the default namespace and their module classes

Concrete fields

Note: We cannot have same named methods defined in Object and Any (and AnyVal, for that matter) because after erasure the Any and AnyVal references get remapped to the Object methods which would result in a double binding assertion failure. Instead we do the following:

Note: We cannot have same named methods defined in Object and Any (and AnyVal, for that matter) because after erasure the Any and AnyVal references get remapped to the Object methods which would result in a double binding assertion failure. Instead we do the following:

  • Have some methods exist only in Any, and remap them with the Erasure denotation transformer to be owned by Object.
  • Have other methods exist only in Object. To achieve this, we synthesize all Any and Object methods; Object methods no longer get loaded from a classfile.
lazy val Any_!=: TermSymbol
lazy val Any_##: TermSymbol
lazy val Any_==: TermSymbol

def getClassA >: this.type: Class[? <: A]

def getClassA >: this.type: Class[? <: A]

lazy val ArrayType: TypeRef
lazy val Boolean_!: Symbol
lazy val Boolean_!=: Symbol
lazy val Boolean_&&: Symbol
lazy val Boolean_==: Symbol
lazy val Boolean_||: Symbol
lazy val ByteType: TypeRef
lazy val CharType: TypeRef
lazy val ConsClass: Symbol
lazy val FloatType: TypeRef

A type alias of Object used to represent any reference to Object in a Java signature, the secret sauce is that subtype checking treats it specially:

A type alias of Object used to represent any reference to Object in a Java signature, the secret sauce is that subtype checking treats it specially:

tp <:< FromJavaObject

is equivalent to:

tp <:< Any

This is useful to avoid usability problems when interacting with Java code where Object is the top type. This is safe because this type will only appear in signatures of Java definitions in positions where Object might appear, let's enumerate all possible cases this gives us:

  1. At the top level:

    // A.java void meth1(Object arg) {} void meth2(T arg) {} // T implicitly extends Object

    // B.scala meth1(1) // OK meth2(1) // OK

    This is safe even though Int is not a subtype of Object, because Erasure will detect the mismatch and box the value type.

  2. In a class type parameter:

    // A.java void meth3(scala.List arg) {} void meth4(scala.List arg) {}

    // B.scala meth3(ListInt) // OK meth4(ListInt) // OK

    At erasure, type parameters are removed and value types are boxed.

  3. As the type parameter of an array:

    // A.java void meth5(Object[] arg) {} void meth6(T[] arg) {}

    // B.scala meth5(ArrayInt) // error: Array[Int] is not a subtype of Array[Object] meth6(ArrayInt) // error: Array[Int] is not a subtype of Array[T & Object]

    This is a bit more subtle: at erasure, Arrays keep their type parameter, and primitive Arrays are not subtypes of reference Arrays on the JVM, so we can't pass an Array of Int where a reference Array is expected. Array is invariant in Scala, so meth5 is safe even if we use FromJavaObject, but generic Arrays are treated specially: we always add & Object (and here we mean the normal java.lang.Object type) to these types when they come from Java signatures (see translateJavaArrayElementType), this ensure that meth6 is safe to use.

  4. As the repeated argument of a varargs method:

    // A.java void meth7(Object... args) {} void meth8(T... args) {}

    // B.scala meth7(1) // OK (creates a reference array) meth8(1) // OK (creates a primitive array and copies it into a reference array at Erasure) val ai = ArrayInt meth7(ai: _) // OK (will copy the array at Erasure) meth8(ai: _) // OK (will copy the array at Erasure)

    Java repeated arguments are erased to arrays, so it would be safe to treat them in the same way: add an & Object to the parameter type to disallow passing primitives, but that would be very inconvenient as it is common to want to pass a primitive to an Object repeated argument (e.g. String.format("foo: %d", 1)). So instead we type them without adding the & Object and let ElimRepeated and Erasure take care of doing any necessary adaptation (note that adapting a primitive array to a reference array requires copying the whole array, so this transformation only preserves semantics if the callee does not try to mutate the varargs array which is a reasonable assumption to make).

  5. This mechanism is similar to ObjectTpeJavaRef in Scala 2, except that we create a new symbol with its own name, this is needed because this type can show up in inferred types and therefore needs to be preserved when pickling so that unpickled trees pass -Ycheck.

    Note that by default we pretty-print FromJavaObject as Object or simply omit it if it's the sole upper-bound of a type parameter, use -Yprint-debug to explicitly display it.

    lazy val Function0: Symbol
    lazy val Function1: Symbol
    lazy val Function2: Symbol
    lazy val ImplicitScrutineeTypeSym: Symbol { type ThisName = TypeName; }
    val IntEnc: Int
    lazy val IntType: TypeRef
    lazy val Int_*: Symbol
    lazy val Int_+: Symbol
    lazy val Int_-: Symbol
    lazy val Int_/: Symbol
    lazy val Int_<=: Symbol
    lazy val Int_==: Symbol
    lazy val Int_>=: Symbol
    lazy val ListClass: Symbol
    lazy val ListModule: Symbol
    lazy val LongType: TypeRef
    lazy val Long_*: Symbol
    lazy val Long_+: Symbol
    lazy val Long_/: Symbol
    lazy val NilModule: Symbol

    Classes that are known not to have an initializer irrespective of whether NoInits is set. Note: FunctionXXLClass is in this set because if it is compiled by Scala2, it does not get a NoInit flag. But since it is introduced only at erasure, there's no chance for augmentScala2Traits to do anything on a class that inherits it. So it also misses an implementation class, which means that the usual scheme of calling a superclass init in the implementation class of a Scala2 trait gets screwed up. Therefore, it is mandatory that FunctionXXL is treated as a NoInit trait.

    Classes that are known not to have an initializer irrespective of whether NoInits is set. Note: FunctionXXLClass is in this set because if it is compiled by Scala2, it does not get a NoInit flag. But since it is introduced only at erasure, there's no chance for augmentScala2Traits to do anything on a class that inherits it. So it also misses an implementation class, which means that the usual scheme of calling a superclass init in the implementation class of a Scala2 trait gets screwed up. Therefore, it is mandatory that FunctionXXL is treated as a NoInit trait.

    lazy val NoneModule: Symbol

    Class symbols for which no class exist at runtime

    Class symbols for which no class exist at runtime

    A package in which we can place all methods and types that are interpreted specially by the compiler

    A package in which we can place all methods and types that are interpreted specially by the compiler

    lazy val SeqModule: Symbol
    lazy val SeqType: TypeRef
    lazy val Seq_apply: Symbol
    lazy val Seq_drop: Symbol
    lazy val Seq_head: Symbol
    lazy val Seq_length: Symbol
    lazy val Seq_toSeq: Symbol

    Names of the root import symbols that can be hidden by other imports

    Names of the root import symbols that can be hidden by other imports

    lazy val ShortType: TypeRef

    The scala.runtime.stdLibPacthes package contains objects that contain defnitions that get added as members to standard library objects with the same name.

    The scala.runtime.stdLibPacthes package contains objects that contain defnitions that get added as members to standard library objects with the same name.

    lazy val StringOps: Symbol
    lazy val SysPackage: Symbol
    lazy val Sys_error: Symbol
    lazy val TupleType: Array[TypeRef | Null]
    lazy val Tuple_cons: Symbol
    lazy val UnitType: TypeRef
    lazy val orType: TypeSymbol

    Methods in Object and Any that do not have a side effect

    Methods in Object and Any that do not have a side effect

    Lists core methods that don't have underlying bytecode, but are synthesized on-the-fly in every reflection universe

    Lists core methods that don't have underlying bytecode, but are synthesized on-the-fly in every reflection universe

    Lists core classes that don't have underlying bytecode, but are synthesized on-the-fly in every reflection universe

    Lists core classes that don't have underlying bytecode, but are synthesized on-the-fly in every reflection universe

    Method representing a throw

    Method representing a throw

    lazy val topClasses: Set[Symbol]