Skip to content

Change/type aliases #270

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 10 commits into from
Dec 17, 2014
6 changes: 4 additions & 2 deletions src/dotty/tools/dotc/core/Constraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ object Constraint {
private val addDep: DepDelta = (_ + _)
private val removeDep: DepDelta = (_ - _)

private val NoTypeBounds = new TypeBounds(WildcardType, WildcardType){}
private val NoTypeBounds = new TypeBounds(WildcardType, WildcardType) {
override def computeHash = unsupported("computeHash")
}

/** An accumulator that changes dependencies on `param`.
* @param param The parameter to which changed dependencies refer.
Expand Down Expand Up @@ -70,7 +72,7 @@ import Constraint._
* @param dependents a map from PolyTypes to arrays of Sets of PolyParams.
* The i'th set in an array corresponding to polytype `pt` contains
* those dependent `PolyParam`s `dp` that have `PolyParam(pt, i)` in their bounds in
* significant position. A position is significant if solving the
* significant position. A position is significant if solving the
* constraint for `(pt, i)` with a type higher than its lower bound
* would lead to a constraint for `dp` that was not looser than
* the existing constraint. Specifically, it means that all poly params
Expand Down
4 changes: 2 additions & 2 deletions src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,13 @@ object Contexts {
private[core] val uniqueNamedTypes = new NamedTypeUniques

/** A table for hash consing unique type bounds */
private[core] val uniqueTypeBounds = new TypeBoundsUniques
private[core] val uniqueTypeAliases = new TypeAliasUniques

private def uniqueSets = Map(
"uniques" -> uniques,
"uniqueRefinedTypes" -> uniqueRefinedTypes,
"uniqueNamedTypes" -> uniqueNamedTypes,
"uniqueTypeBounds" -> uniqueTypeBounds)
"uniqueTypeAliases" -> uniqueTypeAliases)

