Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ object Trees {
/** The type of the tree. In case of an untyped tree,
* an UnAssignedTypeException is thrown. (Overridden by empty trees)
*/
final def tpe: T =
if myTpe == null then throw UnAssignedTypeException(this)
myTpe.uncheckedNN
final def tpe: T = myTpe match
case null => throw UnAssignedTypeException(this)
case t => t

/** Copy `tpe` attribute from tree `from` into this tree, independently
* whether it is null or not.
Expand Down Expand Up @@ -292,10 +292,11 @@ object Trees {
trait DefTree[+T <: Untyped] extends DenotingTree[T] {
type ThisTree[+T <: Untyped] <: DefTree[T]

private var myMods: untpd.Modifiers | Null = uninitialized
private var myMods: untpd.Modifiers | Null = null

private[dotc] def rawMods: untpd.Modifiers =
if (myMods == null) untpd.EmptyModifiers else myMods.uncheckedNN
private[dotc] def rawMods: untpd.Modifiers = myMods match
case null => untpd.EmptyModifiers
case mods => mods

def withAnnotations(annots: List[untpd.Tree]): ThisTree[Untyped] = withMods(rawMods.withAnnotations(annots))

Expand Down
6 changes: 2 additions & 4 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import Spans.*

import scala.annotation.tailrec
import scala.collection.{immutable, mutable}
import scala.compiletime.uninitialized

/** Some creators for typed trees */
object tpd extends Trees.Instance[Type] with TypedTreeInfo {
Expand Down Expand Up @@ -1373,13 +1372,12 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
trait TreeProvider {
protected def computeRootTrees(using Context): List[Tree]

private var myTrees: List[Tree] | Null = uninitialized
private var myTrees: List[Tree] | Null = null

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no point in uninitialized for explicitly nullable stuff


/** Get trees defined by this provider. Cache them if -Yretain-trees is set. */
def rootTrees(using Context): List[Tree] =
if (ctx.settings.YretainTrees.value) {
if (myTrees == null) myTrees = computeRootTrees
myTrees.uncheckedNN
initialize(myTrees, myTrees = _, computeRootTrees)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(scroll to the last file in this diff view to see the definition of this -- it's as you'd expect, hopefully)

}
else computeRootTrees

Expand Down
7 changes: 2 additions & 5 deletions compiler/src/dotty/tools/dotc/cc/Capability.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import util.common.alwaysTrue
import scala.collection.mutable
import CCState.*
import Periods.{NoRunId, RunId, RunWidth}
import compiletime.uninitialized
import StdNames.nme
import CaptureSet.{Refs, emptyRefs, VarState}
import Annotations.Annotation
Expand Down Expand Up @@ -341,7 +340,7 @@ object Capabilities:
*/
trait Capability extends Showable:

private var myCaptureSet: CaptureSet | Null = uninitialized
private var myCaptureSet: CaptureSet | Null = null
private var captureSetValid: Validity = invalid
private var mySingletonCaptureSet: CaptureSet.Const | Null = null
private var myDerived: List[DerivedCapability] = Nil
Expand Down Expand Up @@ -602,9 +601,7 @@ object Capabilities:

/** The capture set consisting of exactly this reference */
def singletonCaptureSet(using Context): CaptureSet.Const =
if mySingletonCaptureSet == null then
mySingletonCaptureSet = CaptureSet(this)
mySingletonCaptureSet.uncheckedNN
initialize(mySingletonCaptureSet, mySingletonCaptureSet = _, CaptureSet(this))

/** The capture set of the type underlying this reference */
def captureSetOfInfo(using Context): CaptureSet =
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/ConstraintRunInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import scala.compiletime.uninitialized

trait ConstraintRunInfo { self: Run =>
private var maxSize = 0
private var maxConstraint: Constraint | Null = uninitialized
private var maxConstraint: Constraint | Null = null
def recordConstraintSize(c: Constraint, size: Int): Unit =
if (size > maxSize) {
maxSize = size
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ object Contexts {
finally ctx.base.comparersInUse = saved
end comparing

@sharable val NoContext: Context = new FreshContext((null: ContextBase | Null).uncheckedNN) {
@sharable val NoContext: Context = new FreshContext(null.asInstanceOf[ContextBase]) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh. This is just wrong :(
(not that it was better before your PR)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know 😭

override val implicits: ContextualImplicits = new ContextualImplicits(Nil, null, false)(this: @unchecked)
setSource(NoSource)
}
Expand All @@ -913,7 +913,7 @@ object Contexts {
val initialCtx: Context = FreshContext.initial(this: @unchecked, settings)

/** The platform, initialized by `initPlatform()`. */
private var _platform: Platform | Null = uninitialized
private var _platform: Platform | Null = null

/** The platform */
def platform: Platform = {
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/core/GadtConstraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ class GadtConstraint private (
def apply(tp: Type): Type = externalize(tp, this)(using mapCtx)

def tvarOrError(sym: Symbol)(using Context): TypeVar =
mapping(sym).ensuring(_ != null, i"not a constrainable symbol: $sym").uncheckedNN
mapping(sym) match
case null => throw new AssertionError(i"not a constrainable symbol: $sym")
case m => m

@tailrec final def stripInternalTypeVar(tp: Type): Type = tp match
case tv: TypeVar =>
Expand Down
29 changes: 15 additions & 14 deletions compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -888,22 +888,23 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
i += 1
}

private var myUninstVars: mutable.ArrayBuffer[TypeVar] | Null = uninitialized
private var myUninstVars: mutable.ArrayBuffer[TypeVar] | Null = null

/** The uninstantiated typevars of this constraint */
def uninstVars: collection.Seq[TypeVar] = {
if (myUninstVars == null || myUninstVars.uncheckedNN.exists(_.isPermanentlyInstantiated)) {
myUninstVars = new mutable.ArrayBuffer[TypeVar]
boundsMap.foreachBinding { (poly, entries) =>
for (i <- 0 until paramCount(entries))
typeVar(entries, i) match {
case tv: TypeVar if !tv.isPermanentlyInstantiated && isBounds(entries(i)) => myUninstVars.uncheckedNN += tv
case _ =>
}
}
}
myUninstVars.uncheckedNN
}
def uninstVars: collection.Seq[TypeVar] =
myUninstVars match
case uv: mutable.ArrayBuffer[TypeVar] if !uv.exists(_.isPermanentlyInstantiated) => uv
case _ =>
val res = new mutable.ArrayBuffer[TypeVar]
myUninstVars = res
boundsMap.foreachBinding { (poly, entries) =>
for (i <- 0 until paramCount(entries))
typeVar(entries, i) match {
case tv: TypeVar if !tv.isPermanentlyInstantiated && isBounds(entries(i)) => res += tv
case _ =>
}
}
res

// ---------- Checking -----------------------------------------------

Expand Down
44 changes: 26 additions & 18 deletions compiler/src/dotty/tools/dotc/core/Scopes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import printing.Printer
import SymDenotations.NoDenotation

import collection.mutable
import scala.compiletime.uninitialized

object Scopes {

Expand All @@ -31,7 +30,7 @@ object Scopes {
* This value must be a power of two, so that the index of an element can
* be computed as element.hashCode & (hashTable.length - 1)
*/
inline val MinHashedScopeSize = 8
private inline val MinHashedScopeSize = 8

/** The maximal permissible number of recursions when creating
* a hashtable
Expand All @@ -42,7 +41,7 @@ object Scopes {
* the given name in the given context. Returns `NoSymbol` if the
* no symbol should be synthesized for the given name.
*/
type SymbolSynthesizer = Name => Context ?=> Symbol
private type SymbolSynthesizer = Name => Context ?=> Symbol

class ScopeEntry private[Scopes] (val name: Name, _sym: Symbol, val owner: Scope) {

Expand Down Expand Up @@ -135,7 +134,11 @@ object Scopes {
final def lookupAll(name: Name)(using Context): Iterator[Symbol] = new Iterator[Symbol] {
var e = lookupEntry(name)
def hasNext: Boolean = e != null
def next(): Symbol = { val r = e.nn.sym; e = lookupNextEntry(e.uncheckedNN); r }
def next(): Symbol = e match
case null => throw new NoSuchElementException()
case ee =>
e = lookupNextEntry(ee)
ee.sym
}

/** Does this scope contain a reference to `sym` when looking up `name`? */
Expand Down Expand Up @@ -179,8 +182,10 @@ object Scopes {
result.nn.enter(newName, sym)
else
drop()
// TODO: improve flow typing to handle this case
if result == null then this else result.uncheckedNN
// TODO: `if result == null then this else result` should work here, improve flow typing to handle it
result match
case null => this
case r => r

def implicitDecls(using Context): List[TermRef] = Nil

Expand Down Expand Up @@ -257,7 +262,7 @@ object Scopes {

/** create and enter a scope entry with given name and symbol */
protected def newScopeEntry(name: Name, sym: Symbol)(using Context): ScopeEntry = {
ensureCapacity(if (hashTable != null) hashTable.uncheckedNN.length else MinHashedScopeSize)
ensureCapacity(hashTable match { case null => MinHashedScopeSize; case ht => ht.length })
val e = new ScopeEntry(name, sym, this)
e.prev = lastEntry
lastEntry = e
Expand Down Expand Up @@ -383,21 +388,24 @@ object Scopes {
while ((e != null) && e.name != name)
e = e.prev
}
if ((e == null) && (synthesize != null)) {
val sym = synthesize.uncheckedNN(name)
if (sym.exists) newScopeEntry(sym.name, sym) else e
}
else e
if e != null then e
else synthesize match
case null => null
case s =>
val sym = s(name)
if (sym.exists) newScopeEntry(sym.name, sym) else e
}

/** lookup next entry with same name as this one */
override final def lookupNextEntry(entry: ScopeEntry)(using Context): ScopeEntry | Null = {
var e: ScopeEntry | Null = entry
if (hashTable != null)
while ({ e = e.nn.tail ; (e != null) && e.uncheckedNN.name != entry.name }) ()
if hashTable != null then
var e: ScopeEntry | Null = entry.tail
while e != null && e.name != entry.name do e = e.tail
e
else
while ({ e = e.nn.prev ; (e != null) && e.uncheckedNN.name != entry.name }) ()
e
var e: ScopeEntry | Null = entry.prev
while e != null && e.name != entry.name do e = e.prev
e
}

/** Returns all symbols as a list in the order they were entered in this scope.
Expand All @@ -418,7 +426,7 @@ object Scopes {

override def implicitDecls(using Context): List[TermRef] = {
ensureComplete()
var irefs = new mutable.ListBuffer[TermRef]
val irefs = new mutable.ListBuffer[TermRef]
var e = lastEntry
while (e != null) {
if (e.sym.isOneOf(GivenOrImplicitVal)) {
Expand Down
35 changes: 21 additions & 14 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1917,7 +1917,9 @@ object SymDenotations {
invalidateMemberNamesCache()

def invalidateMemberCachesFor(sym: Symbol)(using Context): Unit =
if myMemberCache != null then myMemberCache.uncheckedNN.remove(sym.name)
myMemberCache match
case null => ()
case mc => mc.remove(sym.name)
if !sym.flagsUNSAFE.is(Private) then
invalidateMemberNamesCache()
if sym.isWrappedToplevelDef then
Expand Down Expand Up @@ -2165,7 +2167,9 @@ object SymDenotations {
*/
def replace(prev: Symbol, replacement: Symbol)(using Context): Unit = {
unforcedDecls.openForMutations.replace(prev, replacement)
if (myMemberCache != null) myMemberCache.uncheckedNN.remove(replacement.name)
myMemberCache match
case null => ()
case mc => mc.remove(replacement.name)
}

/** Delete symbol from current scope.
Expand All @@ -2176,7 +2180,9 @@ 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.uncheckedNN.remove(sym.name)
myMemberCache match
case null => ()
case mc => mc.remove(sym.name)
if (!sym.flagsUNSAFE.is(Private)) invalidateMemberNamesCache()
}

Expand Down Expand Up @@ -3073,17 +3079,18 @@ object SymDenotations {
: (List[ClassSymbol], BaseClassSet) = {
assert(isValid)
CyclicReference.trace("compute the base classes of ", clsd.symbol):
if cache != null then cache.uncheckedNN
else
if (locked) throw CyclicReference(clsd)
locked = true
provisional = false
val computed =
try clsd.computeBaseData(using this, ctx)
finally locked = false
if (!provisional) cache = computed
else onBehalf.signalProvisional()
computed
cache match
case null =>
if (locked) throw CyclicReference(clsd)
locked = true
provisional = false
val computed =
try clsd.computeBaseData(using this, ctx)
finally locked = false
if (!provisional) cache = computed
else onBehalf.signalProvisional()
computed
case mc => mc
}

def sameGroup(p1: Phase, p2: Phase) = p1.sameParentsStartId == p2.sameParentsStartId
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ object Symbols extends SymUtils {

/** The symbol's signature if it is completed or a method, NotAMethod otherwise. */
final def signature(using Context): Signature =
if lastDenot.uncheckedNN.isCompleted || lastDenot.uncheckedNN.is(Method) then
if lastDenot.isCompleted || lastDenot.is(Method) then
denot.signature
else
Signature.NotAMethod
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling

override def checkReset() =
super.checkReset()
assert(pendingSubTypes == null || pendingSubTypes.uncheckedNN.isEmpty)
pendingSubTypes match
case null => ()
case ps => assert(ps.isEmpty)
assert(canCompareAtoms == true)
assert(successCount == 0)
assert(totalCount == 0)
Expand Down
15 changes: 6 additions & 9 deletions compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,12 @@ object TypeErasure:
case tp: TypeVar if !tp.isInstantiated => -2
case _ => -1

def normalizeClass(cls: ClassSymbol)(using Context): ClassSymbol = {
if (defn.specialErasure.contains(cls))
return defn.specialErasure(cls).uncheckedNN
if (cls.owner == defn.ScalaPackageClass) {
if (cls == defn.UnitClass)
return defn.BoxedUnitClass
}
cls
}
def normalizeClass(cls: ClassSymbol)(using Context): ClassSymbol =
defn.specialErasure.get(cls) match
case Some(se) => se
case None =>
if cls.owner == defn.ScalaPackageClass && cls == defn.UnitClass then defn.BoxedUnitClass
else cls

/** A predicate that tests whether a type is a legal erased type. Only asInstanceOf and
* isInstanceOf may have types that do not satisfy the predicate.
Expand Down
Loading
Loading