diff options
-rwxr-xr-x | src/compiler/scala/tools/nsc/symtab/BaseTypeSeqs.scala | 42 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Types.scala | 8 |
2 files changed, 38 insertions, 12 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/BaseTypeSeqs.scala b/src/compiler/scala/tools/nsc/symtab/BaseTypeSeqs.scala index 1b8ddb192e..9947aa5209 100755 --- a/src/compiler/scala/tools/nsc/symtab/BaseTypeSeqs.scala +++ b/src/compiler/scala/tools/nsc/symtab/BaseTypeSeqs.scala @@ -62,6 +62,27 @@ trait BaseTypeSeqs { def exists(p: Type => Boolean): Boolean = elems exists p // (0 until length) exists (i => p(this(i))) + def normalize(parents: List[Type]) { + var j = 0 + while (j < elems.length) { + elems(j) match { + case RefinedType(variants, decls) => + // can't assert decls.isEmpty; see t0764 + //if (!decls.isEmpty) assert(false, "computing closure of "+this+":"+this.isInstanceOf[RefinedType]+"/"+closureCache(j)) + //Console.println("compute closure of "+this+" => glb("+variants+")") + elems(j) = mergePrefixAndArgs(variants, -1, maxBaseTypeSeqDepth(variants) + LubGlbMargin) match { + case Some(tp0) => tp0 + case None => throw new TypeError( + "the type intersection "+(parents mkString " with ")+" is malformed"+ + "\n --- because ---"+ + "\n no common type instance of base types "+(variants mkString ", and ")+" exists.") + } + case _ => + } + j += 1 + } + } + lazy val maxDepth: Int = { var d = 0 for (i <- 0 until length) d = Math.max(d, self.maxDepth(this(i))) @@ -80,17 +101,17 @@ trait BaseTypeSeqs { def baseTypeSingletonSeq(tp: Type): BaseTypeSeq = new BaseTypeSeq(Array(tp)) /** Create the base type sequence of a compound type wuth given tp.parents */ - def compoundBaseTypeSeq(tp: CompoundType): BaseTypeSeq = { - //Console.println("computing baseTypeSeq of " + tsym.tpe + " " + tp.parents)//DEBUG + def compoundBaseTypeSeq(tsym: Symbol, parents: List[Type]): BaseTypeSeq = { +// Console.println("computing baseTypeSeq of " + tsym.tpe + " " + parents)//DEBUG val buf = new ListBuffer[Type] - buf += tp.typeSymbol.tpe + buf += tsym.tpe var btsSize = 1 - val nparents = tp.parents.length + val nparents = parents.length if (nparents != 0) { val pbtss = new Array[BaseTypeSeq](nparents) val index = new Array[Int](nparents) var i = 0 - for (p <- tp.parents) { + for (p <- parents) { pbtss(i) = if (p.baseTypeSeq eq undetBaseTypeSeq) AnyClass.info.baseTypeSeq else p.baseTypeSeq @@ -127,8 +148,10 @@ trait BaseTypeSeqs { } val elems = new Array[Type](btsSize) buf.copyToArray(elems, 0) - //Console.println("baseTypeSeqCache of " + tsym.tpe + " = " + arr.toString)//DEBUG - tp.baseTypeSeqCache = new BaseTypeSeq(elems) +// Console.println("computed baseTypeSeq of " + tsym.tpe + " " + parents + ": "+elems.toString)//DEBUG + new BaseTypeSeq(elems) + } +/* var j = 0 while (j < btsSize) { elems(j) match { @@ -139,7 +162,7 @@ trait BaseTypeSeqs { elems(j) = mergePrefixAndArgs(variants, -1, maxBaseTypeSeqDepth(variants) + LubGlbMargin) match { case Some(tp0) => tp0 case None => throw new TypeError( - "the type intersection "+(tp.parents mkString " with ")+" is malformed"+ + "the type intersection "+(parents mkString " with ")+" is malformed"+ "\n --- because ---"+ "\n no common type instance of base types "+(variants mkString ", and ")+" exists.") } @@ -147,6 +170,7 @@ trait BaseTypeSeqs { } j += 1 } - tp.baseTypeSeqCache // todo: needed, or can be unit? + tp.baseTypeSeqCache } +*/ } diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index efe789e2e6..2eeecbace6 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -121,7 +121,7 @@ trait Types { } /** A proxy for a type (identified by field `underlying') that forwards most - * operations to it (for exceptions, see WrappingProxy, which forwards even more operations. + * operations to it (for exceptions, see WrappingProxy, which forwards even more operations). * every operation that is overridden for some kind of types should be forwarded. */ trait SimpleTypeProxy extends Type { @@ -1035,7 +1035,10 @@ trait Types { if (util.Statistics.enabled) compoundBaseTypeSeqCount += 1 baseTypeSeqCache = undetBaseTypeSeq - baseTypeSeqCache = memo(compoundBaseTypeSeq(this))(_.baseTypeSeq updateHead typeSymbol.tpe) + baseTypeSeqCache = memo(compoundBaseTypeSeq(typeSymbol, parents))(_.baseTypeSeq updateHead typeSymbol.tpe) +// println("normalizing baseTypeSeq of "+typeSymbol+"/"+parents+": "+baseTypeSeqCache)//DEBUG + baseTypeSeqCache.normalize(parents) +// println("normalized baseTypeSeq of "+typeSymbol+"/"+parents+": "+baseTypeSeqCache)//DEBUG } //Console.println("baseTypeSeq(" + typeSymbol + ") = " + List.fromArray(baseTypeSeqCache));//DEBUG } @@ -1469,7 +1472,6 @@ A type's typeSymbol should never be inspected directly. } } - } if (baseTypeSeqCache == undetBaseTypeSeq) throw new TypeError("illegal cyclic inheritance involving " + sym) baseTypeSeqCache |