From 609aeee025eec0bfc6680bf7fe717d0083cfb15b Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 3 Apr 2013 19:02:42 +0200 Subject: Improvements in tracing and some Type fixes. --- src/dotty/tools/dotc/core/Contexts.scala | 10 +--- src/dotty/tools/dotc/core/SymDenotations.scala | 64 +++++++++++++++++--------- src/dotty/tools/dotc/core/SymbolLoaders.scala | 2 +- src/dotty/tools/dotc/core/TypeComparers.scala | 60 ++++++++++++------------ src/dotty/tools/dotc/core/TypeOps.scala | 2 + src/dotty/tools/dotc/core/Types.scala | 10 ++-- src/dotty/tools/dotc/reporting/Reporter.scala | 17 ++++--- 7 files changed, 92 insertions(+), 73 deletions(-) (limited to 'src') diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala index 241d41da9..bb8735860 100644 --- a/src/dotty/tools/dotc/core/Contexts.scala +++ b/src/dotty/tools/dotc/core/Contexts.scala @@ -258,15 +258,7 @@ object Contexts { val settings = new ScalaSettings /** The initial context */ - val initialCtx: Context = - new InitialContext(this, settings) - .withSetting(settings.verbose, true) // !!! for now - .withSetting(settings.debug, true) -// .withSetting(settings.debugNames, true) - .withSetting(settings.Ylogcp, true) - .withSetting(settings.printtypes, true) - .withSetting(settings.pageWidth, 90) - .withSetting(settings.log, List(">>> completing "+this.debugString+"/"+owner.id, -// "<<<< completed: "+this.debugString) { + + /* !!! DEBUG Context.theBase.initialCtx.traceIndented(s"completing ${this.debugString}") */ { completer.complete(this) -// } + } } protected[core] final def info_=(tp: Type) = { @@ -855,13 +854,31 @@ object SymDenotations { final def baseTypeOf(tp: Type)(implicit ctx: Context): Type = { + def foldGlb(bt: Type, ps: List[Type]): Type = ps match { + case p :: ps1 => foldGlb(bt & baseTypeOf(p), ps1) + case _ => bt + } + def computeBaseTypeOf(tp: Type): Type = tp match { + case tp: TypeRef => + val subcls = tp.symbol + if (subcls eq symbol) + tp + else (subcls.denot) match { + case cdenot: ClassDenotation => + if (cdenot.superClassBits contains symbol.superId) foldGlb(NoType, tp.parents) + else NoType + case _ => + baseTypeOf(tp.underlying) + } case tp: TypeProxy => baseTypeOf(tp.underlying) case AndType(tp1, tp2) => baseTypeOf(tp1) & baseTypeOf(tp2) case OrType(tp1, tp2) => baseTypeOf(tp1) | baseTypeOf(tp2) +/* + * case tp: ClassInfo => def foldGlb(bt: Type, ps: List[Type]): Type = ps match { case p :: ps1 => foldGlb(bt & baseTypeOf(p), ps1) @@ -873,28 +890,31 @@ object SymDenotations { tp.rebase(foldGlb(NoType, tp.classParents)) else NoType +*/ case _ => NoType } - if (symbol.isStatic) symbol.typeConstructor - else tp match { - case tp: CachedType => - if (baseTypeValid != ctx.runId) { - baseTypeCache = new java.util.HashMap[CachedType, Type] - baseTypeValid = ctx.runId - } - var basetp = baseTypeCache get tp - if (basetp == null) { - baseTypeCache.put(tp, NoType) - basetp = computeBaseTypeOf(tp) - baseTypeCache.put(tp, basetp) - } else if (basetp == NoType) { - throw new CyclicReference(symbol) - } - basetp - case _ => - computeBaseTypeOf(tp) + /* !!! DEBUG ctx.traceIndented(s"$tp.baseType($this)") */ { + if (symbol.isStatic) symbol.typeConstructor + else tp match { + case tp: CachedType => + if (baseTypeValid != ctx.runId) { + baseTypeCache = new java.util.HashMap[CachedType, Type] + baseTypeValid = ctx.runId + } + var basetp = baseTypeCache get tp + if (basetp == null) { + baseTypeCache.put(tp, NoType) + basetp = computeBaseTypeOf(tp) + baseTypeCache.put(tp, basetp) + } else if (basetp == NoType) { + throw new CyclicReference(symbol) + } + basetp + case _ => + computeBaseTypeOf(tp) + } } } diff --git a/src/dotty/tools/dotc/core/SymbolLoaders.scala b/src/dotty/tools/dotc/core/SymbolLoaders.scala index ab177a92b..d3d99c11a 100644 --- a/src/dotty/tools/dotc/core/SymbolLoaders.scala +++ b/src/dotty/tools/dotc/core/SymbolLoaders.scala @@ -228,7 +228,7 @@ abstract class SymbolLoader extends LazyType { } try { val start = currentTime - cctx.traceIndented(s">>>> loading ${root.debugString}", s"<<<< loaded ${root.debugString}") { + cctx.traceIndented(s">>>> loading ${root.debugString}", _ => s"<<<< loaded ${root.debugString}") { doComplete(root) } cctx.informTime("loaded " + description, start) diff --git a/src/dotty/tools/dotc/core/TypeComparers.scala b/src/dotty/tools/dotc/core/TypeComparers.scala index b5896df21..7320438ed 100644 --- a/src/dotty/tools/dotc/core/TypeComparers.scala +++ b/src/dotty/tools/dotc/core/TypeComparers.scala @@ -55,38 +55,38 @@ object TypeComparers { } } - def firstTry(tp1: Type, tp2: Type): Boolean = tp2 match { - case tp2: NamedType => - tp1 match { - case tp1: NamedType => - val sym1 = tp1.symbol - val sym2 = tp2.symbol - val pre1 = tp1.prefix - val pre2 = tp2.prefix - if (sym1 == sym2) ( - ctx.erasedTypes - || (sym1.owner is Package) - || isSubType(pre1, pre2) - ) else ( - tp1.name == tp2.name && isSubType(pre1, pre2) - || sym2.isClass && { - val base = tp1.baseType(sym2) - (base ne tp1) && isSubType(base, tp2) - } - || thirdTryNamed(tp1, tp2) - ) - case _ => - secondTry(tp1, tp2) - } - case WildcardType | ErrorType => - true - case tp2: PolyParam if constraints contains tp2 => - addConstraint(tp2, TypeBounds.lower(tp1)) - case _ => - secondTry(tp1, tp2) + def firstTry(tp1: Type, tp2: Type): Boolean = /* !!! DEBUG ctx.traceIndented(s"$tp1 <:< $tp2") */ { + tp2 match { + case tp2: NamedType => + tp1 match { + case tp1: NamedType => + val sym1 = tp1.symbol + val sym2 = tp2.symbol + val pre1 = tp1.prefix + val pre2 = tp2.prefix + if (sym1 == sym2) ( + ctx.erasedTypes + || (sym1.owner is Package) + || isSubType(pre1, pre2)) + else ( + tp1.name == tp2.name && isSubType(pre1, pre2) + || sym2.isClass && { + val base = tp1.baseType(sym2) + (base ne tp1) && isSubType(base, tp2) + } + || thirdTryNamed(tp1, tp2)) + case _ => + secondTry(tp1, tp2) + } + case WildcardType | ErrorType => + true + case tp2: PolyParam if constraints contains tp2 => + addConstraint(tp2, TypeBounds.lower(tp1)) + case _ => + secondTry(tp1, tp2) + } } - def secondTry(tp1: Type, tp2: Type): Boolean = tp1 match { case WildcardType | ErrorType => true diff --git a/src/dotty/tools/dotc/core/TypeOps.scala b/src/dotty/tools/dotc/core/TypeOps.scala index 847fb0ebd..f86cc5296 100644 --- a/src/dotty/tools/dotc/core/TypeOps.scala +++ b/src/dotty/tools/dotc/core/TypeOps.scala @@ -19,6 +19,7 @@ trait TypeOps { this: Context => else toPrefix(pre.baseType(cls).normalizedPrefix, cls.owner, thiscls) + /* !!! DEBUG ctx.traceIndented(s"$tp.asSeenFrom($pre, $cls)") */ { tp match { case tp: NamedType => val sym = tp.symbol @@ -43,6 +44,7 @@ trait TypeOps { this: Context => .mapOver(tp) } } + } class AsSeenFromMap(pre: Type, cls: Symbol) extends TypeMap { def apply(tp: Type) = asSeenFrom(tp, pre, cls, this) diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index c1a84604f..98dcc43a1 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -462,7 +462,8 @@ object Types { /** This type seen as a TypeBounds */ final def bounds(implicit ctx: Context): TypeBounds = this match { case tp: TypeBounds => tp - case _ => TypeBounds(this, this) + case ci: ClassInfo => TypeAlias(ci.typeConstructor) + case _ => TypeAlias(this) } /** The type parameter with given `name`. This tries first `preCompleteDecls` @@ -1406,7 +1407,8 @@ object Types { else tp.substThis(cls, prefix) def typeConstructor(implicit ctx: Context): Type = - NamedType(prefix, cls.name) + if ((cls is PackageClass) || cls.owner.isTerm) TypeRef(prefix, cls) + else TypeRef(prefix, cls.name) // cached because baseType needs parents private var parentsCache: List[TypeRef] = null @@ -1435,8 +1437,8 @@ object Types { /** Type bounds >: lo <: hi */ abstract case class TypeBounds(lo: Type, hi: Type) extends CachedProxyType with TypeType { - assert(!lo.isInstanceOf[TypeBounds], lo+" "+lo.getClass) - assert(!hi.isInstanceOf[TypeBounds], hi+" "+hi.getClass) + assert(lo.isInstanceOf[TermType], lo+" "+lo.getClass) + assert(hi.isInstanceOf[TermType], hi+" "+hi.getClass) override def underlying(implicit ctx: Context): Type = hi diff --git a/src/dotty/tools/dotc/reporting/Reporter.scala b/src/dotty/tools/dotc/reporting/Reporter.scala index 77cbc3662..9e3a11352 100644 --- a/src/dotty/tools/dotc/reporting/Reporter.scala +++ b/src/dotty/tools/dotc/reporting/Reporter.scala @@ -35,24 +35,27 @@ trait Reporting { this: Context => value } - def traceIndented[T](leading: => String, trailing: => String)(op: => T): T = { + def traceIndented[T](question: => String)(op: => T): T = + traceIndented[T](s"==> $question?", (res: Any) => s"<== $question = $res")(op) + + def traceIndented[T](leading: => String, trailing: Any => String)(op: => T): T = { var finalized = false - def finalize(note: String) = + def finalize(result: Any, note: String) = if (!finalized) { base.indent -= 1 - log(s"${base.indentTab * base.indent}$trailing$note") + log(s"${base.indentTab * base.indent}${trailing(result)}$note") finalized = true } try { log(s"${base.indentTab * base.indent}$leading") base.indent += 1 - op + val res = op + finalize(res, "") + res } catch { case ex: Throwable => - finalize(s" (with exception $ex)") + finalize("", s" (with exception $ex)") throw ex - } finally { - finalize("") } } } -- cgit v1.2.3