Skip to content

Commit

Permalink
Fix symdenot
Browse files Browse the repository at this point in the history
  • Loading branch information
noti0na1 committed Jan 7, 2022
1 parent 9923fbc commit f0e4a8e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 58 deletions.
49 changes: 25 additions & 24 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package dotty.tools
package dotc
package core

// import scala.language.{unsafeNulls => _}
import scala.language.{unsafeNulls => _}

import Periods._, Contexts._, Symbols._, Denotations._, Names._, NameOps._, Annotations._
import Types._, Flags._, Decorators._, DenotTransformers._, StdNames._, Scopes._
Expand Down Expand Up @@ -1723,14 +1723,14 @@ object SymDenotations {
myMemberCache = EqHashMap()
myMemberCachePeriod = ctx.period
}
myMemberCache
myMemberCache.nn
}

private def baseTypeCache(using Context): BaseTypeMap = {
if !currentHasSameBaseTypesAs(myBaseTypeCachePeriod) then
myBaseTypeCache = new BaseTypeMap()
myBaseTypeCachePeriod = ctx.period
myBaseTypeCache
myBaseTypeCache.nn
}

private def invalidateBaseDataCache() = {
Expand Down Expand Up @@ -1806,7 +1806,7 @@ object SymDenotations {
case _ => typeParamsFromDecls
}
}
myTypeParams
myTypeParams.nn
}

