From 90f2668220645df7b654827c2dfdd1100c878ac2 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 9 Jan 2015 09:52:00 +0100 Subject: Optimize for case where RefinedThis is absent Since we cache the information whether a refinement contains RefinedThis occurrences to the refinement itself, we can use this info to avoid substututing RefinedThis types. Used in findMember and hasMatchingMember. The commit uncovered an issue with constraint handling that will be fixed in the next commit. --- src/dotty/tools/dotc/core/TypeComparer.scala | 8 ++++++-- src/dotty/tools/dotc/core/Types.scala | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index 8ce1ad354..79ec7ad3c 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -796,8 +796,12 @@ class TypeComparer(initctx: Context) extends DotClass with Skolemization { def hasMatchingMember(name: Name, tp1: Type, tp2: RefinedType): Boolean = /*>|>*/ ctx.traceIndented(s"hasMatchingMember($tp1 . $name, ${tp2.refinedInfo}) ${tp1.member(name).info.show}", subtyping) /*<|<*/ { val saved = skolemsOutstanding try { - val base = ensureSingleton(tp1) - var rinfo2 = tp2.refinedInfo.substRefinedThis(0, base) + var base = tp1 + var rinfo2 = tp2.refinedInfo + if (tp2.refinementRefersToThis) { + base = ensureSingleton(base) + rinfo2 = rinfo2.substRefinedThis(0, base) + } def qualifies(m: SingleDenotation) = isSubType(m.info, rinfo2) def memberMatches(mbr: Denotation): Boolean = mbr match { // inlined hasAltWith for performance case mbr: SingleDenotation => qualifies(mbr) diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 920c9c6f8..21997c5fa 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -438,7 +438,9 @@ object Types { val pdenot = go(tp.parent) val rinfo = pre match { case pre: RefinedType => tp.refinedInfo.substThis0(tp, RefinedThis(pre, -1)) - case _ => tp.refinedInfo.substRefinedThis(0, pre) + case _ => + if (tp.refinementRefersToThis) tp.refinedInfo.substRefinedThis(0, pre) + else tp.refinedInfo } if (Types.goRefinedCheck) { val rinfo0 = tp.refinedInfo.substThis0(tp, pre) -- cgit v1.2.3