/** A map that associates label and size of all uniques sets */
def uniquesSizes: Map[String, Int] = uniqueSets.mapValues(_.size)
Expand Down
40 changes: 20 additions & 20 deletions src/dotty/tools/dotc/core/Substituters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ trait Substituters { this: Context =>
tp
case tp: RefinedType =>
tp.derivedRefinedType(subst(tp.parent, from, to, theMap), tp.refinedName, subst(tp.refinedInfo, from, to, theMap))
case tp: TypeBounds if tp.lo eq tp.hi =>
tp.derivedTypeAlias(subst(tp.lo, from, to, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(subst(tp.alias, from, to, theMap))
case _ =>
(if (theMap != null) theMap else new SubstBindingMap(from, to))
.mapOver(tp)
Expand All @@ -36,8 +36,8 @@ trait Substituters { this: Context =>
tp
case tp: RefinedType =>
tp.derivedRefinedType(subst1(tp.parent, from, to, theMap), tp.refinedName, subst1(tp.refinedInfo, from, to, theMap))
case tp: TypeBounds if tp.lo eq tp.hi =>
tp.derivedTypeAlias(subst1(tp.lo, from, to, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(subst1(tp.alias, from, to, theMap))
case _ =>
(if (theMap != null) theMap else new Subst1Map(from, to))
.mapOver(tp)
Expand All @@ -56,8 +56,8 @@ trait Substituters { this: Context =>
tp
case tp: RefinedType =>
tp.derivedRefinedType(subst2(tp.parent, from1, to1, from2, to2, theMap), tp.refinedName, subst2(tp.refinedInfo, from1, to1, from2, to2, theMap))
case tp: TypeBounds if tp.lo eq tp.hi =>
tp.derivedTypeAlias(subst2(tp.lo, from1, to1, from2, to2, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(subst2(tp.alias, from1, to1, from2, to2, theMap))
case _ =>
(if (theMap != null) theMap else new Subst2Map(from1, to1, from2, to2))
.mapOver(tp)
Expand All @@ -81,8 +81,8 @@ trait Substituters { this: Context =>
tp
case tp: RefinedType =>
tp.derivedRefinedType(subst(tp.parent, from, to, theMap), tp.refinedName, subst(tp.refinedInfo, from, to, theMap))
case tp: TypeBounds if tp.lo eq tp.hi =>
tp.derivedTypeAlias(subst(tp.lo, from, to, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(subst(tp.alias, from, to, theMap))
case _ =>
(if (theMap != null) theMap else new SubstMap(from, to))
.mapOver(tp)
Expand Down Expand Up @@ -115,8 +115,8 @@ trait Substituters { this: Context =>
tp
case tp: RefinedType =>
tp.derivedRefinedType(substDealias(tp.parent, from, to, theMap), tp.refinedName, substDealias(tp.refinedInfo, from, to, theMap))
case tp: TypeBounds if tp.lo eq tp.hi =>
tp.derivedTypeAlias(substDealias(tp.lo, from, to, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(substDealias(tp.alias, from, to, theMap))
case _ =>
(if (theMap != null) theMap else new SubstDealiasMap(from, to))
.mapOver(tp)
Expand Down Expand Up @@ -154,8 +154,8 @@ trait Substituters { this: Context =>
tp
case tp: RefinedType =>
tp.derivedRefinedType(substSym(tp.parent, from, to, theMap), tp.refinedName, substSym(tp.refinedInfo, from, to, theMap))
case tp: TypeBounds if tp.lo eq tp.hi =>
tp.derivedTypeAlias(substSym(tp.lo, from, to, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(substSym(tp.alias, from, to, theMap))
case _ =>
(if (theMap != null) theMap else new SubstSymMap(from, to))
.mapOver(tp)
Expand All @@ -172,8 +172,8 @@ trait Substituters { this: Context =>
tp
case tp: RefinedType =>
tp.derivedRefinedType(substThis(tp.parent, from, to, theMap), tp.refinedName, substThis(tp.refinedInfo, from, to, theMap))
case tp: TypeBounds if tp.lo eq tp.hi =>
tp.derivedTypeAlias(substThis(tp.lo, from, to, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(substThis(tp.alias, from, to, theMap))
case _ =>
(if (theMap != null) theMap else new SubstThisMap(from, to))
.mapOver(tp)
Expand All @@ -190,8 +190,8 @@ trait Substituters { this: Context =>
tp
case tp: RefinedType =>
tp.derivedRefinedType(substThis(tp.parent, from, to, theMap), tp.refinedName, substThis(tp.refinedInfo, from, to, theMap))
case tp: TypeBounds if tp.lo eq tp.hi =>
tp.derivedTypeAlias(substThis(tp.lo, from, to, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(substThis(tp.alias, from, to, theMap))
case _ =>
(if (theMap != null) theMap else new SubstRefinedThisMap(from, to))
.mapOver(tp)
Expand All @@ -208,8 +208,8 @@ trait Substituters { this: Context =>
tp
case tp: RefinedType =>
tp.derivedRefinedType(substParam(tp.parent, from, to, theMap), tp.refinedName, substParam(tp.refinedInfo, from, to, theMap))
case tp: TypeBounds if tp.lo eq tp.hi =>
tp.derivedTypeAlias(substParam(tp.lo, from, to, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(substParam(tp.alias, from, to, theMap))
case _ =>
(if (theMap != null) theMap else new SubstParamMap(from, to))
.mapOver(tp)
Expand All @@ -226,8 +226,8 @@ trait Substituters { this: Context =>
tp
case tp: RefinedType =>
tp.derivedRefinedType(substParams(tp.parent, from, to, theMap), tp.refinedName, substParams(tp.refinedInfo, from, to, theMap))
case tp: TypeBounds if tp.lo eq tp.hi =>
tp.derivedTypeAlias(substParams(tp.lo, from, to, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(substParams(tp.alias, from, to, theMap))
case _ =>
(if (theMap != null) theMap else new SubstParamsMap(from, to))
.mapOver(tp)
Expand Down
6 changes: 3 additions & 3 deletions src/dotty/tools/dotc/core/TypeApplications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class TypeApplications(val self: Type) extends AnyVal {
case tp: RefinedType =>
val tparams = tp.parent.typeParams
tp.refinedInfo match {
case TypeBounds(lo, hi) if lo eq hi => tparams.filterNot(_.name == tp.refinedName)
case rinfo: TypeAlias => tparams.filterNot(_.name == tp.refinedName)
case _ => tparams
}
case tp: SingletonType =>
Expand Down Expand Up @@ -353,9 +353,9 @@ class TypeApplications(val self: Type) extends AnyVal {
* for a contravariant type-parameter becomes L.
*/
final def argInfo(tparam: Symbol, interpolate: Boolean = true)(implicit ctx: Context): Type = self match {
case self: TypeAlias => self.alias
case TypeBounds(lo, hi) =>
if (lo eq hi) hi
else if (interpolate) {
if (interpolate) {
val v = tparam.variance
if (v > 0 && (lo isRef defn.NothingClass)) hi
else if (v < 0 && (hi isRef defn.AnyClass)) lo
Expand Down
4 changes: 2 additions & 2 deletions src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,8 @@ class TypeComparer(initctx: Context) extends DotClass {
{ // special case for situations like:
// foo <: C { type T = foo.T }
tp2.refinedInfo match {
case TypeBounds(lo, hi) if lo eq hi =>
!ctx.phase.erasedTypes && (tp1r select name) =:= lo
case rinfo: TypeAlias =>
!ctx.phase.erasedTypes && (tp1r select name) =:= rinfo.alias
case _ => false
}
})
Expand Down
13 changes: 7 additions & 6 deletions src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ trait TypeOps { this: Context =>
asSeenFrom(tp.parent, pre, cls, theMap),
tp.refinedName,
asSeenFrom(tp.refinedInfo, pre, cls, theMap))
case tp: TypeBounds if tp.lo eq tp.hi =>
tp.derivedTypeAlias(asSeenFrom(tp.lo, pre, cls, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(asSeenFrom(tp.alias, pre, cls, theMap))
case _ =>
(if (theMap != null) theMap else new AsSeenFromMap(pre, cls))
.mapOver(tp)
Expand Down Expand Up @@ -71,8 +71,8 @@ trait TypeOps { this: Context =>
tp
case tp: RefinedType =>
tp.derivedRefinedType(simplify(tp.parent, theMap), tp.refinedName, simplify(tp.refinedInfo, theMap))
case tp: TypeBounds if tp.lo eq tp.hi =>
tp.derivedTypeAlias(simplify(tp.lo, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(simplify(tp.alias, theMap))
case AndType(l, r) =>
simplify(l, theMap) & simplify(r, theMap)
case OrType(l, r) =>
Expand Down Expand Up @@ -142,9 +142,10 @@ trait TypeOps { this: Context =>
def needsChecking(tp: Type, isPart: Boolean): Boolean = tp match {
case tp: TypeRef =>
tp.info match {
case TypeAlias(alias) =>
needsChecking(alias, isPart)
case TypeBounds(lo, hi) =>
if (lo eq hi) needsChecking(hi, isPart)
else isPart || tp.controlled(isVolatile(hi))
isPart || tp.controlled(isVolatile(hi))
case _ => false
}
case tp: RefinedType =>
Expand Down
Loading