A class defining symbols and types of standard definitions
- Companion:
- object
Type members
Classlikes
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.
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)
Types
Value members
Concrete methods
The enumeration type, goven a value of the enumeration
The enumeration type, goven a value of the enumeration
If it is BoxedUnit, remove java.io.Serializable
from parents
.
If it is BoxedUnit, remove java.io.Serializable
from parents
.
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
The type of the boxed class corresponding to primitive value type tp
.
The type of the boxed class corresponding to primitive value type tp
.
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.
A whitelist of Scala-2 classes that are known to be pure
A whitelist of Scala-2 classes that are known to be pure
Is an context function class.
Is an context function class.
- ContextFunctionN for N >= 0
- ErasedContextFunctionN for N > 0
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?
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?
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?
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
Is this type a TupleN
type?
Is this type a TupleN
type?
- Returns:
true if the dealiased type of
tp
isTupleN[T1, T2, ..., Tn]
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
andcurried
methods and without atoString
. 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.
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
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.
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.
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:
-
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.
-
In a class type parameter:
// A.java void meth3(scala.List
// B.scala meth3(ListInt) // OK meth4(ListInt) // OK
At erasure, type parameters are removed and value types are boxed.
-
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 useFromJavaObject
, 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 (seetranslateJavaArrayElementType
), this ensure thatmeth6
is safe to use. -
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 letElimRepeated
andErasure
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).
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.
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.
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
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
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.
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