From b9232781f413056eadae65fb19bbfc6d514f39d2 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 10 Sep 2008 17:02:36 +0000 Subject: new starr with more robust handling of recursiv... new starr with more robust handling of recursive dependencies in glb. Needed for next iteration of collection classes. --- lib/scala-compiler.jar.desired.sha1 | 2 +- lib/scala-library-src.jar.desired.sha1 | 2 +- lib/scala-library.jar.desired.sha1 | 2 +- src/compiler/scala/tools/nsc/symtab/Types.scala | 42 ++++++++++++++++++------- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/lib/scala-compiler.jar.desired.sha1 b/lib/scala-compiler.jar.desired.sha1 index 65088b5738..c1bddc1ca1 100644 --- a/lib/scala-compiler.jar.desired.sha1 +++ b/lib/scala-compiler.jar.desired.sha1 @@ -1 +1 @@ -0ec57247578730103488689e3fd8686396c63c6a ?scala-compiler.jar +8c0f90b320d40477cb7f2df6dbb6faf5fbde8064 ?scala-compiler.jar diff --git a/lib/scala-library-src.jar.desired.sha1 b/lib/scala-library-src.jar.desired.sha1 index f26bda34b5..8fb42be864 100644 --- a/lib/scala-library-src.jar.desired.sha1 +++ b/lib/scala-library-src.jar.desired.sha1 @@ -1 +1 @@ -47a9b123beefe77ca07599379604db310377b7f3 ?scala-library-src.jar +6a4b849fd2dc42f65e76671de7468e58353e32e0 ?scala-library-src.jar diff --git a/lib/scala-library.jar.desired.sha1 b/lib/scala-library.jar.desired.sha1 index 3654c39baf..c2fe093dfa 100644 --- a/lib/scala-library.jar.desired.sha1 +++ b/lib/scala-library.jar.desired.sha1 @@ -1 +1 @@ -b0d33d9ee53b7efa093db7b7e3f7f2e953aafe68 ?scala-library.jar +b8ae24f3f67aceb84009de3692c3ed39c101985f ?scala-library.jar diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index 342d931eeb..8fbf8926e7 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -3583,9 +3583,9 @@ A type's typeSymbol should never be inspected directly. case (_, WildcardType) => true case (NoType, _) => false - case (NoPrefix, _) => tp2.typeSymbol.isPackageClass + case (NoPrefix, _) => tp2 == NoPrefix || tp2.typeSymbol.isPackageClass case (_, NoType) => false - case (_, NoPrefix) => tp1.typeSymbol.isPackageClass + case (_, NoPrefix) => tp1 == NoPrefix || tp1.typeSymbol.isPackageClass case (ThisType(_), ThisType(_)) => tp1 =:= tp2 case (ThisType(_), SingleType(_, _)) => tp1 =:= tp2 @@ -3967,7 +3967,6 @@ A type's typeSymbol should never be inspected directly. def elimSub0(ts: List[Type]): List[Type] = ts match { case List() => List() case t :: ts1 => - assert(depth != AnyDepth) val rest = elimSub0(ts1 filter (t1 => !isSubType(t1, t, decr(depth)))) if (rest exists (t1 => isSubType(t, t1, decr(depth)))) rest else t :: rest } @@ -4012,7 +4011,6 @@ A type's typeSymbol should never be inspected directly. case ts @ MethodType(pts, _) :: rest => MethodType(pts, lub0(matchingRestypes(ts, pts))) case ts @ TypeBounds(_, _) :: rest => - assert(false) mkTypeBounds(glb(ts map (_.bounds.lo), depth), lub(ts map (_.bounds.hi), depth)) case ts0 => val (ts, tparams) = stripExistentialsAndTypeVars(ts0) @@ -4090,6 +4088,15 @@ A type's typeSymbol should never be inspected directly. val GlbFailure = new Throwable + /** A global counter for glb calls in the `specializes' query connected to the `addMembers' + * call in `glb'. There's a possible inifinite recursion when `specializes' calls + * memberType, which calls baseTypeSeq, which calls mergePrefixAndArgs, which calls glb. + * The counter breaks this recursion after two calls. + * If the recursion is broken, no member is added to the glb. + */ + private var globalGlbDepth = 0 + private final val globalGlbLimit = 2 + def glb(ts: List[Type]): Type = glb(ts, lubDepth(ts)) /** The greatest lower bound wrt <:< of a list of types */ @@ -4114,6 +4121,12 @@ A type's typeSymbol should never be inspected directly. case RefinedType(ps, _) => ps flatMap refinedToParents case _ => List(t) } + def refinedToDecls(t: Type): List[Scope] = t match { + case RefinedType(ps, decls) => + val dss = ps flatMap refinedToDecls + if (decls.isEmpty) dss else decls :: dss + case _ => List() + } val ts1 = ts flatMap refinedToParents val glbBase = intersectionType(ts1, glbOwner) val glbType = @@ -4154,13 +4167,20 @@ A type's typeSymbol should never be inspected directly. result }) } - for (t <- ts; val sym <- t.nonPrivateMembers) - if (!sym.isClass && !sym.isConstructor && !(glbThisType specializes sym)) - try { - addMember(glbThisType, glbRefined, glbsym(sym)) - } catch { - case ex: NoCommonType => - } + if (globalGlbDepth < globalGlbLimit) + try { + globalGlbDepth += 1 + val dss = ts flatMap refinedToDecls + for (ds <- dss; val sym <- ds.elements) + if (globalGlbDepth < globalGlbLimit && !(glbThisType specializes sym)) + try { + addMember(glbThisType, glbRefined, glbsym(sym)) + } catch { + case ex: NoCommonType => + } + } finally { + globalGlbDepth -= 1 + } if (glbRefined.decls.isEmpty) glbBase else glbRefined } existentialAbstraction(tparams, glbType) -- cgit v1.2.3