Skip to content

Commit db7d2c4

Browse files
committed
Rewrite type for SimpleIdenMap
1 parent fb4ce66 commit db7d2c4

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
@@ -304,7 +304,7 @@ object Contexts {
304304
def getFile(name: String): AbstractFile = getFile(name.toTermName)
305305

306306

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

309309
private def lookup(key: Phase | SourceFile): Context | Null =
310310
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
@@ -1781,7 +1781,7 @@ class Definitions {
17811781
def isValueSubClass(sym1: Symbol, sym2: Symbol): Boolean =
17821782
valueTypeEnc(sym2.asClass.name) % valueTypeEnc(sym1.asClass.name) == 0
17831783

1784-
@tu lazy val specialErasure: SimpleIdentityMap[Symbol, ClassSymbol | Null] =
1784+
@tu lazy val specialErasure: SimpleIdentityMap[Symbol, ClassSymbol] =
17851785
SimpleIdentityMap.empty[Symbol]
17861786
.updated(AnyClass, ObjectClass)
17871787
.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
@@ -61,8 +61,8 @@ sealed abstract class GadtConstraint extends Showable {
6161

6262
final class ProperGadtConstraint private(
6363
private var myConstraint: Constraint,
64-
private var mapping: SimpleIdentityMap[Symbol, TypeVar | Null],
65-
private var reverseMapping: SimpleIdentityMap[TypeParamRef, Symbol | Null],
64+
private var mapping: SimpleIdentityMap[Symbol, TypeVar],
65+
private var reverseMapping: SimpleIdentityMap[TypeParamRef, Symbol],
6666
private var wasConstrained: Boolean
6767
) extends GadtConstraint with ConstraintHandling {
6868
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}
@@ -104,13 +106,13 @@ object Implicits:
104106
*/
105107
def companionRefs: TermRefSet = TermRefSet.empty
106108

107-
private var mySingletonClass: ClassSymbol = null
109+
private var mySingletonClass: ClassSymbol | Null = null
108110

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

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

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

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

333335
private def combineEligibles(ownEligible: List[Candidate], outerEligible: List[Candidate]): List[Candidate] =
@@ -369,7 +371,7 @@ object Implicits:
369371
if (monitored) record(s"check eligible refs in irefCtx", refs.length)
370372
val ownEligible = filterMatching(tp)
371373
if isOuterMost then ownEligible
372-
else combineEligibles(ownEligible, outerImplicits.eligible(tp))
374+
else combineEligibles(ownEligible, outerImplicits.uncheckedNN.eligible(tp))
373375
}
374376

375377
override def isAccessible(ref: TermRef)(using Context): Boolean =
@@ -386,9 +388,9 @@ object Implicits:
386388
def exclude(root: Symbol): ContextualImplicits =
387389
if (this == NoContext.implicits) this
388390
else {
389-
val outerExcluded = outerImplicits exclude root
391+
val outerExcluded = outerImplicits.uncheckedNN exclude root
390392
if (irefCtx.importInfo.site.termSymbol == root) outerExcluded
391-
else if (outerExcluded eq outerImplicits) this
393+
else if (outerExcluded eqn outerImplicits) this
392394
else new ContextualImplicits(refs, outerExcluded, isImport)(irefCtx)
393395
}
394396
}
@@ -841,7 +843,7 @@ trait Implicits:
841843
}
842844
}
843845

844-
private var synthesizer: Synthesizer = null
846+
private var synthesizer: Synthesizer | Null = null
845847

846848
/** Find an implicit argument for parameter `formal`.
847849
* Return a failure as a SearchFailureType in the type of the returned tree.
@@ -853,7 +855,7 @@ trait Implicits:
853855
if fail.isAmbiguous then failed
854856
else
855857
if synthesizer == null then synthesizer = Synthesizer(this)
856-
synthesizer.tryAll(formal, span).orElse(failed)
858+
synthesizer.uncheckedNN.tryAll(formal, span).orElse(failed)
857859

858860
/** Search an implicit argument and report error if not found */
859861
def implicitArgTree(formal: Type, span: Span)(using Context): Tree = {
@@ -1666,11 +1668,11 @@ final class SearchRoot extends SearchHistory:
16661668
var nestedSearches: Int = 0
16671669

16681670
/** The dictionary of recursive implicit types and corresponding terms for this search. */
1669-
var myImplicitDictionary: mutable.Map[Type, (TermRef, tpd.Tree)] = null
1671+
var myImplicitDictionary: mutable.Map[Type, (TermRef, tpd.Tree)] | Null = null
16701672
private def implicitDictionary =
16711673
if myImplicitDictionary == null then
16721674
myImplicitDictionary = mutable.Map.empty[Type, (TermRef, tpd.Tree)]
1673-
myImplicitDictionary
1675+
myImplicitDictionary.uncheckedNN
16741676

16751677
/**
16761678
* Link a reference to an under-construction implicit for the provided type to its
@@ -1849,10 +1851,12 @@ sealed class TermRefSet(using Context):
18491851
if !that.isEmpty then that.foreach(+=)
18501852

18511853
def foreach[U](f: TermRef => U): Unit =
1852-
elems.forEach((sym: TermSymbol, prefixes: Type | List[Type]) =>
1854+
// TODO
1855+
def handle(sym: TermSymbol | Null, prefixes: Type | List[Type] | Null): Unit =
18531856
prefixes match
1854-
case prefix: Type => f(TermRef(prefix, sym))
1855-
case prefixes: List[Type] => prefixes.foreach(pre => f(TermRef(pre, sym))))
1857+
case prefix: Type => f(TermRef(prefix, sym.uncheckedNN))
1858+
case prefixes: List[Type] => prefixes.foreach(pre => f(TermRef(pre, sym.uncheckedNN)))
1859+
elems.forEach(handle)
18561860

18571861
// used only for debugging
18581862
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._
@@ -1361,7 +1363,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
13611363
// the binding is to be maximized iff it only occurs contravariantly in the type
13621364
val wasToBeMinimized: Boolean = {
13631365
val v = syms(trSym)
1364-
if (v ne null) v else false
1366+
if (v != null) v else false
13651367
}
13661368
syms.updated(trSym, wasToBeMinimized || variance >= 0 : java.lang.Boolean)
13671369
case _ =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2925,7 +2925,7 @@ class Typer extends Namer
29252925

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

0 commit comments

Comments
 (0)