Skip to content

Commit 7a2f158

Browse files
committed
Don't use null for inherited caches
The lgoxi is much nicer without it.
1 parent d2b3fff commit 7a2f158

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,8 +1239,8 @@ object SymDenotations {
12391239
private[this] var baseTypeRefCache: java.util.HashMap[CachedType, Type] = null
12401240
private[this] var baseTypeRefValid: RunId = NoRunId
12411241

1242-
private var baseDataCache: BaseData = null
1243-
private var memberNamesCache: MemberNames = null
1242+
private var baseDataCache: BaseData = BaseData.None
1243+
private var memberNamesCache: MemberNames = MemberNames.None
12441244

12451245
private def memberCache(implicit ctx: Context): LRUCache[Name, PreDenotation] = {
12461246
if (myMemberCachePeriod != ctx.period) {
@@ -1250,31 +1250,21 @@ object SymDenotations {
12501250
myMemberCache
12511251
}
12521252

1253-
private def baseDataCacheValid(implicit ctx: Context) =
1254-
baseDataCache != null && baseDataCache.isValid
1255-
1256-
private def invalidateBaseDataCache() =
1257-
if (baseDataCache != null) {
1258-
baseDataCache.invalidate()
1259-
baseDataCache = null
1260-
}
1261-
1262-
private def memberNamesCacheValid(implicit ctx: Context) =
1263-
memberNamesCache != null && memberNamesCache.isValid
1253+
private def invalidateBaseDataCache() = {
1254+
baseDataCache.invalidate()
1255+
baseDataCache = BaseData.None
1256+
}
12641257

1265-
private def invalidateMemberNamesCache() =
1266-
if (memberNamesCache != null) {
1267-
memberNamesCache.invalidate()
1268-
memberNamesCache = null
1269-
}
1258+
private def invalidateMemberNamesCache() = {
1259+
memberNamesCache.invalidate()
1260+
memberNamesCache = MemberNames.None
1261+
}
12701262

12711263
override def copyCaches(from: SymDenotation, phase: Phase)(implicit ctx: Context): this.type = {
12721264
from match {
12731265
case from: ClassDenotation =>
1274-
if (from.memberNamesCache != null && from.memberNamesCache.isValidAt(phase))
1275-
memberNamesCache = from.memberNamesCache
1276-
if (from.baseDataCache != null && from.baseDataCache.isValidAt(phase))
1277-
baseDataCache = from.baseDataCache
1266+
if (from.memberNamesCache.isValidAt(phase)) memberNamesCache = from.memberNamesCache
1267+
if (from.baseDataCache.isValidAt(phase)) baseDataCache = from.baseDataCache
12781268
case _ =>
12791269
}
12801270
this
@@ -1429,7 +1419,7 @@ object SymDenotations {
14291419
}
14301420

14311421
private def baseData(implicit onBehalf: BaseData, ctx: Context): (List[ClassSymbol], BaseClassSet) = {
1432-
if (!baseDataCacheValid) baseDataCache = BaseData()
1422+
if (!baseDataCache.isValid) baseDataCache = BaseData.newCache()
14331423
baseDataCache(this)
14341424
}
14351425

@@ -1771,7 +1761,7 @@ object SymDenotations {
17711761
if ((this is PackageClass) || !Config.cacheMemberNames)
17721762
computeMemberNames(keepOnly) // don't cache package member names; they might change
17731763
else {
1774-
if (!memberNamesCacheValid) memberNamesCache = MemberNames()
1764+
if (!memberNamesCache.isValid) memberNamesCache = MemberNames.newCache()
17751765
memberNamesCache(keepOnly, this)
17761766
}
17771767

@@ -2071,7 +2061,7 @@ object SymDenotations {
20712061
implicit val None: MemberNames = new InvalidCache with MemberNames {
20722062
def apply(keepOnly: NameFilter, clsd: ClassDenotation)(implicit onBehalf: MemberNames, ctx: Context) = ???
20732063
}
2074-
def apply()(implicit ctx: Context): MemberNames = new MemberNamesImpl(ctx.period)
2064+
def newCache()(implicit ctx: Context): MemberNames = new MemberNamesImpl(ctx.period)
20752065
}
20762066

20772067
trait BaseData extends InheritedCache {
@@ -2085,7 +2075,7 @@ object SymDenotations {
20852075
def apply(clsd: ClassDenotation)(implicit onBehalf: BaseData, ctx: Context) = ???
20862076
def signalProvisional() = ()
20872077
}
2088-
def apply()(implicit ctx: Context): BaseData = new BaseDataImpl(ctx.period)
2078+
def newCache()(implicit ctx: Context): BaseData = new BaseDataImpl(ctx.period)
20892079
}
20902080

20912081
private abstract class InheritedCacheImpl(val createdAt: Period) extends InheritedCache {

0 commit comments

Comments
 (0)