Skip to content

Commit c9e3dff

Browse files
committed
Rewrite type for SimpleIdenMap
1 parent 54b61d2 commit c9e3dff

16 files changed

+114
-88
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ object Contexts {
308308
def getFile(name: String): AbstractFile = getFile(name.toTermName)
309309

310310

311-
private var related: SimpleIdentityMap[Phase | SourceFile, Context | Null] | Null = null
311+
private var related: SimpleIdentityMap[Phase | SourceFile, Context] | Null = null
312312

313313
private def lookup(key: Phase | SourceFile): Context | Null =
314314
util.Stats.record("Context.related.lookup")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,7 @@ class Definitions {
17841784
def isValueSubClass(sym1: Symbol, sym2: Symbol): Boolean =
17851785
valueTypeEnc(sym2.asClass.name) % valueTypeEnc(sym1.asClass.name) == 0
17861786

1787-
@tu lazy val specialErasure: SimpleIdentityMap[Symbol, ClassSymbol | Null] =
1787+
@tu lazy val specialErasure: SimpleIdentityMap[Symbol, ClassSymbol] =
17881788
SimpleIdentityMap.empty[Symbol]
17891789
.updated(AnyClass, ObjectClass)
17901790
.updated(MatchableClass, ObjectClass)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ sealed abstract class GadtConstraint extends Showable {
6262

6363
final class ProperGadtConstraint private(
6464
private var myConstraint: Constraint,
65-
private var mapping: SimpleIdentityMap[Symbol, TypeVar | Null],
66-
private var reverseMapping: SimpleIdentityMap[TypeParamRef, Symbol | Null],
65+
private var mapping: SimpleIdentityMap[Symbol, TypeVar],
66+
private var reverseMapping: SimpleIdentityMap[TypeParamRef, Symbol],
6767
private var wasConstrained: Boolean
6868
) extends GadtConstraint with ConstraintHandling {
6969
import dotty.tools.dotc.config.Printers.{gadts, gadtsConstr}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import annotation.internal.sharable
1717

1818
object OrderingConstraint {
1919

20-
type ArrayValuedMap[T] = SimpleIdentityMap[TypeLambda, Array[T] | Null]
20+
type ArrayValuedMap[T] = SimpleIdentityMap[TypeLambda, Array[T]]
2121

2222
/** The type of `OrderingConstraint#boundsMap` */
2323
type ParamBounds = ArrayValuedMap[Type]

compiler/src/dotty/tools/dotc/typer/Docstrings.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package dotty.tools
22
package dotc
33
package typer
44

5+
import scala.language.{unsafeNulls => _}
6+
57
import core._
68
import Contexts._, Symbols._, Decorators._, Comments.{_, given}
79
import ast.tpd

compiler/src/dotty/tools/dotc/typer/Dynamic.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package dotty.tools
22
package dotc
33
package typer
44

5+
import scala.language.{unsafeNulls => _}
6+
57
import dotty.tools.dotc.ast.Trees._
68
import dotty.tools.dotc.ast.tpd
79
import dotty.tools.dotc.ast.untpd

compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package dotty.tools
22
package dotc
33
package typer
44

5+
import scala.language.{unsafeNulls => _}
6+
57
import ast._
68
import core._
79
import Types._, ProtoTypes._, Contexts._, Decorators._, Denotations._, Symbols._
@@ -294,7 +296,7 @@ class ImplicitSearchError(
294296
}
295297

296298
"""\$\{\s*([^}\s]+)\s*\}""".r.replaceAllIn(raw, (_: Regex.Match) match {
297-
case Regex.Groups(v) => quoteReplacement(translate(v).getOrElse(""))
299+
case Regex.Groups(v) => quoteReplacement(translate(v).getOrElse("")).nn
298300
})
299301
}
300302

compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package dotty.tools
22
package dotc
33
package typer
44

5+
import scala.language.{unsafeNulls => _}
6+
57
import core._
68
import ast.{Trees, untpd, tpd}
79
import Contexts._

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package dotty.tools
22
package dotc
33
package typer
44

5+
import scala.language.{unsafeNulls => _}
6+
57
import backend.sjs.JSDefinitions
68
import core._
79
import ast.{Trees, TreeTypeMap, untpd, tpd, DesugarEnums}
@@ -105,13 +107,13 @@ object Implicits:
105107
*/
106108
def companionRefs: TermRefSet = TermRefSet.empty
107109

108-
private var mySingletonClass: ClassSymbol = null
110+
private var mySingletonClass: ClassSymbol | Null = null
109111

110112
/** Widen type so that it is neither a singleton type nor a type that inherits from scala.Singleton. */
111113
private def widenSingleton(tp: Type)(using Context): Type = {
112114
if (mySingletonClass == null) mySingletonClass = defn.SingletonClass
113115
val wtp = tp.widenSingleton
114-
if (wtp.derivesFrom(mySingletonClass)) defn.AnyType else wtp
116+
if (wtp.derivesFrom(mySingletonClass.uncheckedNN)) defn.AnyType else wtp
115117
}
116118

117119
protected def isAccessible(ref: TermRef)(using Context): Boolean
@@ -272,7 +274,7 @@ object Implicits:
272274
* @param companionRefs the companion objects in the implicit scope.
273275
*/
274276
class OfTypeImplicits(tp: Type, override val companionRefs: TermRefSet)(initctx: Context) extends ImplicitRefs(initctx) {
275-
assert(initctx.typer != null)
277+
// assert(initctx.typer != null)
276278
implicits.println(i"implicit scope of type $tp = ${companionRefs.showAsList}%, %")
277279
@threadUnsafe lazy val refs: List[ImplicitRef] = {
278280
val buf = new mutable.ListBuffer[TermRef]
@@ -312,23 +314,23 @@ object Implicits:
312314
* Scala2 mode, since we do not want to change the implicit disambiguation then.
313315
*/
314316
override val level: Int =
315-
def isSameOwner = irefCtx.owner eq outerImplicits.irefCtx.owner
316-
def isSameScope = irefCtx.scope eq outerImplicits.irefCtx.scope
317+
def isSameOwner = irefCtx.owner eq outerImplicits.uncheckedNN.irefCtx.owner
318+
def isSameScope = irefCtx.scope eq outerImplicits.uncheckedNN.irefCtx.scope
317319
def isLazyImplicit = refs.head.implicitName.is(LazyImplicitName)
318320

319321
if outerImplicits == null then 1
320322
else if migrateTo3(using irefCtx)
321323
|| isSameOwner && (isImport || isSameScope && !isLazyImplicit)
322-
then outerImplicits.level
323-
else outerImplicits.level + 1
324+
then outerImplicits.uncheckedNN.level
325+
else outerImplicits.uncheckedNN.level + 1
324326
end level
325327

326328
/** Is this the outermost implicits? This is the case if it either the implicits
327329
* of NoContext, or the last one before it.
328330
*/
329331
private def isOuterMost = {
330332
val finalImplicits = NoContext.implicits
331-
(this eq finalImplicits) || (outerImplicits eq finalImplicits)
333+
(this eq finalImplicits) || (outerImplicits eqn finalImplicits)
332334
}
333335

334336
private def combineEligibles(ownEligible: List[Candidate], outerEligible: List[Candidate]): List[Candidate] =
@@ -370,7 +372,7 @@ object Implicits:
370372
if (monitored) record(s"check eligible refs in irefCtx", refs.length)
371373
val ownEligible = filterMatching(tp)
372374
if isOuterMost then ownEligible
373-
else combineEligibles(ownEligible, outerImplicits.eligible(tp))
375+
else combineEligibles(ownEligible, outerImplicits.uncheckedNN.eligible(tp))
374376
}
375377

376378
override def isAccessible(ref: TermRef)(using Context): Boolean =
@@ -387,9 +389,9 @@ object Implicits:
387389
def exclude(root: Symbol): ContextualImplicits =
388390
if (this == NoContext.implicits) this
389391
else {
390-
val outerExcluded = outerImplicits exclude root
392+
val outerExcluded = outerImplicits.uncheckedNN exclude root
391393
if (irefCtx.importInfo.site.termSymbol == root) outerExcluded
392-
else if (outerExcluded eq outerImplicits) this
394+
else if (outerExcluded eqn outerImplicits) this
393395
else new ContextualImplicits(refs, outerExcluded, isImport)(irefCtx)
394396
}
395397
}
@@ -848,7 +850,7 @@ trait Implicits:
848850
}
849851
}
850852

851-
private var synthesizer: Synthesizer = null
853+
private var synthesizer: Synthesizer | Null = null
852854

853855
/** Find an implicit argument for parameter `formal`.
854856
* Return a failure as a SearchFailureType in the type of the returned tree.
@@ -860,7 +862,7 @@ trait Implicits:
860862
if fail.isAmbiguous then failed
861863
else
862864
if synthesizer == null then synthesizer = Synthesizer(this)
863-
synthesizer.tryAll(formal, span).orElse(failed)
865+
synthesizer.uncheckedNN.tryAll(formal, span).orElse(failed)
864866

865867
/** Search an implicit argument and report error if not found */
866868
def implicitArgTree(formal: Type, span: Span)(using Context): Tree = {
@@ -1673,11 +1675,11 @@ final class SearchRoot extends SearchHistory:
16731675
var nestedSearches: Int = 0
16741676

16751677
/** The dictionary of recursive implicit types and corresponding terms for this search. */
1676-
var myImplicitDictionary: mutable.Map[Type, (TermRef, tpd.Tree)] = null
1678+
var myImplicitDictionary: mutable.Map[Type, (TermRef, tpd.Tree)] | Null = null
16771679
private def implicitDictionary =
16781680
if myImplicitDictionary == null then
16791681
myImplicitDictionary = mutable.Map.empty[Type, (TermRef, tpd.Tree)]
1680-
myImplicitDictionary
1682+
myImplicitDictionary.uncheckedNN
16811683

16821684
/**
16831685
* Link a reference to an under-construction implicit for the provided type to its
@@ -1856,10 +1858,12 @@ sealed class TermRefSet(using Context):
18561858
if !that.isEmpty then that.foreach(+=)
18571859

18581860
def foreach[U](f: TermRef => U): Unit =
1859-
elems.forEach((sym: TermSymbol, prefixes: Type | List[Type]) =>
1861+
// TODO
1862+
def handle(sym: TermSymbol | Null, prefixes: Type | List[Type] | Null): Unit =
18601863
prefixes match
1861-
case prefix: Type => f(TermRef(prefix, sym))
1862-
case prefixes: List[Type] => prefixes.foreach(pre => f(TermRef(pre, sym))))
1864+
case prefix: Type => f(TermRef(prefix, sym.uncheckedNN))
1865+
case prefixes: List[Type] => prefixes.foreach(pre => f(TermRef(pre, sym.uncheckedNN)))
1866+
elems.forEach(handle)
18631867

18641868
// used only for debugging
18651869
def showAsList: List[TermRef] = {

compiler/src/dotty/tools/dotc/typer/ImportInfo.scala

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package dotty.tools
22
package dotc
33
package typer
44

5+
import scala.language.{unsafeNulls => _}
6+
57
import ast.{tpd, untpd}
68
import ast.Trees._
79
import core._
@@ -67,9 +69,9 @@ class ImportInfo(symf: Context ?=> Symbol,
6769
mySym = symf
6870
assert(mySym != null)
6971
}
70-
mySym
72+
mySym.uncheckedNN
7173
}
72-
private var mySym: Symbol = _
74+
private var mySym: Symbol | Null = _
7375

7476
/** The (TermRef) type of the qualifier of the import clause */
7577
def site(using Context): Type = importSym.info match {
@@ -78,23 +80,23 @@ class ImportInfo(symf: Context ?=> Symbol,
7880
}
7981

8082
/** The names that are excluded from any wildcard import */
81-
def excluded: Set[TermName] = { ensureInitialized(); myExcluded }
83+
def excluded: Set[TermName] = { ensureInitialized(); myExcluded.nn }
8284

8385
/** A mapping from original to renamed names */
84-
def forwardMapping: SimpleIdentityMap[TermName, TermName] = { ensureInitialized(); myForwardMapping }
86+
def forwardMapping: SimpleIdentityMap[TermName, TermName] = { ensureInitialized(); myForwardMapping.nn }
8587

8688
/** A mapping from renamed to original names */
87-
def reverseMapping: SimpleIdentityMap[TermName, TermName] = { ensureInitialized(); myReverseMapping }
89+
def reverseMapping: SimpleIdentityMap[TermName, TermName] = { ensureInitialized(); myReverseMapping.nn }
8890

8991
/** Does the import clause contain wildcard selectors (both `_` and `given` count)? */
9092
def isWildcardImport: Boolean = { ensureInitialized(); myWildcardImport }
9193

9294
/** Does the import clause have at least one `given` selector? */
9395
def isGivenImport: Boolean = { ensureInitialized(); myGivenImport }
9496

95-
private var myExcluded: Set[TermName] = null
96-
private var myForwardMapping: SimpleIdentityMap[TermName, TermName] = null
97-
private var myReverseMapping: SimpleIdentityMap[TermName, TermName] = null
97+
private var myExcluded: Set[TermName] | Null = null
98+
private var myForwardMapping: SimpleIdentityMap[TermName, TermName] | Null = null
99+
private var myReverseMapping: SimpleIdentityMap[TermName, TermName] | Null = null
98100
private var myWildcardImport: Boolean = false
99101
private var myGivenImport: Boolean = false
100102
private var myWildcardBound: Type = NoType
@@ -111,10 +113,10 @@ class ImportInfo(symf: Context ?=> Symbol,
111113
if sel.isGiven then myGivenImport = true
112114
else
113115
if sel.rename != sel.name then
114-
myExcluded += sel.name
116+
myExcluded = myExcluded.nn + sel.name
115117
if sel.rename != nme.WILDCARD then
116-
myForwardMapping = myForwardMapping.updated(sel.name, sel.rename)
117-
myReverseMapping = myReverseMapping.updated(sel.rename, sel.name)
118+
myForwardMapping = myForwardMapping.uncheckedNN.updated(sel.name, sel.rename)
119+
myReverseMapping = myReverseMapping.uncheckedNN.updated(sel.rename, sel.name)
118120

119121
/** The upper bound for `given` wildcards, or `Nothing` if there are none */
120122
def givenBound(using Context) =
@@ -151,9 +153,9 @@ class ImportInfo(symf: Context ?=> Symbol,
151153
else
152154
for
153155
renamed <- reverseMapping.keys
154-
denot <- pre.member(reverseMapping(renamed)).altsWith(_.isOneOf(GivenOrImplicitVal))
156+
denot <- pre.member(reverseMapping(renamed).nn).altsWith(_.isOneOf(GivenOrImplicitVal))
155157
yield
156-
val original = reverseMapping(renamed)
158+
val original = reverseMapping(renamed).nn
157159
val ref = TermRef(pre, original, denot)
158160
if renamed == original then ref
159161
else RenamedImplicitRef(ref, renamed)
@@ -179,11 +181,11 @@ class ImportInfo(symf: Context ?=> Symbol,
179181
if maybeShadowsRoot && defn.rootImportTypes.exists(_.symbol == sym) then sym
180182
else NoSymbol
181183
assert(myUnimported != null)
182-
myUnimported
184+
myUnimported.uncheckedNN
183185

184186
private val isLanguageImport: Boolean = untpd.languageImport(qualifier).isDefined
185187

186-
private var myUnimported: Symbol = _
188+
private var myUnimported: Symbol | Null = _
187189

188190
private var featureCache: SimpleIdentityMap[TermName, java.lang.Boolean] = SimpleIdentityMap.empty
189191

@@ -222,9 +224,10 @@ class ImportInfo(symf: Context ?=> Symbol,
222224
case None =>
223225
var c = ctx.outer
224226
while c.importInfo eq ctx.importInfo do c = c.outer
225-
(c.importInfo != null) && c.importInfo.featureImported(feature)(using c)
227+
// TODO
228+
((c.importInfo: ImportInfo | Null) != null) && c.importInfo.featureImported(feature)(using c)
226229
)
227-
featureCache(feature)
230+
featureCache(feature).nn
228231

229232
def toText(printer: Printer): Text = printer.toText(this)
230233
}

compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package dotty.tools
22
package dotc
33
package typer
44

5+
import scala.language.{unsafeNulls => _}
6+
57
import backend.sjs.JSDefinitions
68
import core._
79
import Contexts._, Types._, Symbols._, Names._, Decorators._, ProtoTypes._

compiler/src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package dotty.tools
22
package dotc
33
package typer
44

5+
import scala.language.{unsafeNulls => _}
6+
57
import core._
68
import ast._
79
import Contexts._, Types._, Flags._, Symbols._

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package dotty.tools
22
package dotc
33
package typer
44

5+
import scala.language.{unsafeNulls => _}
6+
57
import ast.{TreeInfo, tpd, _}
68
import Trees._
79
import core._
@@ -1364,7 +1366,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
13641366
// the binding is to be maximized iff it only occurs contravariantly in the type
13651367
val wasToBeMinimized: Boolean = {
13661368
val v = syms(trSym)
1367-
if (v ne null) v else false
1369+
if (v != null) v else false
13681370
}
13691371
syms.updated(trSym, wasToBeMinimized || variance >= 0 : java.lang.Boolean)
13701372
case _ =>

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2943,7 +2943,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
29432943

29442944
def typedStats(stats: List[untpd.Tree], exprOwner: Symbol)(using Context): (List[Tree], Context) = {
29452945
val buf = new mutable.ListBuffer[Tree]
2946-
var enumContexts: SimpleIdentityMap[Symbol, Context | Null] = SimpleIdentityMap.empty
2946+
var enumContexts: SimpleIdentityMap[Symbol, Context] = SimpleIdentityMap.empty
29472947
val initialNotNullInfos = ctx.notNullInfos
29482948
// A map from `enum` symbols to the contexts enclosing their definitions
29492949
@tailrec def traverse(stats: List[untpd.Tree])(using Context): (List[Tree], Context) = stats match {

0 commit comments

Comments
 (0)