Skip to content

Commit 3b2fd9a

Browse files
committed
Enable explicit nulls for all compile
1 parent aff1e11 commit 3b2fd9a

File tree

5 files changed

+27
-22
lines changed

5 files changed

+27
-22
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ abstract class GenericHashMap[Key, Value]
133133
val v1 = value
134134
v = v1
135135
update(key, v1)
136-
v.uncheckedNN
136+
v
137137

138138
private def addOld(key: Key, value: Value): Unit =
139139
Stats.record(statsItem("re-enter"))

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class HashSet[T](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends Mu
8484
var idx = firstIndex(x)
8585
var e: T | Null = entryAt(idx)
8686
while e != null do
87-
if isEqual(e.uncheckedNN, x) then return e
87+
if isEqual(e, x) then return e
8888
idx = nextIndex(idx)
8989
e = entryAt(idx)
9090
null
@@ -102,8 +102,7 @@ class HashSet[T](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends Mu
102102
var idx = firstIndex(x)
103103
var e: T | Null = entryAt(idx)
104104
while e != null do
105-
// TODO: remove uncheckedNN when explicit-nulls is enabled for regule compiling
106-
if isEqual(e.uncheckedNN, x) then return e.uncheckedNN
105+
if isEqual(e, x) then return e
107106
idx = nextIndex(idx)
108107
e = entryAt(idx)
109108
addEntryAt(idx, x)
@@ -115,20 +114,20 @@ class HashSet[T](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends Mu
115114
var idx = firstIndex(x)
116115
var e: T | Null = entryAt(idx)
117116
while e != null do
118-
if isEqual(e.uncheckedNN, x) then
117+
if isEqual(e, x) then
119118
var hole = idx
120119
while
121120
idx = nextIndex(idx)
122121
e = entryAt(idx)
123122
e != null
124123
do
125-
val eidx = index(hash(e.uncheckedNN))
124+
val eidx = index(hash(e))
126125
if isDense
127126
|| index(eidx - (hole + 1)) > index(idx - (hole + 1))
128127
// entry `e` at `idx` can move unless `index(hash(e))` is in
129128
// the (ring-)interval [hole + 1 .. idx]
130129
then
131-
setEntry(hole, e.uncheckedNN)
130+
setEntry(hole, e)
132131
hole = idx
133132
table(hole) = null
134133
used -= 1
@@ -156,7 +155,7 @@ class HashSet[T](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends Mu
156155
var idx = 0
157156
while idx < oldTable.length do
158157
val e: T | Null = oldTable(idx).asInstanceOf[T | Null]
159-
if e != null then addOld(e.uncheckedNN)
158+
if e != null then addOld(e)
160159
idx += 1
161160

162161
protected def growTable(): Unit =

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,25 @@ abstract class ReadOnlyMap[Key, Value]:
1515

1616
def isEmpty: Boolean = size == 0
1717

18-
def get(key: Key): Option[Value] = lookup(key) match
19-
case null => None
20-
case v => Some(v.uncheckedNN)
21-
22-
def getOrElse(key: Key, value: => Value) = lookup(key) match
23-
case null => value
24-
case v => v.uncheckedNN
18+
def get(key: Key): Option[Value] =
19+
val v = lookup(key)
20+
v match
21+
case null => None
22+
case _ => Some(v)
23+
24+
def getOrElse(key: Key, value: => Value) =
25+
val v = lookup(key)
26+
v match
27+
case null => value
28+
case _ => v
2529

2630
def contains(key: Key): Boolean = lookup(key) != null
2731

28-
def apply(key: Key): Value = lookup(key) match
29-
case null => throw new NoSuchElementException(s"$key")
30-
case v => v.uncheckedNN
32+
def apply(key: Key): Value =
33+
val v = lookup(key)
34+
v match
35+
case null => throw new NoSuchElementException(s"$key")
36+
case _ => v
3137

3238
def toArray: Array[(Key, Value)] =
3339
val result = new Array[(Key, Value)](size)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ abstract class WeakHashSet[A <: AnyRef](initialCapacity: Int = 8, loadFactor: Do
178178
case null => addEntryAt(bucket, elem, h, oldHead)
179179
case _ =>
180180
val entryElem = entry.get
181-
if entryElem != null && isEqual(elem, entryElem) then entryElem.uncheckedNN
181+
if entryElem != null && isEqual(elem, entryElem) then entryElem
182182
else linkedListLoop(entry.tail)
183183
}
184184

project/Build.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,9 @@ object Build {
611611

612612
Compile / mainClass := Some("dotty.tools.dotc.Main"),
613613

614+
// Note: bench/profiles/projects.yml should be updated accordingly.
615+
Compile / scalacOptions ++= Seq("-Yexplicit-nulls"),
616+
614617
scala := {
615618
val args: List[String] = spaceDelimited("<arg>").parsed.toList
616619
val externalDeps = externalCompilerClasspathTask.value
@@ -773,9 +776,6 @@ object Build {
773776
)
774777
},
775778

776-
// Note: bench/profiles/projects.yml should be updated accordingly.
777-
Compile / scalacOptions ++= Seq("-Yexplicit-nulls"),
778-
779779
repl := (Compile / console).value,
780780
Compile / console / scalacOptions := Nil, // reset so that we get stock REPL behaviour! E.g. avoid -unchecked being enabled
781781
)

0 commit comments

Comments
 (0)