diff options
author | Martin Odersky <odersky@gmail.com> | 2015-01-09 09:52:00 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-01-09 09:52:37 +0100 |
commit | 90f2668220645df7b654827c2dfdd1100c878ac2 (patch) | |
tree | 8cd20e382467cbceffa7767d65563b76a61cdb39 | |
parent | 9f745338242524c6607fa7b2930157b0c71be939 (diff) | |
download | dotty-90f2668220645df7b654827c2dfdd1100c878ac2.tar.gz dotty-90f2668220645df7b654827c2dfdd1100c878ac2.tar.bz2 dotty-90f2668220645df7b654827c2dfdd1100c878ac2.zip |
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.
-rw-r--r-- | src/dotty/tools/dotc/core/TypeComparer.scala | 8 | ||||
-rw-r--r-- | 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) |