Skip to content

Commit bc48797

Browse files
committed
Add more nulls
1 parent 35d4492 commit bc48797

14 files changed

+130
-104
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,9 +1420,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
14201420
def tupleTypeTree(elems: List[Tree])(using Context): Tree = {
14211421
val arity = elems.length
14221422
if arity <= Definitions.MaxTupleArity then
1423-
val tupleTp: TypeRef | Null = defn.TupleType{arity}
1423+
val tupleTp: TypeRef | Null = defn.TupleType(arity)
14241424
if tupleTp != null then
1425-
AppliedTypeTree(TypeTree(defn.TupleType(arity)), elems)
1425+
AppliedTypeTree(TypeTree(tupleTp), elems)
14261426
else nestedPairsTypeTree(elems)
14271427
else nestedPairsTypeTree(elems)
14281428
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ object Constants {
160160
case TypeBounds(lo, hi) =>
161161
if (hi.classSymbol.isPrimitiveValueClass) hi //constrain further with high bound
162162
else classBound(lo)
163-
case NoType => classBound(param.binder.paramInfos.nn(param.paramNum).lo) // TODO
163+
case NoType => classBound(param.binder.paramInfos(param.paramNum).lo) // TODO
164164
case inst => classBound(inst)
165165
}
166166
case pt => pt

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ trait ConstraintHandling {
426426
val e = constraint.entry(param)
427427
if (e.exists) e.bounds
428428
else {
429-
val pinfos = param.binder.paramInfos
429+
// TODO
430+
val pinfos: List[param.binder.PInfo] | Null = param.binder.paramInfos
430431
if (pinfos != null) pinfos(param.paramNum) // pinfos == null happens in pos/i536.scala
431432
else TypeBounds.empty
432433
}
@@ -501,7 +502,7 @@ trait ConstraintHandling {
501502
def apply(t: Type): Type = t match {
502503
case t @ TypeParamRef(tl: TypeLambda, n) if comparedTypeLambdas contains tl =>
503504
// TODO: do we need to check null here?
504-
val bounds = tl.paramInfos.nn(n)
505+
val bounds = tl.paramInfos(n)
505506
range(bounds.lo, bounds.hi)
506507
case _ =>
507508
mapOver(t)

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

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

4+
import scala.language.{unsafeNulls => _}
5+
46
import Contexts._
57
import config.Printers.{default, typr}
68

@@ -14,7 +16,7 @@ trait ConstraintRunInfo { self: Run =>
1416
}
1517
def printMaxConstraint()(using Context): Unit = {
1618
val printer = if (ctx.settings.YdetailedStats.value) default else typr
17-
if (maxSize > 0) printer.println(s"max constraint = ${maxConstraint.show}")
19+
if (maxSize > 0) printer.println(s"max constraint = ${maxConstraint.nn.show}")
1820
}
1921
protected def reset(): Unit = maxConstraint = null
2022
}

compiler/src/dotty/tools/dotc/core/TypeErasure.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 core
44

5+
import scala.language.{unsafeNulls => _}
6+
57
import Symbols._, Types._, Contexts._, Flags._, Names._, StdNames._, Phases._
68
import Flags.JavaDefined
79
import Uniques.unique
@@ -77,7 +79,7 @@ object TypeErasure {
7779
def normalizeClass(cls: ClassSymbol)(using Context): ClassSymbol = {
7880
if (cls.owner == defn.ScalaPackageClass) {
7981
if (defn.specialErasure.contains(cls))
80-
return defn.specialErasure(cls)
82+
return defn.specialErasure(cls).uncheckedNN
8183
if (cls == defn.UnitClass)
8284
return defn.BoxedUnitClass
8385
}

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

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

5+
import scala.language.{unsafeNulls => _}
6+
57
import Types._
68
import Symbols._
79
import Flags._
@@ -18,8 +20,10 @@ class TypeError(msg: String) extends Exception(msg) {
1820
def this() = this("")
1921
final def toMessage(using Context): Message =
2022
withMode(Mode.Printing)(produceMessage)
21-
def produceMessage(using Context): Message = super.getMessage
22-
override def getMessage: String = super.getMessage
23+
def produceMessage(using Context): Message =
24+
val msg: String = super.getMessage.uncheckedNN
25+
msg
26+
override def getMessage: String = super.getMessage.nn
2327
}
2428

2529
class MalformedType(pre: Type, denot: Denotation, absMembers: Set[Name]) extends TypeError {
@@ -78,7 +82,7 @@ class RecursionOverflow(val op: String, details: => String, val previous: Throwa
7882
}
7983

8084
override def fillInStackTrace(): Throwable = this
81-
override def getStackTrace(): Array[StackTraceElement] = previous.getStackTrace()
85+
override def getStackTrace(): Array[StackTraceElement] = previous.getStackTrace().asInstanceOf
8286
}
8387

8488
/** Post-process exceptions that might result from StackOverflow to add
@@ -95,7 +99,7 @@ object handleRecursive {
9599
case _: RecursionOverflow =>
96100
throw new RecursionOverflow(op, details, exc, weight)
97101
case _ =>
98-
var e = exc
102+
var e: Throwable | Null = exc
99103
while (e != null && !e.isInstanceOf[StackOverflowError]) e = e.getCause
100104
if (e != null) throw new RecursionOverflow(op, details, e, weight)
101105
else throw exc
@@ -155,7 +159,8 @@ object CyclicReference {
155159
val ex = new CyclicReference(denot)
156160
if (!(ctx.mode is Mode.CheckCyclic) || ctx.settings.Ydebug.value) {
157161
cyclicErrors.println(s"Cyclic reference involving! $denot")
158-
for (elem <- ex.getStackTrace take 200)
162+
val sts = ex.getStackTrace.asInstanceOf[Array[StackTraceElement]]
163+
for (elem <- sts take 200)
159164
cyclicErrors.println(elem.toString)
160165
}
161166
ex

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

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

5+
import scala.language.{unsafeNulls => _}
6+
57
import Contexts._, Types._, Symbols._, Names._, Flags._
68
import SymDenotations._
79
import util.Spans._
@@ -783,7 +785,7 @@ object TypeOps:
783785
//
784786
// See tests/patmat/i3938.scala
785787
class InferPrefixMap extends TypeMap {
786-
var prefixTVar: Type = null
788+
var prefixTVar: Type | Null = null
787789
def apply(tp: Type): Type = tp match {
788790
case ThisType(tref: TypeRef) if !tref.symbol.isStaticOwner =>
789791
if (tref.symbol.is(Module))
@@ -794,7 +796,7 @@ object TypeOps:
794796
prefixTVar = WildcardType // prevent recursive call from assigning it
795797
val tref2 = this(tref.applyIfParameterized(tref.typeParams.map(_ => TypeBounds.empty)))
796798
prefixTVar = newTypeVar(TypeBounds.upper(tref2))
797-
prefixTVar
799+
prefixTVar.uncheckedNN
798800
}
799801
case tp => mapOver(tp)
800802
}

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

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

5+
import scala.language.{unsafeNulls => _}
6+
57
import Types._
68
import Contexts._
79
import util.{SimpleIdentityMap, SimpleIdentitySet}
@@ -45,7 +47,7 @@ class TyperState() {
4547
private var myId: Int = _
4648
def id: Int = myId
4749

48-
private var previous: TyperState /* | Null */ = _
50+
private var previous: TyperState | Null = _
4951

5052
private var myReporter: Reporter = _
5153

@@ -75,7 +77,7 @@ class TyperState() {
7577
this
7678

7779
def isGlobalCommittable: Boolean =
78-
isCommittable && (previous == null || previous.isGlobalCommittable)
80+
isCommittable && (previous == null || previous.uncheckedNN.isGlobalCommittable)
7981

8082
private var isCommitted: Boolean = _
8183

@@ -92,7 +94,7 @@ class TyperState() {
9294
/** Initializes all fields except reporter, isCommittable, which need to be
9395
* set separately.
9496
*/
95-
private[core] def init(previous: TyperState /* | Null */, constraint: Constraint): this.type =
97+
private[core] def init(previous: TyperState | Null, constraint: Constraint): this.type =
9698
this.myId = TyperState.nextId
9799
TyperState.nextId += 1
98100
this.previous = previous
@@ -117,7 +119,8 @@ class TyperState() {
117119
* which is not yet committed, or which does not have a parent.
118120
*/
119121
def uncommittedAncestor: TyperState =
120-
if (isCommitted) previous.uncommittedAncestor else this
122+
// TODO
123+
if (isCommitted) previous.nn.uncommittedAncestor else this
121124

122125
/** Commit typer state so that its information is copied into current typer state
123126
* In addition (1) the owning state of undetermined or temporarily instantiated
@@ -179,7 +182,7 @@ class TyperState() {
179182
var ts = this
180183
while ts.constraint.domainLambdas.contains(tl) do
181184
ts.constraint = ts.constraint.subst(tl, tl1)
182-
ts = ts.previous
185+
ts = ts.previous.nn
183186

184187
/** Integrate the constraints from `that` into this TyperState.
185188
*
@@ -235,14 +238,14 @@ class TyperState() {
235238
* each tvar can only be instantiated by one TyperState.
236239
*/
237240
private def includeVar(tvar: TypeVar)(using Context): Unit =
238-
val oldState = tvar.owningState.get
241+
val oldState = tvar.owningState.nn.get
239242
assert(oldState == null || !oldState.isCommittable,
240243
i"$this attempted to take ownership of $tvar which is already owned by committable $oldState")
241244
tvar.owningState = new WeakReference(this)
242245
ownedVars += tvar
243246

244247
private def isOwnedAnywhere(ts: TyperState, tvar: TypeVar): Boolean =
245-
ts.ownedVars.contains(tvar) || ts.previous != null && isOwnedAnywhere(ts.previous, tvar)
248+
ts.ownedVars.contains(tvar) || ts.previous != null && isOwnedAnywhere(ts.previous.uncheckedNN, tvar)
246249

247250
/** Make type variable instances permanent by assigning to `inst` field if
248251
* type variable instantiation cannot be retracted anymore. Then, remove
@@ -253,7 +256,8 @@ class TyperState() {
253256
Stats.record("typerState.gc")
254257
val toCollect = new mutable.ListBuffer[TypeLambda]
255258
for tvar <- ownedVars do
256-
assert(tvar.owningState.get eq this, s"Inconsistent state in $this: it owns $tvar whose owningState is ${tvar.owningState.get}")
259+
val tvaros = tvar.owningState.nn.get
260+
assert(tvaros != null && (tvaros eq this), s"Inconsistent state in $this: it owns $tvar whose owningState is ${tvaros}")
257261
assert(!tvar.inst.exists, s"Inconsistent state in $this: it owns $tvar which is already instantiated")
258262
val inst = constraint.instType(tvar)
259263
if inst.exists then
@@ -266,9 +270,9 @@ class TyperState() {
266270
override def toString: String = {
267271
def ids(state: TyperState): List[String] =
268272
s"${state.id}${if (state.isCommittable) "" else "X"}" ::
269-
(if (state.previous == null) Nil else ids(state.previous))
273+
(if (state.previous == null) Nil else ids(state.previous.uncheckedNN))
270274
s"TS[${ids(this).mkString(", ")}]"
271275
}
272276

273-
def stateChainStr: String = s"$this${if (previous == null) "" else previous.stateChainStr}"
277+
def stateChainStr: String = s"$this${if (previous == null) "" else previous.uncheckedNN.stateChainStr}"
274278
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3423,7 +3423,7 @@ object Types {
34233423
type ParamRefType <: ParamRef
34243424

34253425
def paramNames: List[ThisName]
3426-
def paramInfos: List[PInfo] | Null
3426+
def paramInfos: List[PInfo]
34273427
def resType: Type
34283428
protected def newParamRef(n: Int): ParamRefType
34293429

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package dotty.tools.dotc
22
package core
33

4+
import scala.language.{unsafeNulls => _}
5+
46
import Types._, Contexts._, util.Stats._, Hashable._, Names._
57
import config.Config
68
import Decorators._
@@ -52,7 +54,7 @@ object Uniques:
5254
val oldHead = table(bucket)
5355

5456
@tailrec
55-
def linkedListLoop(entry: Entry[NamedType]): NamedType = entry match
57+
def linkedListLoop(entry: Entry[NamedType] | Null): NamedType = entry match
5658
case null => addEntryAt(bucket, newType, h, oldHead)
5759
case _ =>
5860
val e = entry.get
@@ -79,7 +81,7 @@ object Uniques:
7981
val oldHead = table(bucket)
8082

8183
@tailrec
82-
def linkedListLoop(entry: Entry[AppliedType]): AppliedType = entry match
84+
def linkedListLoop(entry: Entry[AppliedType] | Null): AppliedType = entry match
8385
case null => addEntryAt(bucket, newType, h, oldHead)
8486
case _ =>
8587
val e = entry.get

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

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

4+
import scala.language.{unsafeNulls => _}
5+
46
import Types._, Contexts._, Flags._, Symbols._, Annotations._
57
import TypeApplications.TypeParamInfo
68
import Decorators._

compiler/src/dotty/tools/dotc/util/MutableSet.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dotty.tools.dotc.util
22

3+
import scala.language.{unsafeNulls => _}
4+
35
/** A common class for lightweight mutable sets.
46
*/
57
abstract class MutableSet[T] extends ReadOnlySet[T]:

compiler/src/dotty/tools/dotc/util/ReadOnlySet.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dotty.tools.dotc.util
22

3+
import scala.language.{unsafeNulls => _}
4+
35
/** A class for the readonly part of mutable sets.
46
*/
57
abstract class ReadOnlySet[T]:

0 commit comments

Comments
 (0)