Skip to content

Commit

Permalink
Fix symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
noti0na1 committed Jan 7, 2022
1 parent af86110 commit 9923fbc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
30 changes: 15 additions & 15 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ object SymDenotations {
/** `fullName` where `.' is the separator character */
def fullName(using Context): Name = fullNameSeparated(QualifiedName)

private var myTargetName: Name = null
private var myTargetName: Name | Null = null

private def computeTargetName(targetNameAnnot: Option[Annotation])(using Context): Name =
targetNameAnnot match
Expand Down Expand Up @@ -529,9 +529,9 @@ object SymDenotations {
else carrier.getAnnotation(defn.TargetNameAnnot)
myTargetName = computeTargetName(targetNameAnnot)
if name.is(SuperAccessorName) then
myTargetName = myTargetName.unmangle(List(ExpandedName, SuperAccessorName, ExpandPrefixName))
myTargetName = myTargetName.nn.unmangle(List(ExpandedName, SuperAccessorName, ExpandPrefixName))

myTargetName
myTargetName.nn

// ----- Tests -------------------------------------------------

Expand Down Expand Up @@ -834,7 +834,7 @@ object SymDenotations {
* As a side effect, drop Local flags of members that are not accessed via the ThisType
* of their owner.
*/
final def isAccessibleFrom(pre: Type, superAccess: Boolean = false, whyNot: StringBuffer = null)(using Context): Boolean = {
final def isAccessibleFrom(pre: Type, superAccess: Boolean = false, whyNot: StringBuffer | Null = null)(using Context): Boolean = {

/** Are we inside definition of `boundary`?
* If this symbol is Java defined, package structure is interpreted to be flat.
Expand Down Expand Up @@ -864,7 +864,7 @@ object SymDenotations {
/** Is protected access to target symbol permitted? */
def isProtectedAccessOK: Boolean =
inline def fail(str: String): false =
if whyNot != null then whyNot.append(str)
if whyNot != null then whyNot.nn.append(str)
false
val cls = owner.enclosingSubClass
if !cls.exists then
Expand Down Expand Up @@ -1240,7 +1240,7 @@ object SymDenotations {
.map(tpd.definedSym)
.find(_.name == name)
.getOrElse(NoSymbol)
else if (ctx.scope == null)
else if ((ctx.scope: Scope | Null) == null) // TODO
NoSymbol
else if (ctx.scope.lookup(this.name) == symbol)
ctx.scope.lookup(name)
Expand Down Expand Up @@ -1534,10 +1534,10 @@ object SymDenotations {
owner: Symbol = this.owner,
name: Name = this.name,
initFlags: FlagSet = UndefinedFlags,
info: Type = null,
privateWithin: Symbol = null,
annotations: List[Annotation] = null,
rawParamss: List[List[Symbol]] = null)(
info: Type | Null = null,
privateWithin: Symbol | Null = null,
annotations: List[Annotation] | Null = null,
rawParamss: List[List[Symbol]] | Null = null)(
using Context): SymDenotation = {
// simulate default parameters, while also passing implicit context ctx to the default values
val initFlags1 = (if (initFlags != UndefinedFlags) initFlags else this.flags)
Expand All @@ -1562,7 +1562,7 @@ object SymDenotations {
/** Are `info1` and `info2` ClassInfo types with different parents?
* @param completersMatter if `true`, consider parents changed if `info1` or `info2 `is a type completer
*/
protected def changedClassParents(info1: Type, info2: Type, completersMatter: Boolean): Boolean =
protected def changedClassParents(info1: Type | Null, info2: Type | Null, completersMatter: Boolean): Boolean =
info2 match {
case info2: ClassInfo =>
info1 match {
Expand Down Expand Up @@ -1704,15 +1704,15 @@ object SymDenotations {

// ----- caches -------------------------------------------------------

private var myTypeParams: List[TypeSymbol] = null
private var myTypeParams: List[TypeSymbol] | Null = null
private var fullNameCache: SimpleIdentityMap[QualifiedNameKind, Name] = SimpleIdentityMap.empty

private var myMemberCache: EqHashMap[Name, PreDenotation] = null
private var myMemberCache: EqHashMap[Name, PreDenotation] | Null = null
private var myMemberCachePeriod: Period = Nowhere

/** A cache from types T to baseType(T, C) */
type BaseTypeMap = EqHashMap[CachedType, Type]
private var myBaseTypeCache: BaseTypeMap = null
private var myBaseTypeCache: BaseTypeMap | Null = null
private var myBaseTypeCachePeriod: Period = Nowhere

private var baseDataCache: BaseData = BaseData.None
Expand Down Expand Up @@ -1753,7 +1753,7 @@ object SymDenotations {
invalidateMemberNamesCache()

def invalidateMemberCachesFor(sym: Symbol)(using Context): Unit =
if myMemberCache != null then myMemberCache.remove(sym.name)
if myMemberCache != null then myMemberCache.uncheckedNN.remove(sym.name)
if !sym.flagsUNSAFE.is(Private) then
invalidateMemberNamesCache()
if sym.isWrappedToplevelDef then
Expand Down
29 changes: 15 additions & 14 deletions compiler/src/dotty/tools/dotc/core/Symbols.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._
import Names._
Expand Down Expand Up @@ -74,7 +74,7 @@ object Symbols {

/** The tree defining the symbol at pickler time, EmptyTree if none was retained */
def defTree: Tree =
if (myDefTree == null) tpd.EmptyTree else myDefTree
if (myDefTree == null) tpd.EmptyTree else myDefTree.nn

/** Set defining tree if this symbol retains its definition tree */
def defTree_=(tree: Tree)(using Context): Unit =
Expand All @@ -91,7 +91,7 @@ object Symbols {
ctx.settings.YcheckInit.value // initialization check

/** The last denotation of this symbol */
private var lastDenot: SymDenotation = _
private var lastDenot: SymDenotation | Null = _
private var checkedPeriod: Period = Nowhere

private[core] def invalidateDenotCache(): Unit = { checkedPeriod = Nowhere }
Expand All @@ -106,7 +106,7 @@ object Symbols {
/** The current denotation of this symbol */
final def denot(using Context): SymDenotation = {
util.Stats.record("Symbol.denot")
val lastd = lastDenot
val lastd = lastDenot.nn
if (checkedPeriod == ctx.period) lastd
else computeDenot(lastd)
}
Expand All @@ -128,14 +128,14 @@ object Symbols {

/** The original denotation of this symbol, without forcing anything */
final def originDenotation: SymDenotation =
lastDenot.initial
lastDenot.nn.initial

/** The last known denotation of this symbol, without going through `current` */
final def lastKnownDenotation: SymDenotation =
lastDenot
lastDenot.nn

private[core] def defRunId: RunId =
if (lastDenot == null) NoRunId else lastDenot.validFor.runId
if (lastDenot == null) NoRunId else lastDenot.nn.validFor.runId

/** Does this symbol come from a currently compiled source file? */
final def isDefinedInCurrentRun(using Context): Boolean =
Expand All @@ -150,17 +150,18 @@ object Symbols {

/** Is symbol valid in current run? */
final def isValidInCurrentRun(using Context): Boolean =
(lastDenot.validFor.runId == ctx.runId || stillValid(lastDenot)) &&
(lastDenot.symbol eq this)
val d = lastDenot.nn
(d.validFor.runId == ctx.runId || stillValid(d)) &&
(d.symbol eq this)
// the last condition is needed because under ctx.staleOK overwritten
// members keep denotations pointing to the new symbol, so the validity
// periods check out OK. But once a package member is overridden it is not longer
// valid. If the option would be removed, the check would be no longer needed.

final def isTerm(using Context): Boolean =
(if (defRunId == ctx.runId) lastDenot else denot).isTerm
(if (defRunId == ctx.runId) lastDenot.nn else denot).isTerm
final def isType(using Context): Boolean =
(if (defRunId == ctx.runId) lastDenot else denot).isType
(if (defRunId == ctx.runId) lastDenot.nn else denot).isType
final def asTerm(using Context): TermSymbol = {
assert(isTerm, s"asTerm called on not-a-Term $this" );
asInstanceOf[TermSymbol]
Expand Down Expand Up @@ -189,14 +190,14 @@ object Symbols {

/** The symbol's signature if it is completed or a method, NotAMethod otherwise. */
final def signature(using Context): Signature =
if (lastDenot != null && (lastDenot.isCompleted || lastDenot.is(Method)))
if (lastDenot != null && (lastDenot.uncheckedNN.isCompleted || lastDenot.uncheckedNN.is(Method)))
denot.signature
else
Signature.NotAMethod

/** Special cased here, because it may be used on naked symbols in substituters */
final def isStatic(using Context): Boolean =
lastDenot != null && lastDenot.initial.isStatic
lastDenot != null && lastDenot.uncheckedNN.initial.isStatic

/** This symbol entered into owner's scope (owner must be a class). */
final def entered(using Context): this.type = {
Expand Down Expand Up @@ -264,7 +265,7 @@ object Symbols {
* Overridden in ClassSymbol
*/
def associatedFile(using Context): AbstractFile | Null =
if (lastDenot == null) null else lastDenot.topLevelClass.associatedFile
if (lastDenot == null) null else lastDenot.uncheckedNN.topLevelClass.associatedFile

/** The class file from which this class was generated, null if not applicable. */
final def binaryFile(using Context): AbstractFile | Null = {
Expand Down

0 comments on commit 9923fbc

Please sign in to comment.