From a02ce561ca7078414141dbb326ea235af2e80e4b Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Wed, 18 Mar 2015 23:55:38 +0100 Subject: Cache the instantiations of ErasedValueType This reduces the number of objects created and speeds up subtyping tests Also make ErasedValueType extend ValueType --- src/dotty/tools/dotc/core/TypeErasure.scala | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/dotty/tools/dotc/core/TypeErasure.scala') 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) = -- cgit v1.2.3