Skip to content

Commit 3a68e50

Browse files
committed
Merge pull request #270 from dotty-staging/change/type-aliases
Change/type aliases
2 parents ca03148 + 7c1e76d commit 3a68e50

File tree

11 files changed

+144
-147
lines changed

11 files changed

+144
-147
lines changed

src/dotty/tools/dotc/core/Constraint.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ object Constraint {
2424
private val addDep: DepDelta = (_ + _)
2525
private val removeDep: DepDelta = (_ - _)
2626

27-
private val NoTypeBounds = new TypeBounds(WildcardType, WildcardType){}
27+
private val NoTypeBounds = new TypeBounds(WildcardType, WildcardType) {
28+
override def computeHash = unsupported("computeHash")
29+
}
2830

2931
/** An accumulator that changes dependencies on `param`.
3032
* @param param The parameter to which changed dependencies refer.
@@ -70,7 +72,7 @@ import Constraint._
7072
* @param dependents a map from PolyTypes to arrays of Sets of PolyParams.
7173
* The i'th set in an array corresponding to polytype `pt` contains
7274
* those dependent `PolyParam`s `dp` that have `PolyParam(pt, i)` in their bounds in
73-
* significant position. A position is significant if solving the
75+
* significant position. A position is significant if solving the
7476
* constraint for `(pt, i)` with a type higher than its lower bound
7577
* would lead to a constraint for `dp` that was not looser than
7678
* the existing constraint. Specifically, it means that all poly params

src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,13 +528,13 @@ object Contexts {
528528
private[core] val uniqueNamedTypes = new NamedTypeUniques
529529

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

533533
private def uniqueSets = Map(
534534
"uniques" -> uniques,
535535
"uniqueRefinedTypes" -> uniqueRefinedTypes,
536536
"uniqueNamedTypes" -> uniqueNamedTypes,
537-
"uniqueTypeBounds" -> uniqueTypeBounds)
537+
"uniqueTypeAliases" -> uniqueTypeAliases)
538538

539539
/** A map that associates label and size of all uniques sets */
540540
def uniquesSizes: Map[String, Int] = uniqueSets.mapValues(_.size)

src/dotty/tools/dotc/core/Substituters.scala

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ trait Substituters { this: Context =>
1818
tp
1919
case tp: RefinedType =>
2020
tp.derivedRefinedType(subst(tp.parent, from, to, theMap), tp.refinedName, subst(tp.refinedInfo, from, to, theMap))
21-
case tp: TypeBounds if tp.lo eq tp.hi =>
22-
tp.derivedTypeAlias(subst(tp.lo, from, to, theMap))
21+
case tp: TypeAlias =>
22+
tp.derivedTypeAlias(subst(tp.alias, from, to, theMap))
2323
case _ =>
2424
(if (theMap != null) theMap else new SubstBindingMap(from, to))
2525
.mapOver(tp)
@@ -36,8 +36,8 @@ trait Substituters { this: Context =>
3636
tp
3737
case tp: RefinedType =>
3838
tp.derivedRefinedType(subst1(tp.parent, from, to, theMap), tp.refinedName, subst1(tp.refinedInfo, from, to, theMap))
39-
case tp: TypeBounds if tp.lo eq tp.hi =>
40-
tp.derivedTypeAlias(subst1(tp.lo, from, to, theMap))
39+
case tp: TypeAlias =>
40+
tp.derivedTypeAlias(subst1(tp.alias, from, to, theMap))
4141
case _ =>
4242
(if (theMap != null) theMap else new Subst1Map(from, to))
4343
.mapOver(tp)
@@ -56,8 +56,8 @@ trait Substituters { this: Context =>
5656
tp
5757
case tp: RefinedType =>
5858
tp.derivedRefinedType(subst2(tp.parent, from1, to1, from2, to2, theMap), tp.refinedName, subst2(tp.refinedInfo, from1, to1, from2, to2, theMap))
59-
case tp: TypeBounds if tp.lo eq tp.hi =>
60-
tp.derivedTypeAlias(subst2(tp.lo, from1, to1, from2, to2, theMap))
59+
case tp: TypeAlias =>
60+
tp.derivedTypeAlias(subst2(tp.alias, from1, to1, from2, to2, theMap))
6161
case _ =>
6262
(if (theMap != null) theMap else new Subst2Map(from1, to1, from2, to2))
6363
.mapOver(tp)
@@ -81,8 +81,8 @@ trait Substituters { this: Context =>
8181
tp
8282
case tp: RefinedType =>
8383
tp.derivedRefinedType(subst(tp.parent, from, to, theMap), tp.refinedName, subst(tp.refinedInfo, from, to, theMap))
84-
case tp: TypeBounds if tp.lo eq tp.hi =>
85-
tp.derivedTypeAlias(subst(tp.lo, from, to, theMap))
84+
case tp: TypeAlias =>
85+
tp.derivedTypeAlias(subst(tp.alias, from, to, theMap))
8686
case _ =>
8787
(if (theMap != null) theMap else new SubstMap(from, to))
8888
.mapOver(tp)
@@ -115,8 +115,8 @@ trait Substituters { this: Context =>
115115
tp
116116
case tp: RefinedType =>
117117
tp.derivedRefinedType(substDealias(tp.parent, from, to, theMap), tp.refinedName, substDealias(tp.refinedInfo, from, to, theMap))
118-
case tp: TypeBounds if tp.lo eq tp.hi =>
119-
tp.derivedTypeAlias(substDealias(tp.lo, from, to, theMap))
118+
case tp: TypeAlias =>
119+
tp.derivedTypeAlias(substDealias(tp.alias, from, to, theMap))
120120
case _ =>
121121
(if (theMap != null) theMap else new SubstDealiasMap(from, to))
122122
.mapOver(tp)
@@ -154,8 +154,8 @@ trait Substituters { this: Context =>
154154
tp
155155
case tp: RefinedType =>
156156
tp.derivedRefinedType(substSym(tp.parent, from, to, theMap), tp.refinedName, substSym(tp.refinedInfo, from, to, theMap))
157-
case tp: TypeBounds if tp.lo eq tp.hi =>
158-
tp.derivedTypeAlias(substSym(tp.lo, from, to, theMap))
157+
case tp: TypeAlias =>
158+
tp.derivedTypeAlias(substSym(tp.alias, from, to, theMap))
159159
case _ =>
160160
(if (theMap != null) theMap else new SubstSymMap(from, to))
161161
.mapOver(tp)
@@ -172,8 +172,8 @@ trait Substituters { this: Context =>
172172
tp
173173
case tp: RefinedType =>
174174
tp.derivedRefinedType(substThis(tp.parent, from, to, theMap), tp.refinedName, substThis(tp.refinedInfo, from, to, theMap))
175-
case tp: TypeBounds if tp.lo eq tp.hi =>
176-
tp.derivedTypeAlias(substThis(tp.lo, from, to, theMap))
175+
case tp: TypeAlias =>
176+
tp.derivedTypeAlias(substThis(tp.alias, from, to, theMap))
177177
case _ =>
178178
(if (theMap != null) theMap else new SubstThisMap(from, to))
179179
.mapOver(tp)
@@ -190,8 +190,8 @@ trait Substituters { this: Context =>
190190
tp
191191
case tp: RefinedType =>
192192
tp.derivedRefinedType(substThis(tp.parent, from, to, theMap), tp.refinedName, substThis(tp.refinedInfo, from, to, theMap))
193-
case tp: TypeBounds if tp.lo eq tp.hi =>
194-
tp.derivedTypeAlias(substThis(tp.lo, from, to, theMap))
193+
case tp: TypeAlias =>
194+
tp.derivedTypeAlias(substThis(tp.alias, from, to, theMap))
195195
case _ =>
196196
(if (theMap != null) theMap else new SubstRefinedThisMap(from, to))
197197
.mapOver(tp)
@@ -208,8 +208,8 @@ trait Substituters { this: Context =>
208208
tp
209209
case tp: RefinedType =>
210210
tp.derivedRefinedType(substParam(tp.parent, from, to, theMap), tp.refinedName, substParam(tp.refinedInfo, from, to, theMap))
211-
case tp: TypeBounds if tp.lo eq tp.hi =>
212-
tp.derivedTypeAlias(substParam(tp.lo, from, to, theMap))
211+
case tp: TypeAlias =>
212+
tp.derivedTypeAlias(substParam(tp.alias, from, to, theMap))
213213
case _ =>
214214
(if (theMap != null) theMap else new SubstParamMap(from, to))
215215
.mapOver(tp)
@@ -226,8 +226,8 @@ trait Substituters { this: Context =>
226226
tp
227227
case tp: RefinedType =>
228228
tp.derivedRefinedType(substParams(tp.parent, from, to, theMap), tp.refinedName, substParams(tp.refinedInfo, from, to, theMap))
229-
case tp: TypeBounds if tp.lo eq tp.hi =>
230-
tp.derivedTypeAlias(substParams(tp.lo, from, to, theMap))
229+
case tp: TypeAlias =>
230+
tp.derivedTypeAlias(substParams(tp.alias, from, to, theMap))
231231
case _ =>
232232
(if (theMap != null) theMap else new SubstParamsMap(from, to))
233233
.mapOver(tp)

src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class TypeApplications(val self: Type) extends AnyVal {
6262
case tp: RefinedType =>
6363
val tparams = tp.parent.typeParams
6464
tp.refinedInfo match {
65-
case TypeBounds(lo, hi) if lo eq hi => tparams.filterNot(_.name == tp.refinedName)
65+
case rinfo: TypeAlias => tparams.filterNot(_.name == tp.refinedName)
6666
case _ => tparams
6767
}
6868
case tp: SingletonType =>
@@ -353,9 +353,9 @@ class TypeApplications(val self: Type) extends AnyVal {
353353
* for a contravariant type-parameter becomes L.
354354
*/
355355
final def argInfo(tparam: Symbol, interpolate: Boolean = true)(implicit ctx: Context): Type = self match {
356+
case self: TypeAlias => self.alias
356357
case TypeBounds(lo, hi) =>
357-
if (lo eq hi) hi
358-
else if (interpolate) {
358+
if (interpolate) {
359359
val v = tparam.variance
360360
if (v > 0 && (lo isRef defn.NothingClass)) hi
361361
else if (v < 0 && (hi isRef defn.AnyClass)) lo

src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,8 @@ class TypeComparer(initctx: Context) extends DotClass {
667667
{ // special case for situations like:
668668
// foo <: C { type T = foo.T }
669669
tp2.refinedInfo match {
670-
case TypeBounds(lo, hi) if lo eq hi =>
671-
!ctx.phase.erasedTypes && (tp1r select name) =:= lo
670+
case rinfo: TypeAlias =>
671+
!ctx.phase.erasedTypes && (tp1r select name) =:= rinfo.alias
672672
case _ => false
673673
}
674674
})

src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ trait TypeOps { this: Context =>
4343
asSeenFrom(tp.parent, pre, cls, theMap),
4444
tp.refinedName,
4545
asSeenFrom(tp.refinedInfo, pre, cls, theMap))
46-
case tp: TypeBounds if tp.lo eq tp.hi =>
47-
tp.derivedTypeAlias(asSeenFrom(tp.lo, pre, cls, theMap))
46+
case tp: TypeAlias =>
47+
tp.derivedTypeAlias(asSeenFrom(tp.alias, pre, cls, theMap))
4848
case _ =>
4949
(if (theMap != null) theMap else new AsSeenFromMap(pre, cls))
5050
.mapOver(tp)
@@ -73,8 +73,8 @@ trait TypeOps { this: Context =>
7373
tp
7474
case tp: RefinedType =>
7575
tp.derivedRefinedType(simplify(tp.parent, theMap), tp.refinedName, simplify(tp.refinedInfo, theMap))
76-
case tp: TypeBounds if tp.lo eq tp.hi =>
77-
tp.derivedTypeAlias(simplify(tp.lo, theMap))
76+
case tp: TypeAlias =>
77+
tp.derivedTypeAlias(simplify(tp.alias, theMap))
7878
case AndType(l, r) =>
7979
simplify(l, theMap) & simplify(r, theMap)
8080
case OrType(l, r) =>
@@ -144,9 +144,10 @@ trait TypeOps { this: Context =>
144144
def needsChecking(tp: Type, isPart: Boolean): Boolean = tp match {
145145
case tp: TypeRef =>
146146
tp.info match {
147+
case TypeAlias(alias) =>
148+
needsChecking(alias, isPart)
147149
case TypeBounds(lo, hi) =>
148-
if (lo eq hi) needsChecking(hi, isPart)
149-
else isPart || tp.controlled(isVolatile(hi))
150+
isPart || tp.controlled(isVolatile(hi))
150151
case _ => false
151152
}
152153
case tp: RefinedType =>

0 commit comments

Comments
 (0)