Skip to content

Make erased value type take a TypeRef instead of a ClassSymbol #1199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
case OrType(tp21, tp22) =>
if (tp21.stripTypeVar eq tp22.stripTypeVar) isSubType(tp1, tp21)
else secondTry(tp1, tp2)
case TypeErasure.ErasedValueType(cls2, underlying2) =>
case TypeErasure.ErasedValueType(tycon1, underlying2) =>
def compareErasedValueType = tp1 match {
case TypeErasure.ErasedValueType(cls1, underlying1) =>
(cls1 eq cls2) && isSameType(underlying1, underlying2)
case TypeErasure.ErasedValueType(tycon2, underlying1) =>
(tycon1.symbol eq tycon2.symbol) && isSameType(underlying1, underlying2)
case _ =>
secondTry(tp1, tp2)
}
Expand Down
16 changes: 8 additions & 8 deletions src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ object TypeErasure {
* Nothing. This is because this type is only useful for type adaptation (see
* [[Erasure.Boxing#adaptToType]]).
*
* @param cls The value class symbol
* @param tycon A TypeRef referring to 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)
abstract case class ErasedValueType(tycon: TypeRef, erasedUnderlying: Type)
extends CachedGroundType with ValueType {
override def computeHash = doHash(cls, erasedUnderlying)
override def computeHash = doHash(tycon, erasedUnderlying)
}

final class CachedErasedValueType(cls: ClassSymbol, erasedUnderlying: Type)
extends ErasedValueType(cls, erasedUnderlying)
final class CachedErasedValueType(tycon: TypeRef, erasedUnderlying: Type)
extends ErasedValueType(tycon, erasedUnderlying)

object ErasedValueType {
def apply(cls: ClassSymbol, erasedUnderlying: Type)(implicit ctx: Context) = {
unique(new CachedErasedValueType(cls, erasedUnderlying))
def apply(tycon: TypeRef, erasedUnderlying: Type)(implicit ctx: Context) = {
unique(new CachedErasedValueType(tycon, erasedUnderlying))
}
}

Expand Down Expand Up @@ -411,7 +411,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
private def eraseDerivedValueClassRef(tref: TypeRef)(implicit ctx: Context): Type = {
val cls = tref.symbol.asClass
val underlying = underlyingOfValueClass(cls)
if (underlying.exists) ErasedValueType(cls, valueErasure(underlying))
if (underlying.exists) ErasedValueType(tref, valueErasure(underlying))
else NoType
}

Expand Down
4 changes: 2 additions & 2 deletions src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
return toText(tp.info)
case ExprType(result) =>
return "=> " ~ toText(result)
case ErasedValueType(clazz, underlying) =>
return "ErasedValueType(" ~ toText(clazz.typeRef) ~ ", " ~ toText(underlying) ~ ")"
case ErasedValueType(tycon, underlying) =>
return "ErasedValueType(" ~ toText(tycon) ~ ", " ~ toText(underlying) ~ ")"
case tp: ClassInfo =>
return toTextParents(tp.parentsWithArgs) ~ "{...}"
case JavaArrayType(elemtp) =>
Expand Down
20 changes: 10 additions & 10 deletions src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ object Erasure extends TypeTestsCasts{

final def box(tree: Tree, target: => String = "")(implicit ctx: Context): Tree = ctx.traceIndented(i"boxing ${tree.showSummary}: ${tree.tpe} into $target") {
tree.tpe.widen match {
case ErasedValueType(clazz, _) =>
New(clazz.typeRef, cast(tree, underlyingOfValueClass(clazz)) :: Nil) // todo: use adaptToType?
case ErasedValueType(tycon, _) =>
New(tycon, cast(tree, underlyingOfValueClass(tycon.symbol.asClass)) :: Nil) // todo: use adaptToType?
case tp =>
val cls = tp.classSymbol
if (cls eq defn.UnitClass) constant(tree, ref(defn.BoxedUnit_UNIT))
Expand All @@ -173,10 +173,10 @@ object Erasure extends TypeTestsCasts{

def unbox(tree: Tree, pt: Type)(implicit ctx: Context): Tree = ctx.traceIndented(i"unboxing ${tree.showSummary}: ${tree.tpe} as a $pt") {
pt match {
case ErasedValueType(clazz, underlying) =>
case ErasedValueType(tycon, underlying) =>
def unboxedTree(t: Tree) =
adaptToType(t, clazz.typeRef)
.select(valueClassUnbox(clazz))
adaptToType(t, tycon)
.select(valueClassUnbox(tycon.symbol.asClass))
.appliedToNone

// Null unboxing needs to be treated separately since we cannot call a method on null.
Expand All @@ -185,7 +185,7 @@ object Erasure extends TypeTestsCasts{
val tree1 =
if (tree.tpe isRef defn.NullClass)
adaptToType(tree, underlying)
else if (!(tree.tpe <:< clazz.typeRef)) {
else if (!(tree.tpe <:< tycon)) {
assert(!(tree.tpe.typeSymbol.isPrimitiveValueClass))
val nullTree = Literal(Constant(null))
val unboxedNull = adaptToType(nullTree, underlying)
Expand Down Expand Up @@ -223,12 +223,12 @@ object Erasure extends TypeTestsCasts{
if treeElem.widen.isPrimitiveValueType && !ptElem.isPrimitiveValueType =>
// See SI-2386 for one example of when this might be necessary.
cast(ref(defn.runtimeMethodRef(nme.toObjectArray)).appliedTo(tree), pt)
case (_, ErasedValueType(cls, _)) =>
ref(u2evt(cls)).appliedTo(tree)
case (_, ErasedValueType(tycon, _)) =>
ref(u2evt(tycon.symbol.asClass)).appliedTo(tree)
case _ =>
tree.tpe.widen match {
case ErasedValueType(cls, _) =>
ref(evt2u(cls)).appliedTo(tree)
case ErasedValueType(tycon, _) =>
ref(evt2u(tycon.symbol.asClass)).appliedTo(tree)
case _ =>
if (pt.isPrimitiveValueType)
primitiveConversion(tree, pt.classSymbol)
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/transform/ExtensionMethods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ExtensionMethods extends MiniPhaseTransform with DenotTransformer with Ful
}

val underlying = valueErasure(underlyingOfValueClass(valueClass))
val evt = ErasedValueType(valueClass, underlying)
val evt = ErasedValueType(valueClass.typeRef, underlying)
val u2evtSym = ctx.newSymbol(moduleSym, nme.U2EVT, Synthetic | Method,
MethodType(List(nme.x_0), List(underlying), evt))
val evt2uSym = ctx.newSymbol(moduleSym, nme.EVT2U, Synthetic | Method,
Expand Down