summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-06-03 21:23:30 -0700
committerPaul Phillips <paulp@improving.org>2013-06-03 21:23:30 -0700
commit278305a7f60c46515c2133d11f7c561e972ef705 (patch)
tree12062d7a8fce298bc5bbdb7b83fe8c930d18282b
parenta04977736c007fc7976c10c7fa5c74ae67902b92 (diff)
downloadscala-278305a7f60c46515c2133d11f7c561e972ef705.tar.gz
scala-278305a7f60c46515c2133d11f7c561e972ef705.tar.bz2
scala-278305a7f60c46515c2133d11f7c561e972ef705.zip
Revert "SI-7517 type constructors too eagerly normalized."
This reverts commit 14534c693d2eb6acafaf8244c14b5643388fbd67. It turns out this approach was breaking the working variations in the submitted test case even as it was unbreaking the unworking one, but I never managed to uncomment them. Fortunately retronym's test case was not so lackadaisical.
-rw-r--r--src/reflect/scala/reflect/internal/Types.scala4
-rw-r--r--src/reflect/scala/reflect/internal/tpe/GlbLubs.scala16
-rw-r--r--src/reflect/scala/reflect/internal/tpe/TypeMaps.scala15
-rw-r--r--test/files/neg/t2994a.check7
-rw-r--r--test/files/neg/t2994a.scala27
-rw-r--r--test/files/pos/t2994a.scala8
-rw-r--r--test/files/pos/t2994c.scala8
-rw-r--r--test/files/pos/t7517.scala22
-rw-r--r--test/files/run/t6113.check2
-rw-r--r--test/pending/neg/t2994b.scala8
-rw-r--r--test/pending/pos/lubbing-aliases.scala40
11 files changed, 31 insertions, 126 deletions
diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala
index dfb8632968..00a929003e 100644
--- a/src/reflect/scala/reflect/internal/Types.scala
+++ b/src/reflect/scala/reflect/internal/Types.scala
@@ -3222,7 +3222,7 @@ trait Types
if (constr.instValid) constr.inst
// get here when checking higher-order subtyping of the typevar by itself
// TODO: check whether this ever happens?
- else if (isHigherKinded) logResult(s"Normalizing HK $this")(typeFun(params, applyArgs(params map (_.typeConstructor))))
+ else if (isHigherKinded) logResult("Normalizing HK $this")(typeFun(params, applyArgs(params map (_.typeConstructor))))
else super.normalize
)
override def typeSymbol = origin.typeSymbol
@@ -3649,7 +3649,7 @@ trait Types
def existentialAbstraction(tparams: List[Symbol], tpe0: Type): Type =
if (tparams.isEmpty) tpe0
else {
- val tpe = tpe0 map (_.dealias)
+ val tpe = normalizeAliases(tpe0)
val tpe1 = new ExistentialExtrapolation(tparams) extrapolate tpe
var tparams0 = tparams
var tparams1 = tparams0 filter tpe1.contains
diff --git a/src/reflect/scala/reflect/internal/tpe/GlbLubs.scala b/src/reflect/scala/reflect/internal/tpe/GlbLubs.scala
index 7a10401a45..0a7a2a127c 100644
--- a/src/reflect/scala/reflect/internal/tpe/GlbLubs.scala
+++ b/src/reflect/scala/reflect/internal/tpe/GlbLubs.scala
@@ -80,11 +80,11 @@ private[internal] trait GlbLubs {
var lubListDepth = 0
// This catches some recursive situations which would otherwise
// befuddle us, e.g. pos/hklub0.scala
- def isHotForTs(xs: List[Type]) = ts exists (_.typeParams == xs.map(_.typeSymbolDirect))
+ def isHotForTs(xs: List[Type]) = ts exists (_.typeParams == xs.map(_.typeSymbol))
def elimHigherOrderTypeParam(tp: Type) = tp match {
case TypeRef(_, _, args) if args.nonEmpty && isHotForTs(args) =>
- logResult(s"Retracting dummies from $tp in lublist")(tp.typeConstructor)
+ logResult("Retracting dummies from " + tp + " in lublist")(tp.typeConstructor)
case _ => tp
}
// pretypes is a tail-recursion-preserving accumulator.
@@ -101,7 +101,7 @@ private[internal] trait GlbLubs {
// Is the frontier made up of types with the same symbol?
val isUniformFrontier = (ts0: @unchecked) match {
- case t :: ts => ts forall (_.typeSymbolDirect == t.typeSymbolDirect)
+ case t :: ts => ts forall (_.typeSymbol == t.typeSymbol)
}
// Produce a single type for this frontier by merging the prefixes and arguments of those
@@ -112,11 +112,11 @@ private[internal] trait GlbLubs {
if (isUniformFrontier) {
val fbounds = findRecursiveBounds(ts0) map (_._2)
val tcLubList = typeConstructorLubList(ts0)
- def isRecursive(tp: Type) = tp.typeSymbolDirect.typeParams exists fbounds.contains
+ def isRecursive(tp: Type) = tp.typeSymbol.typeParams exists fbounds.contains
val ts1 = ts0 map { t =>
if (isRecursive(t)) {
- tcLubList map (t baseType _.typeSymbolDirect) find (t => !isRecursive(t)) match {
+ tcLubList map (t baseType _.typeSymbol) find (t => !isRecursive(t)) match {
case Some(tp) => logResult(s"Breaking recursion in lublist, substituting weaker type.\n Was: $t\n Now")(tp)
case _ => t
}
@@ -133,7 +133,7 @@ private[internal] trait GlbLubs {
// frontier is not uniform yet, move it beyond the current minimal symbol;
// lather, rinSe, repeat
val sym = minSym(ts0)
- val newtps = tsBts map (ts => if (ts.head.typeSymbolDirect == sym) ts.tail else ts)
+ val newtps = tsBts map (ts => if (ts.head.typeSymbol == sym) ts.tail else ts)
if (printLubs) {
val str = (newtps.zipWithIndex map { case (tps, idx) =>
tps.map(" " + _ + "\n").mkString(" (" + idx + ")\n", "", "\n")
@@ -157,7 +157,9 @@ private[internal] trait GlbLubs {
/** The minimal symbol of a list of types (as determined by `Symbol.isLess`). */
private def minSym(tps: List[Type]): Symbol =
- tps.iterator map (_.typeSymbolDirect) reduceLeft ((x, y) => if (x isLess y) x else y)
+ (tps.head.typeSymbol /: tps.tail) {
+ (sym1, tp2) => if (tp2.typeSymbol isLess sym1) tp2.typeSymbol else sym1
+ }
/** A minimal type list which has a given list of types as its base type sequence */
def spanningTypes(ts: List[Type]): List[Type] = ts match {
diff --git a/src/reflect/scala/reflect/internal/tpe/TypeMaps.scala b/src/reflect/scala/reflect/internal/tpe/TypeMaps.scala
index 76d02f5f9d..c35825dcee 100644
--- a/src/reflect/scala/reflect/internal/tpe/TypeMaps.scala
+++ b/src/reflect/scala/reflect/internal/tpe/TypeMaps.scala
@@ -12,6 +12,19 @@ private[internal] trait TypeMaps {
self: SymbolTable =>
import definitions._
+ /** Normalize any type aliases within this type (@see Type#normalize).
+ * Note that this depends very much on the call to "normalize", not "dealias",
+ * so it is no longer carries the too-stealthy name "deAlias".
+ */
+ object normalizeAliases extends TypeMap {
+ def apply(tp: Type): Type = tp match {
+ case TypeRef(_, sym, _) if sym.isAliasType =>
+ def msg = if (tp.isHigherKinded) s"Normalizing type alias function $tp" else s"Dealiasing type alias $tp"
+ mapOver(logResult(msg)(tp.normalize))
+ case _ => mapOver(tp)
+ }
+ }
+
/** Remove any occurrence of type <singleton> from this type and its parents */
object dropSingletonType extends TypeMap {
def apply(tp: Type): Type = {
@@ -376,7 +389,7 @@ private[internal] trait TypeMaps {
case TypeRef(pre, sym, args) if tparams contains sym =>
val repl = if (variance.isPositive) dropSingletonType(tp1.bounds.hi) else tp1.bounds.lo
val count = occurCount(sym)
- val containsTypeParam = tparams exists repl.contains
+ val containsTypeParam = tparams exists (repl contains _)
def msg = {
val word = if (variance.isPositive) "upper" else "lower"
s"Widened lone occurrence of $tp1 inside existential to $word bound"
diff --git a/test/files/neg/t2994a.check b/test/files/neg/t2994a.check
deleted file mode 100644
index 24538a50c3..0000000000
--- a/test/files/neg/t2994a.check
+++ /dev/null
@@ -1,7 +0,0 @@
-t2994a.scala:24: error: kinds of the type arguments (m#a,s) do not conform to the expected kinds of the type parameters (type n,type s) in trait curry.
-m#a's type parameters do not match type n's expected parameters:
-type _'s bounds <: Naturals.NAT are stricter than type _'s declared bounds >: Nothing <: Any, type z's bounds <: Naturals.NAT are stricter than type _'s declared bounds >: Nothing <: Any, s's type parameters do not match type s's expected parameters:
-type _'s bounds <: Naturals.NAT are stricter than type _ (in trait curry)'s declared bounds >: Nothing <: Any
- type a[s[_ <: NAT] <: NAT, z <: NAT] = n#a[curry[m#a, s]#f, z]
- ^
-one error found
diff --git a/test/files/neg/t2994a.scala b/test/files/neg/t2994a.scala
deleted file mode 100644
index f2d57c34ca..0000000000
--- a/test/files/neg/t2994a.scala
+++ /dev/null
@@ -1,27 +0,0 @@
-object Naturals {
- trait NAT {
- type a[s[_ <: NAT] <: NAT, z <: NAT] <: NAT
- type v = a[SUCC, ZERO]
- }
- final class ZERO extends NAT {
- type a[s[_ <: NAT] <: NAT, z <: NAT] = z
- }
- final class SUCC[n <: NAT] extends NAT {
- type a[s[_ <: NAT] <: NAT, z <: NAT] = s[n#a[s, z]]
- }
- type _0 = ZERO
- type _1 = SUCC[_0]
- type _2 = SUCC[_1]
- type _3 = SUCC[_2]
- type _4 = SUCC[_3]
- type _5 = SUCC[_4]
- type _6 = SUCC[_5]
-
-
- // crashes scala-2.8.0 beta1
- trait MUL[n <: NAT, m <: NAT] extends NAT {
- trait curry[n[_[_], _], s[_]] { type f[z <: NAT] = n[s, z] }
- type a[s[_ <: NAT] <: NAT, z <: NAT] = n#a[curry[m#a, s]#f, z]
- }
-
-} \ No newline at end of file
diff --git a/test/files/pos/t2994a.scala b/test/files/pos/t2994a.scala
index 15456991d0..f2d57c34ca 100644
--- a/test/files/pos/t2994a.scala
+++ b/test/files/pos/t2994a.scala
@@ -17,9 +17,11 @@ object Naturals {
type _5 = SUCC[_4]
type _6 = SUCC[_5]
- // crashes scala-2.8.0 beta1
+
+ // crashes scala-2.8.0 beta1
trait MUL[n <: NAT, m <: NAT] extends NAT {
- trait curry[ n[ m[x1 <: NAT], x2 <: NAT], s[x3 <: NAT] ] { type f[z <: NAT] = n[s, z] }
+ trait curry[n[_[_], _], s[_]] { type f[z <: NAT] = n[s, z] }
type a[s[_ <: NAT] <: NAT, z <: NAT] = n#a[curry[m#a, s]#f, z]
}
-}
+
+} \ No newline at end of file
diff --git a/test/files/pos/t2994c.scala b/test/files/pos/t2994c.scala
deleted file mode 100644
index 1ad3655c89..0000000000
--- a/test/files/pos/t2994c.scala
+++ /dev/null
@@ -1,8 +0,0 @@
-object Test {
- trait Bar[X[_]]
- trait Qux[S[_] <: Bar[S], T]
- trait Baz[S[_] <: Bar[S]] {
- type Apply[T] = Qux[S,T]
- }
- trait Foo[/**/V[_] <: Bar[V]/**/] extends Bar[Baz[V]#Apply]
-}
diff --git a/test/files/pos/t7517.scala b/test/files/pos/t7517.scala
deleted file mode 100644
index 29bd0936ce..0000000000
--- a/test/files/pos/t7517.scala
+++ /dev/null
@@ -1,22 +0,0 @@
-trait Box[ K[A[x]] ]
-
-object Box {
- // type constructor composition
- sealed trait ∙[A[_], B[_]] { type l[T] = A[B[T]] }
-
- // composes type constructors inside K
- type SplitBox[K[A[x]], B[x]] = Box[ ({ type l[A[x]] = K[ (A ∙ B)#l] })#l ]
-
- def split[ K[A[x]], B[x] ](base: Box[K]): SplitBox[K,B] = ???
-
- class Composed[B[_], K[A[x]] ] {
- val box: Box[K] = ???
-
- type Split[ A[x] ] = K[ (A ∙ B)#l ]
- val a: Box[Split] = Box.split(box)
-
- //Either of these work:
- //val a: Box[Split] = Box.split[K,B](box)
- //val a: Box[ ({ type l[A[x]] = K[ (A ∙ B)#l ] })#l ] = Box.split(box)
- }
-}
diff --git a/test/files/run/t6113.check b/test/files/run/t6113.check
index 56c11d1fab..65fb3cd090 100644
--- a/test/files/run/t6113.check
+++ b/test/files/run/t6113.check
@@ -1 +1 @@
-Foo[AnyRef{type l[X] = (Int, X)}#l]
+Foo[[X](Int, X)]
diff --git a/test/pending/neg/t2994b.scala b/test/pending/neg/t2994b.scala
deleted file mode 100644
index 20be85eb58..0000000000
--- a/test/pending/neg/t2994b.scala
+++ /dev/null
@@ -1,8 +0,0 @@
-trait curry[s[_]] { type f = Double }
-
-// a1 and a2 fail to compile, but all three should fail.
-class A {
- type a1[s[_ <: Int]] = curry[s]
- type a2[s[_ <: Int]] = curry[s]#f
- type a3[s[_ <: Int]] = Set[curry[s]#f]
-}
diff --git a/test/pending/pos/lubbing-aliases.scala b/test/pending/pos/lubbing-aliases.scala
deleted file mode 100644
index 9c71a4ec91..0000000000
--- a/test/pending/pos/lubbing-aliases.scala
+++ /dev/null
@@ -1,40 +0,0 @@
-trait outer[cc[x], t] {
- type M[x]
- type V
-}
-
-trait Coll[+A]
-trait List[+A] extends Coll[A]
-trait Set[A] extends Coll[A]
-trait Stream[+A] extends Coll[A]
-trait Vector[A] extends Coll[A]
-
-trait Foo[A] {
- type M1[CC[x]] = outer[CC, A]#V
- type M2[CC[x]] = M1[CC]
- type M3[CC[x]] = outer[CC, A]#M[A]
- type M4[CC[x]] = M3[CC]
-
- def f1: M1[List]
- def f2: M2[Set]
- def f3: M3[Stream]
- def f4: M4[Vector]
-
- def g12 = List(f1, f2).head
- def g13 = List(f1, f3).head
- def g14 = List(f1, f4).head
- def g23 = List(f2, f3).head
- def g24 = List(f2, f4).head
- def g34 = List(f3, f4).head
-}
-
-trait Bar extends Foo[Int] {
- class Bippy {
- def g12 = List(f1, f2).head
- def g13 = List(f1, f3).head
- def g14 = List(f1, f4).head
- def g23 = List(f2, f3).head
- def g24 = List(f2, f4).head
- def g34 = List(f3, f4).head
- }
-}