aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/TypeErasure.scala
diff options
context:
space:
mode:
authorGuillaume Martres <smarter@ubuntu.com>2015-03-18 23:55:38 +0100
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2015-05-01 13:26:22 +0200
commita02ce561ca7078414141dbb326ea235af2e80e4b (patch)
tree5015e83ffb27cc18e84df3fa965be7fdade2d6f4 /src/dotty/tools/dotc/core/TypeErasure.scala
parent926d48e91fafc54d5f82f892c01a7f95bca3ff61 (diff)
downloaddotty-a02ce561ca7078414141dbb326ea235af2e80e4b.tar.gz
dotty-a02ce561ca7078414141dbb326ea235af2e80e4b.tar.bz2
dotty-a02ce561ca7078414141dbb326ea235af2e80e4b.zip
Cache the instantiations of ErasedValueType
This reduces the number of objects created and speeds up subtyping tests Also make ErasedValueType extend ValueType
Diffstat (limited to 'src/dotty/tools/dotc/core/TypeErasure.scala')
-rw-r--r--src/dotty/tools/dotc/core/TypeErasure.scala27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/core/TypeErasure.scala b/src/dotty/tools/dotc/core/TypeErasure.scala
index 6a8d22bf9..56b50c74a 100644
--- a/src/dotty/tools/dotc/core/TypeErasure.scala
+++ b/src/dotty/tools/dotc/core/TypeErasure.scala
@@ -3,6 +3,7 @@ package dotc
package core
import Symbols._, Types._, Contexts._, Flags._, Names._, StdNames._, Decorators._, Flags.JavaDefined
+import Uniques.unique
import dotc.transform.ExplicitOuter._
import typer.Mode
import util.DotClass
@@ -51,8 +52,30 @@ object TypeErasure {
false
}
- case class ErasedValueType(cls: ClassSymbol, underlying: Type) extends CachedGroundType {
- override def computeHash = doHash(cls, underlying)
+ /** A type representing the semi-erasure of a derived value class, see SIP-15
+ * where it's called "C$unboxed" for a class C.
+ * Derived value classes are erased to this type during Erasure (when
+ * semiEraseVCs = true) and subsequently erased to their underlying type
+ * during ElimErasedValueType. This type is outside the normal Scala class
+ * hierarchy: it is a subtype of no other type and is a supertype only of
+ * Nothing. This is because this type is only useful for type adaptation (see
+ * [[Erasure.Boxing#adaptToType]]).
+ *
+ * @param cls The value class symbol
+ * @param erasedUnderlying The erased type of the single field of the value class
+ */
+ abstract case class ErasedValueType(cls: ClassSymbol, erasedUnderlying: Type)
+ extends CachedGroundType with ValueType {
+ override def computeHash = doHash(cls, erasedUnderlying)
+ }
+
+ final class CachedErasedValueType(cls: ClassSymbol, erasedUnderlying: Type)
+ extends ErasedValueType(cls, erasedUnderlying)
+
+ object ErasedValueType {
+ def apply(cls: ClassSymbol, erasedUnderlying: Type)(implicit ctx: Context) = {
+ unique(new CachedErasedValueType(cls, erasedUnderlying))
+ }
}
private def erasureIdx(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean, wildcardOK: Boolean) =