aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Denotations.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-10-23 12:34:45 +0200
committerMartin Odersky <odersky@gmail.com>2013-10-23 12:35:57 +0200
commitb94874635483b2864aabd86140e51e7bdd916b40 (patch)
tree0031b7fe6a641814fddbe0ba2f968571441c1411 /src/dotty/tools/dotc/core/Denotations.scala
parent70958808202aa27034961aeb3352bd8af2e45312 (diff)
downloaddotty-b94874635483b2864aabd86140e51e7bdd916b40.tar.gz
dotty-b94874635483b2864aabd86140e51e7bdd916b40.tar.bz2
dotty-b94874635483b2864aabd86140e51e7bdd916b40.zip
Caching asSeenFrom on denotations.
The last asSeenFrom on a SingleDenotation is cached. Also, correction of effectiveOwner in SymDenotation, which needs to understand that module classes now end in a "$".
Diffstat (limited to 'src/dotty/tools/dotc/core/Denotations.scala')
-rw-r--r--src/dotty/tools/dotc/core/Denotations.scala23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala
index bc2d1a41e..045f74300 100644
--- a/src/dotty/tools/dotc/core/Denotations.scala
+++ b/src/dotty/tools/dotc/core/Denotations.scala
@@ -552,7 +552,9 @@ object Denotations {
}
final def dropUniqueRefsIn(denots: PreDenotation): SingleDenotation =
if (hasUniqueSym && denots.containsSym(symbol)) NoDenotation else this
- def asSeenFrom(pre: Type)(implicit ctx: Context): SingleDenotation = {
+
+ type AsSeenFromResult = SingleDenotation
+ protected def computeAsSeenFrom(pre: Type)(implicit ctx: Context): SingleDenotation = {
val owner = this match {
case thisd: SymDenotation => thisd.owner
case _ => if (symbol.exists) symbol.owner else NoSymbol
@@ -633,8 +635,22 @@ object Denotations {
*/
def dropUniqueRefsIn(denots: PreDenotation): PreDenotation
+ private var cachedPrefix: Type = _
+ private var cachedAsSeenFrom: AsSeenFromResult = _
+ private var validAsSeenFrom: Period = Nowhere
+ type AsSeenFromResult <: PreDenotation
+
/** The denotation with info(s) as seen from prefix type */
- def asSeenFrom(pre: Type)(implicit ctx: Context): PreDenotation
+ final def asSeenFrom(pre: Type)(implicit ctx: Context): AsSeenFromResult = {
+ if ((cachedPrefix ne pre) || ctx.period != validAsSeenFrom) {
+ cachedAsSeenFrom = computeAsSeenFrom(pre)
+ cachedPrefix = pre
+ validAsSeenFrom = ctx.period
+ }
+ cachedAsSeenFrom
+ }
+
+ protected def computeAsSeenFrom(pre: Type)(implicit ctx: Context): AsSeenFromResult
/** The union of two groups. */
def union(that: PreDenotation) =
@@ -662,7 +678,8 @@ object Denotations {
derivedUnion(denots1.filterExcluded(excluded), denots2.filterExcluded(excluded))
def dropUniqueRefsIn(denots: PreDenotation): PreDenotation =
derivedUnion(denots1.dropUniqueRefsIn(denots), denots2.dropUniqueRefsIn(denots))
- def asSeenFrom(pre: Type)(implicit ctx: Context): PreDenotation =
+ type AsSeenFromResult = PreDenotation
+ protected def computeAsSeenFrom(pre: Type)(implicit ctx: Context): PreDenotation =
derivedUnion(denots1.asSeenFrom(pre), denots2.asSeenFrom(pre))
private def derivedUnion(denots1: PreDenotation, denots2: PreDenotation) =
if ((denots1 eq this.denots1) && (denots2 eq this.denots2)) this