diff options
author | Martin Odersky <odersky@gmail.com> | 2006-11-16 17:21:58 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2006-11-16 17:21:58 +0000 |
commit | 2538bfa0587ba2c1f9c005fb6af3c67211397b8b (patch) | |
tree | 9bedfc551c2e18047348f1459b578d530fa87351 | |
parent | 23c02cb584b8b0311aaba4f6675f5078d9dfd6d7 (diff) | |
download | scala-2538bfa0587ba2c1f9c005fb6af3c67211397b8b.tar.gz scala-2538bfa0587ba2c1f9c005fb6af3c67211397b8b.tar.bz2 scala-2538bfa0587ba2c1f9c005fb6af3c67211397b8b.zip |
undid fix to bug798 to make the build work again.
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Types.scala | 45 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Namers.scala | 2 |
2 files changed, 45 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index f2e413130e..61ad82aca1 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -314,6 +314,8 @@ trait Types requires SymbolTable { */ def closure: Array[Type] = Array(this) + def depth: int = 1 + def baseClasses: List[Symbol] = List() /** @@ -494,6 +496,7 @@ trait Types requires SymbolTable { override def decls: Scope = supertype.decls override def baseType(clazz: Symbol): Type = supertype.baseType(clazz) override def closure: Array[Type] = supertype.closure + override def depth: int = supertype.depth override def baseClasses: List[Symbol] = supertype.baseClasses // override def isNonNull = supertype.isNonNull } @@ -652,6 +655,7 @@ trait Types requires SymbolTable { private var closurePeriod = NoPeriod private var baseClassesCache: List[Symbol] = _ private var baseClassesPeriod = NoPeriod + private var depthCache: int = _ override def closure: Array[Type] = { def computeClosure: Array[Type] = @@ -733,6 +737,7 @@ trait Types requires SymbolTable { if (!isValidForBaseClasses(period)) { closureCache = null closureCache = computeClosure + depthCache = maxDepth(closureCache) } //Console.println("closure(" + symbol + ") = " + List.fromArray(closureCache));//DEBUG } @@ -741,6 +746,8 @@ trait Types requires SymbolTable { closureCache } + override def depth: int = { closure; depthCache } + override def baseClasses: List[Symbol] = { def computeBaseClasses: List[Symbol] = if (parents.isEmpty) List(symbol) @@ -859,6 +866,7 @@ trait Types requires SymbolTable { private var parentsPeriod = NoPeriod private var closureCache: Array[Type] = _ private var closurePeriod = NoPeriod + private var depthCache: int = _ override val isTrivial: boolean = pre.isTrivial && !sym.isTypeParameter && args.forall(.isTrivial) @@ -928,11 +936,14 @@ trait Types requires SymbolTable { closureCache = if (sym.isAbstractType) addClosure(this, transform(bounds.hi).closure) else transform(sym.info.closure) + depthCache = maxDepth(closureCache) } } closureCache } + override def depth: int = { closure; depthCache } + override def baseClasses: List[Symbol] = thisInfo.baseClasses // override def isNullable: boolean = sym.info.isNullable @@ -1005,6 +1016,7 @@ trait Types requires SymbolTable { override def decls: Scope = resultType.decls override def symbol: Symbol = resultType.symbol override def closure: Array[Type] = resultType.closure + override def depth: int = resultType.depth override def baseClasses: List[Symbol] = resultType.baseClasses override def baseType(clazz: Symbol): Type = resultType.baseType(clazz) override def narrow: Type = resultType.narrow @@ -1708,6 +1720,35 @@ trait Types requires SymbolTable { // Helper Methods ------------------------------------------------------------- + import Math.max + + final def depth(tps: Seq[Type]): int = { + var d = 0 + for (val tp <- tps) d = max(d, tp.depth) + d + } + + final def maxDepth(tps: Seq[Type]): int = { + var d = 0 + for (val tp <- tps) d = max(d, maxDepth(tp)) + d + } + + final def maxDepth(tp: Type): int = tp match { + case TypeRef(pre, sym, args) => + max(maxDepth(pre), maxDepth(args) + 1) + case RefinedType(parents, decls) => + max(maxDepth(parents), maxDepth(decls.toList.map(.info)) + 1) + case TypeBounds(lo, hi) => + max(maxDepth(lo), maxDepth(hi)) + case MethodType(paramtypes, result) => + maxDepth(result) + case PolyType(tparams, result) => + max(maxDepth(result), maxDepth(tparams map (.info)) + 1) + case _ => + 1 + } + final def isValid(period: Period): boolean = period != 0 && runId(period) == currentRunId && { val pid = phaseId(period) @@ -2028,7 +2069,8 @@ trait Types requires SymbolTable { * @return ... */ private def limitRecursion(tps: List[Type], boundkind: String, - op: List[Type] => Type): Type = + op: List[Type] => Type): Type = { + val recLimit = depth(tps) + 2 if (recCount >= recLimit) { giveUp = true AnyClass.tpe @@ -2049,6 +2091,7 @@ trait Types requires SymbolTable { } result } + } /** The greatest sorted upwards closed lower bound of a list of lists of * types relative to the following ordering <= between lists of types: diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 29af968d2a..142f737283 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -335,7 +335,7 @@ trait Namers requires Analyzer { if (settings.debug.value) log("defining " + sym); val tp = typeSig(tree) sym.setInfo(tp) - if (sym.isType) typer.checkNonCyclic(sym) + //if (sym.isAliasType || sym.isAbstractType) typer.checkNonCyclic(sym) if (settings.debug.value) log("defined " + sym); validate(sym) } |