From 9cd15421432871b920d377af86e1cd1b3edb270e Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 4 Apr 2013 09:57:15 +0200 Subject: Trying to get at the root of cyclic reference problems. Part 1: Enabling tracing and avoiding subtype computations in margeDenot. --- src/dotty/tools/dotc/core/Denotations.scala | 13 ++++++-- src/dotty/tools/dotc/core/SymDenotations.scala | 4 +-- src/dotty/tools/dotc/core/TypeComparers.scala | 2 +- src/dotty/tools/dotc/core/TypeOps.scala | 42 +++++++++++++------------- src/dotty/tools/dotc/core/Types.scala | 2 +- 5 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala index 08f4c9c57..c0fa46e31 100644 --- a/src/dotty/tools/dotc/core/Denotations.scala +++ b/src/dotty/tools/dotc/core/Denotations.scala @@ -227,9 +227,10 @@ object Denotations { val sym2Eligible = sym2.isAsConcrete(sym1) val bounds1 = normalize(info1) val bounds2 = normalize(info2) - if (sym2Eligible && bounds2 <:< bounds1) denot2 - else if (sym1Eligible && bounds1 <:< bounds2) denot1 - else new JointRefDenotation( +// if (sym2Eligible && bounds2 <:< bounds1) denot2 +// else if (sym1Eligible && bounds1 <:< bounds2) denot1 +// else + new LazyJointRefDenotation( if (sym2Eligible) sym2 else sym1, bounds1 & bounds2, denot1.validFor & denot2.validFor) @@ -505,6 +506,12 @@ object Denotations { override protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = new JointRefDenotation(s, i, validFor) } + class LazyJointRefDenotation(val symbol: Symbol, infoFn: => Type, initValidFor: Period) extends SingleDenotation { + validFor = initValidFor + lazy val info = infoFn + override protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = new JointRefDenotation(s, i, validFor) + } + class ErrorDenotation(implicit ctx: Context) extends SingleDenotation { override def exists = false val symbol = NoSymbol diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index ed83878a1..3f0ad171a 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -99,7 +99,7 @@ object SymDenotations { if (_flags is Touched) throw new CyclicReference(this) _flags |= Touched - /* !!! DEBUG Context.theBase.initialCtx.traceIndented(s"completing ${this.debugString}") */ { + Context.theBase.initialCtx.traceIndented(s"completing ${this.debugString}") { completer.complete(this) } } @@ -895,7 +895,7 @@ object SymDenotations { NoType } - /* !!! DEBUG ctx.traceIndented(s"$tp.baseType($this)") */ { + ctx.traceIndented(s"$tp.baseType($this)") { if (symbol.isStatic) symbol.typeConstructor else tp match { case tp: CachedType => diff --git a/src/dotty/tools/dotc/core/TypeComparers.scala b/src/dotty/tools/dotc/core/TypeComparers.scala index 7320438ed..464cec37c 100644 --- a/src/dotty/tools/dotc/core/TypeComparers.scala +++ b/src/dotty/tools/dotc/core/TypeComparers.scala @@ -55,7 +55,7 @@ object TypeComparers { } } - def firstTry(tp1: Type, tp2: Type): Boolean = /* !!! DEBUG ctx.traceIndented(s"$tp1 <:< $tp2") */ { + def firstTry(tp1: Type, tp2: Type): Boolean = ctx.traceIndented(s"$tp1 <:< $tp2") { tp2 match { case tp2: NamedType => tp1 match { diff --git a/src/dotty/tools/dotc/core/TypeOps.scala b/src/dotty/tools/dotc/core/TypeOps.scala index f86cc5296..7b09df769 100644 --- a/src/dotty/tools/dotc/core/TypeOps.scala +++ b/src/dotty/tools/dotc/core/TypeOps.scala @@ -19,32 +19,32 @@ 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 - if (sym.isStatic) tp - else { - val tp1 = tp.derivedNamedType(asSeenFrom(tp.prefix, pre, cls, theMap)) - // short-circuit instantiated type parameters - if ((tp1 ne tp) && (sym is (TypeParam, butNot = Deferred))) tp1.dealias - else tp1 - } - case ThisType(thiscls) => - toPrefix(pre, cls, thiscls) - case _: BoundType | NoPrefix => - tp - case tp: RefinedType => - tp.derivedRefinedType( + ctx.traceIndented(s"$tp.asSeenFrom($pre, $cls)") { + tp match { + case tp: NamedType => + val sym = tp.symbol + if (sym.isStatic) tp + else { + val tp1 = tp.derivedNamedType(asSeenFrom(tp.prefix, pre, cls, theMap)) + // short-circuit instantiated type parameters + if ((tp1 ne tp) && (sym is (TypeParam, butNot = Deferred))) tp1.dealias + else tp1 + } + case ThisType(thiscls) => + toPrefix(pre, cls, thiscls) + case _: BoundType | NoPrefix => + tp + case tp: RefinedType => + tp.derivedRefinedType( asSeenFrom(tp.parent, pre, cls, theMap), tp.refinedName, asSeenFrom(tp.refinedInfo, pre, cls, theMap)) - case _ => - (if (theMap != null) theMap else new AsSeenFromMap(pre, cls)) - .mapOver(tp) + case _ => + (if (theMap != null) theMap else new AsSeenFromMap(pre, cls)) + .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 98dcc43a1..a397426c7 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -984,7 +984,7 @@ object Types { final class TermRefWithSignature(prefix: Type, name: TermName, val sig: Signature) extends TermRef(prefix, name) { override def signature(implicit ctx: Context) = sig - override def loadDenot(implicit ctx: Context): Denotation = + override def loadDenot(implicit ctx: Context): Denotation = super.loadDenot.atSignature(sig) override def newLikeThis(prefix: Type)(implicit ctx: Context): TermRefWithSignature = TermRef(prefix, name, sig) -- cgit v1.2.3