Skip to content

Commit fb06073

Browse files
committed
Merge pull request scala#2624 from paulp/pr/revert-14534c693d
Revert "SI-7517 type constructors too eagerly normalized."
2 parents a049777 + 278305a commit fb06073

File tree

11 files changed

+31
-126
lines changed

11 files changed

+31
-126
lines changed

src/reflect/scala/reflect/internal/Types.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,7 +3222,7 @@ trait Types
32223222
if (constr.instValid) constr.inst
32233223
// get here when checking higher-order subtyping of the typevar by itself
32243224
// TODO: check whether this ever happens?
3225-
else if (isHigherKinded) logResult(s"Normalizing HK $this")(typeFun(params, applyArgs(params map (_.typeConstructor))))
3225+
else if (isHigherKinded) logResult("Normalizing HK $this")(typeFun(params, applyArgs(params map (_.typeConstructor))))
32263226
else super.normalize
32273227
)
32283228
override def typeSymbol = origin.typeSymbol
@@ -3649,7 +3649,7 @@ trait Types
36493649
def existentialAbstraction(tparams: List[Symbol], tpe0: Type): Type =
36503650
if (tparams.isEmpty) tpe0
36513651
else {
3652-
val tpe = tpe0 map (_.dealias)
3652+
val tpe = normalizeAliases(tpe0)
36533653
val tpe1 = new ExistentialExtrapolation(tparams) extrapolate tpe
36543654
var tparams0 = tparams
36553655
var tparams1 = tparams0 filter tpe1.contains

src/reflect/scala/reflect/internal/tpe/GlbLubs.scala

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ private[internal] trait GlbLubs {
8080
var lubListDepth = 0
8181
// This catches some recursive situations which would otherwise
8282
// befuddle us, e.g. pos/hklub0.scala
83-
def isHotForTs(xs: List[Type]) = ts exists (_.typeParams == xs.map(_.typeSymbolDirect))
83+
def isHotForTs(xs: List[Type]) = ts exists (_.typeParams == xs.map(_.typeSymbol))
8484

8585
def elimHigherOrderTypeParam(tp: Type) = tp match {
8686
case TypeRef(_, _, args) if args.nonEmpty && isHotForTs(args) =>
87-
logResult(s"Retracting dummies from $tp in lublist")(tp.typeConstructor)
87+
logResult("Retracting dummies from " + tp + " in lublist")(tp.typeConstructor)
8888
case _ => tp
8989
}
9090
// pretypes is a tail-recursion-preserving accumulator.
@@ -101,7 +101,7 @@ private[internal] trait GlbLubs {
101101

102102
// Is the frontier made up of types with the same symbol?
103103
val isUniformFrontier = (ts0: @unchecked) match {
104-
case t :: ts => ts forall (_.typeSymbolDirect == t.typeSymbolDirect)
104+
case t :: ts => ts forall (_.typeSymbol == t.typeSymbol)
105105
}
106106

107107
// Produce a single type for this frontier by merging the prefixes and arguments of those
@@ -112,11 +112,11 @@ private[internal] trait GlbLubs {
112112
if (isUniformFrontier) {
113113
val fbounds = findRecursiveBounds(ts0) map (_._2)
114114
val tcLubList = typeConstructorLubList(ts0)
115-
def isRecursive(tp: Type) = tp.typeSymbolDirect.typeParams exists fbounds.contains
115+
def isRecursive(tp: Type) = tp.typeSymbol.typeParams exists fbounds.contains
116116

117117
val ts1 = ts0 map { t =>
118118
if (isRecursive(t)) {
119-
tcLubList map (t baseType _.typeSymbolDirect) find (t => !isRecursive(t)) match {
119+
tcLubList map (t baseType _.typeSymbol) find (t => !isRecursive(t)) match {
120120
case Some(tp) => logResult(s"Breaking recursion in lublist, substituting weaker type.\n Was: $t\n Now")(tp)
121121
case _ => t
122122
}
@@ -133,7 +133,7 @@ private[internal] trait GlbLubs {
133133
// frontier is not uniform yet, move it beyond the current minimal symbol;
134134
// lather, rinSe, repeat
135135
val sym = minSym(ts0)
136-
val newtps = tsBts map (ts => if (ts.head.typeSymbolDirect == sym) ts.tail else ts)
136+
val newtps = tsBts map (ts => if (ts.head.typeSymbol == sym) ts.tail else ts)
137137
if (printLubs) {
138138
val str = (newtps.zipWithIndex map { case (tps, idx) =>
139139
tps.map(" " + _ + "\n").mkString(" (" + idx + ")\n", "", "\n")
@@ -157,7 +157,9 @@ private[internal] trait GlbLubs {
157157

158158
/** The minimal symbol of a list of types (as determined by `Symbol.isLess`). */
159159
private def minSym(tps: List[Type]): Symbol =
160-
tps.iterator map (_.typeSymbolDirect) reduceLeft ((x, y) => if (x isLess y) x else y)
160+
(tps.head.typeSymbol /: tps.tail) {
161+
(sym1, tp2) => if (tp2.typeSymbol isLess sym1) tp2.typeSymbol else sym1
162+
}
161163

162164
/** A minimal type list which has a given list of types as its base type sequence */
163165
def spanningTypes(ts: List[Type]): List[Type] = ts match {

src/reflect/scala/reflect/internal/tpe/TypeMaps.scala

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ private[internal] trait TypeMaps {
1212
self: SymbolTable =>
1313
import definitions._
1414

15+
/** Normalize any type aliases within this type (@see Type#normalize).
16+
* Note that this depends very much on the call to "normalize", not "dealias",
17+
* so it is no longer carries the too-stealthy name "deAlias".
18+
*/
19+
object normalizeAliases extends TypeMap {
20+
def apply(tp: Type): Type = tp match {
21+
case TypeRef(_, sym, _) if sym.isAliasType =>
22+
def msg = if (tp.isHigherKinded) s"Normalizing type alias function $tp" else s"Dealiasing type alias $tp"
23+
mapOver(logResult(msg)(tp.normalize))
24+
case _ => mapOver(tp)
25+
}
26+
}
27+
1528
/** Remove any occurrence of type <singleton> from this type and its parents */
1629
object dropSingletonType extends TypeMap {
1730
def apply(tp: Type): Type = {
@@ -376,7 +389,7 @@ private[internal] trait TypeMaps {
376389
case TypeRef(pre, sym, args) if tparams contains sym =>
377390
val repl = if (variance.isPositive) dropSingletonType(tp1.bounds.hi) else tp1.bounds.lo
378391
val count = occurCount(sym)
379-
val containsTypeParam = tparams exists repl.contains
392+
val containsTypeParam = tparams exists (repl contains _)
380393
def msg = {
381394
val word = if (variance.isPositive) "upper" else "lower"
382395
s"Widened lone occurrence of $tp1 inside existential to $word bound"

test/files/neg/t2994a.check

Lines changed: 0 additions & 7 deletions
This file was deleted.

test/files/neg/t2994a.scala

Lines changed: 0 additions & 27 deletions
This file was deleted.

test/files/pos/t2994a.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ object Naturals {
1717
type _5 = SUCC[_4]
1818
type _6 = SUCC[_5]
1919

20-
// crashes scala-2.8.0 beta1
20+
21+
// crashes scala-2.8.0 beta1
2122
trait MUL[n <: NAT, m <: NAT] extends NAT {
22-
trait curry[ n[ m[x1 <: NAT], x2 <: NAT], s[x3 <: NAT] ] { type f[z <: NAT] = n[s, z] }
23+
trait curry[n[_[_], _], s[_]] { type f[z <: NAT] = n[s, z] }
2324
type a[s[_ <: NAT] <: NAT, z <: NAT] = n#a[curry[m#a, s]#f, z]
2425
}
25-
}
26+
27+
}

test/files/pos/t2994c.scala

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/files/pos/t7517.scala

Lines changed: 0 additions & 22 deletions
This file was deleted.

test/files/run/t6113.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Foo[AnyRef{type l[X] = (Int, X)}#l]
1+
Foo[[X](Int, X)]

test/pending/neg/t2994b.scala

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)