override protected[dotc] final def info_=(tp: Type): Unit = {
Expand Down Expand Up @@ -1841,7 +1841,7 @@ object SymDenotations {

// ------ class-specific operations -----------------------------------

private var myThisType: Type = null
private var myThisType: Type | Null = null

/** The this-type depends on the kind of class:
* - for a package class `p`: ThisType(TypeRef(Noprefix, p))
Expand All @@ -1850,7 +1850,7 @@ object SymDenotations {
*/
override def thisType(using Context): Type = {
if (myThisType == null) myThisType = computeThisType
myThisType
myThisType.nn
}

private def computeThisType(using Context): Type = {
Expand All @@ -1859,11 +1859,11 @@ object SymDenotations {
ThisType.raw(TypeRef(pre, cls))
}

private var myTypeRef: TypeRef = null
private var myTypeRef: TypeRef | Null = null

override def typeRef(using Context): TypeRef = {
if (myTypeRef == null) myTypeRef = super.typeRef
myTypeRef
myTypeRef.nn
}

override def appliedRef(using Context): Type = classInfo.appliedRef
Expand Down Expand Up @@ -1971,7 +1971,7 @@ object SymDenotations {
*/
def replace(prev: Symbol, replacement: Symbol)(using Context): Unit = {
unforcedDecls.openForMutations.replace(prev, replacement)
if (myMemberCache != null) myMemberCache.remove(replacement.name)
if (myMemberCache != null) myMemberCache.uncheckedNN.remove(replacement.name)
}

/** Delete symbol from current scope.
Expand All @@ -1982,7 +1982,7 @@ object SymDenotations {
val scope = info.decls.openForMutations
scope.unlink(sym, sym.name)
if sym.name != sym.originalName then scope.unlink(sym, sym.originalName)
if (myMemberCache != null) myMemberCache.remove(sym.name)
if (myMemberCache != null) myMemberCache.uncheckedNN.remove(sym.name)
if (!sym.flagsUNSAFE.is(Private)) invalidateMemberNamesCache()
}

Expand All @@ -2008,7 +2008,7 @@ object SymDenotations {
final def membersNamed(name: Name)(using Context): PreDenotation =
Stats.record("membersNamed")
if Config.cacheMembersNamed then
var denots: PreDenotation = memberCache.lookup(name)
var denots: PreDenotation | Null = memberCache.lookup(name)
if denots == null then
denots = computeMembersNamed(name)
memberCache(name) = denots
Expand Down Expand Up @@ -2416,7 +2416,7 @@ object SymDenotations {
)
if compiledNow.exists then compiledNow
else
val assocFiles = multi.aggregate(d => Set(d.symbol.associatedFile), _ union _)
val assocFiles = multi.aggregate(d => Set(d.symbol.associatedFile.nn), _ union _)
if assocFiles.size == 1 then
multi // they are all overloaded variants from the same file
else
Expand All @@ -2441,7 +2441,7 @@ object SymDenotations {
try f.container == chosen.container catch case NonFatal(ex) => true
if !ambiguityWarningIssued then
for conflicting <- assocFiles.find(!sameContainer(_)) do
report.warning(i"""${ambiguousFilesMsg(conflicting)}
report.warning(i"""${ambiguousFilesMsg(conflicting.nn)}
|Keeping only the definition in $chosen""")
ambiguityWarningIssued = true
multi.filterWithPredicate(_.symbol.associatedFile == chosen)
Expand Down Expand Up @@ -2631,8 +2631,8 @@ object SymDenotations {
def apply(module: TermSymbol, modcls: ClassSymbol): LazyType = this

private var myDecls: Scope = EmptyScope
private var mySourceModule: Symbol = null
private var myModuleClass: Symbol = null
private var mySourceModule: Symbol | Null = null
private var myModuleClass: Symbol | Null = null
private var mySourceModuleFn: Context ?=> Symbol = LazyType.NoSymbolFn
private var myModuleClassFn: Context ?=> Symbol = LazyType.NoSymbolFn

Expand All @@ -2644,10 +2644,10 @@ object SymDenotations {
def decls: Scope = myDecls
def sourceModule(using Context): Symbol =
if mySourceModule == null then mySourceModule = mySourceModuleFn
mySourceModule
mySourceModule.nn
def moduleClass(using Context): Symbol =
if myModuleClass == null then myModuleClass = myModuleClassFn
myModuleClass
myModuleClass.nn

def withDecls(decls: Scope): this.type = { myDecls = decls; this }
def withSourceModule(sourceModuleFn: Context ?=> Symbol): this.type = { mySourceModuleFn = sourceModuleFn; this }
Expand Down Expand Up @@ -2771,10 +2771,11 @@ object SymDenotations {
private abstract class InheritedCacheImpl(val createdAt: Period) extends InheritedCache {
protected def sameGroup(p1: Phase, p2: Phase): Boolean

private var dependent: WeakHashMap[InheritedCache, Unit] = null
private var dependent: WeakHashMap[InheritedCache, Unit] | Null = null
private var checkedPeriod: Period = Nowhere

protected def invalidateDependents() = {
import scala.language.unsafeNulls
if (dependent != null) {
val it = dependent.keySet.iterator()
while (it.hasNext()) it.next().invalidate()
Expand All @@ -2784,7 +2785,7 @@ object SymDenotations {

protected def addDependent(dep: InheritedCache) = {
if (dependent == null) dependent = new WeakHashMap
dependent.put(dep, ())
dependent.nn.put(dep, ())
}

def isValidAt(phase: Phase)(using Context) =
Expand All @@ -2802,7 +2803,7 @@ object SymDenotations {
}

private class MemberNamesImpl(createdAt: Period) extends InheritedCacheImpl(createdAt) with MemberNames {
private var cache: SimpleIdentityMap[NameFilter, Set[Name]] = SimpleIdentityMap.empty
private var cache: SimpleIdentityMap[NameFilter, Set[Name]] | Null = SimpleIdentityMap.empty

final def isValid(using Context): Boolean =
cache != null && isValidAt(ctx.phase)
Expand All @@ -2823,15 +2824,15 @@ object SymDenotations {

def apply(keepOnly: NameFilter, clsd: ClassDenotation)(implicit onBehalf: MemberNames, ctx: Context) = {
assert(isValid)
val cached = cache(keepOnly)
val cached = cache.nn(keepOnly)
try
if (cached != null) cached
else {
locked = true
val computed =
try clsd.computeMemberNames(keepOnly)(this, ctx)
finally locked = false
cache = cache.updated(keepOnly, computed)
cache = cache.nn.updated(keepOnly, computed)
computed
}
finally addDependent(onBehalf)
Expand All @@ -2841,7 +2842,7 @@ object SymDenotations {
}

private class BaseDataImpl(createdAt: Period) extends InheritedCacheImpl(createdAt) with BaseData {
private var cache: (List[ClassSymbol], BaseClassSet) = null
private var cache: (List[ClassSymbol], BaseClassSet) | Null = null

private var valid = true
private var locked = false
Expand All @@ -2866,7 +2867,7 @@ object SymDenotations {
: (List[ClassSymbol], BaseClassSet) = {
assert(isValid)
try
if (cache != null) cache
if (cache != null) cache.uncheckedNN
else {
if (locked) throw CyclicReference(clsd)
locked = true
Expand Down
Loading

0 comments on commit f0e4a8e

Please sign in to comment.