From 7b13a861787eb1e7823957b156dbb989f7b415d3 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 10 Jul 2014 11:50:01 +0200 Subject: Invalidate member caches in different periods A membercache is not valid in a period different from the one it was created in. Reason: The denotations stored in the cache might have different infos in different periods. Also: add maybeOwner convenience method for printing, which handles NoDenotation/NoSymbol gracefully. --- src/dotty/tools/dotc/core/SymDenotations.scala | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/dotty/tools/dotc/core') diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 7d1948784..b0a09baf0 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -83,6 +83,9 @@ object SymDenotations { /** The owner of the symbol; overridden in NoDenotation */ def owner: Symbol = ownerIfExists + /** Same as owner, except returns NoSymbol for NoSymbol */ + def maybeOwner: Symbol = if (exists) owner else NoSymbol + /** The flag set */ final def flags(implicit ctx: Context): FlagSet = { ensureCompleted(); myFlags } @@ -987,6 +990,7 @@ object SymDenotations { mySuperClassBits = null myMemberFingerPrint = FingerPrint.unknown myMemberCache = null + myMemberCachePeriod = Nowhere memberNamesCache = SimpleMap.Empty } @@ -1121,9 +1125,13 @@ object SymDenotations { } private[this] var myMemberCache: LRUCache[Name, PreDenotation] = null + private[this] var myMemberCachePeriod: Period = Nowhere - private def memberCache: LRUCache[Name, PreDenotation] = { - if (myMemberCache == null) myMemberCache = new LRUCache + private def memberCache(implicit ctx: Context): LRUCache[Name, PreDenotation] = { + if (myMemberCachePeriod != ctx.period) { + myMemberCache = new LRUCache + myMemberCachePeriod = ctx.period + } myMemberCache } -- cgit v1.2.3