Skip to content

Commit a7a9a7b

Browse files
committed
Enable explicit nulls for all compile
1 parent 75d8eea commit a7a9a7b

File tree

16 files changed

+43
-37
lines changed

16 files changed

+43
-37
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,11 +2126,12 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
21262126
if (hi1 & hi2).isEmpty then return orType(tp1, tp2)
21272127
case none =>
21282128
case none =>
2129+
21292130
val t1 = mergeIfSuper(tp1, tp2, canConstrain)
2130-
if (t1.exists) return t1
2131+
if t1.exists then return t1.simplified
21312132

21322133
val t2 = mergeIfSuper(tp2, tp1, canConstrain)
2133-
if (t2.exists) return t2
2134+
if t2.exists then return t2.simplified
21342135

21352136
def widen(tp: Type) = if (widenInUnions) tp.widen else tp.widenIfUnstable
21362137
val tp1w = widen(tp1)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object ClasspathFromClassloader {
1414
* BEWARE: with exotic enough classloaders, this may not work at all or do
1515
* the wrong thing.
1616
*/
17-
def apply(cl: ClassLoader): String = {
17+
def apply(cl: ClassLoader | Null): String = {
1818
val classpathBuff = List.newBuilder[String]
1919
def collectClassLoaderPaths(cl: ClassLoader): Unit = {
2020
if (cl != null) {

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

compiler/test/dotty/tools/dotc/TastyBootstrapTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class TastyBootstrapTests {
5050
Properties.compilerInterface, Properties.scalaLibrary, Properties.scalaAsm,
5151
Properties.dottyInterfaces, Properties.jlineTerminal, Properties.jlineReader,
5252
).mkString(File.pathSeparator),
53-
Array("-Ycheck-reentrant", "-language:postfixOps", "-Xsemanticdb")
53+
Array("-Ycheck-reentrant", "-language:postfixOps", "-Xsemanticdb", "-Yexplicit-nulls")
5454
)
5555

5656
val libraryDirs = List(Paths.get("library/src"), Paths.get("library/src-bootstrapped"))

compiler/test/dotty/tools/vulpix/TestConfiguration.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ object TestConfiguration {
6666
val defaultOptions = TestFlags(basicClasspath, commonOptions)
6767
val unindentOptions = TestFlags(basicClasspath, Array("-no-indent") ++ checkOptions ++ noCheckOptions ++ yCheckOptions)
6868
val withCompilerOptions =
69-
defaultOptions.withClasspath(withCompilerClasspath).withRunClasspath(withCompilerClasspath)
69+
defaultOptions.withClasspath(withCompilerClasspath).withRunClasspath(withCompilerClasspath) and "-Yexplicit-nulls"
7070
lazy val withStagingOptions =
7171
defaultOptions.withClasspath(withStagingClasspath).withRunClasspath(withStagingClasspath)
7272
lazy val withTastyInspectorOptions =
@@ -82,7 +82,7 @@ object TestConfiguration {
8282
"-Yprint-pos-syms"
8383
)
8484
val picklingWithCompilerOptions =
85-
picklingOptions.withClasspath(withCompilerClasspath).withRunClasspath(withCompilerClasspath)
85+
picklingOptions.withClasspath(withCompilerClasspath).withRunClasspath(withCompilerClasspath) and "-Yexplicit-nulls"
8686
val scala2CompatMode = defaultOptions.and("-source", "3.0-migration")
8787
val explicitUTF8 = defaultOptions and ("-encoding", "UTF8")
8888
val explicitUTF16 = defaultOptions and ("-encoding", "UTF16")

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
)

tests/neg-with-compiler/GenericNumLits/EvenFromDigitsImpl_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object EvenFromDigitsImpl:
1010
try evenFromDigits(ds)
1111
catch {
1212
case ex: FromDigits.FromDigitsException =>
13-
quotes.reflect.report.error(ex.getMessage)
13+
quotes.reflect.report.error(ex.getMessage.nn)
1414
Even(0)
1515
}
1616
'{Even(${Expr(ev.n)})}

tests/pos-with-compiler/Fileish.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Fileish(val path: Path, val input: () => InputStream) extends Streamable.C
1919

2020
private lazy val pkgLines = lines() collect { case x if x startsWith "package " => x stripPrefix "package" trim }
2121
lazy val pkgFromPath = parent.path.replaceAll("""[/\\]""", ".")
22-
lazy val pkgFromSource = pkgLines map (_ stripSuffix ";") mkString "."
22+
lazy val pkgFromSource = pkgLines map (_.nn.stripSuffix(";")) mkString "."
2323

2424
override def toString = path.path
2525
}
@@ -32,7 +32,7 @@ class Fileish2(val path: Path, val input: () => InputStream) extends Streamable.
3232

3333
private val pkgLines = lines() collect { case x if x startsWith "package " => x stripPrefix "package" trim }
3434
lazy val pkgFromPath = parent.path.replaceAll("""[/\\]""", ".")
35-
lazy val pkgFromSource = pkgLines map (_ stripSuffix ";") mkString "."
35+
lazy val pkgFromSource = pkgLines map (_.nn.stripSuffix(";")) mkString "."
3636

3737
override def toString = path.path
3838
}
@@ -46,7 +46,7 @@ class Fileish3(val path: Path, val input: () => InputStream) extends Streamable.
4646

4747
private val pkgLines = lines() collect { case x if x startsWith "package " => x stripPrefix "package" trim }
4848
private val pkgFromPath = parent.path.replaceAll("""[/\\]""", ".")
49-
private val pkgFromSource = pkgLines map (_ stripSuffix ";") mkString "."
49+
private val pkgFromSource = pkgLines map (_.nn.stripSuffix(";")) mkString "."
5050

5151
override def toString = path.path
5252
}

tests/pos-with-compiler/Patterns.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import dotty.tools.dotc.ast.Trees.*
22
import dotty.tools.dotc.core.Types.*
33

44
object Patterns {
5-
val d: Object = null
5+
val d: Object = null.asInstanceOf[Object]
66
private def rebase(tp: NamedType): Type = {
77
def rebaseFrom(prefix: Type): Type = ???
88
tp.prefix match {

tests/pos-with-compiler/benchSets.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def testAnyRefMap =
7878
i += 1
7979
while i > 0 do
8080
i -= 1
81-
val v = set.getOrNull(elems(i))
81+
val v: Elem | Null = set.getOrNull(elems(i))
8282
if v != null then
8383
count += 1
8484
iter += 1

tests/pos-with-compiler/lazyValsSepComp.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import dotty.tools.dotc.core.Contexts.*
1010

1111
/** A test to trigger issue with separate compilation and lazy vals */
1212
object Foo {
13-
val definitions: Definitions = null
13+
val definitions: Definitions = null.asInstanceOf[Definitions]
1414
def defn = definitions
1515
def go = defn.ScalaBoxedClasses
1616
}

tests/run-with-compiler/i14541.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ object Test:
44
import dotty.tools.runner.RichClassLoader.*
55
val classpath = dotty.tools.dotc.util.ClasspathFromClassloader(getClass.getClassLoader)
66
def main(args: Array[String]): Unit =
7-
getClass.getClassLoader.run("echo", List("hello", "raw", "world"))
7+
getClass.getClassLoader.nn.run("echo", List("hello", "raw", "world"))
88
// caution: uses "SCALA_OPTS"
99
dotty.tools.MainGenericRunner.main(Array("--class-path", classpath, "echo", "hello", "run", "world"))
1010

tests/run-with-compiler/scripting.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
object Test {
22
def main(args: Array[String]): Unit = {
33
val m = new javax.script.ScriptEngineManager(getClass().getClassLoader())
4-
val e = m.getEngineByName("scala")
4+
val e = m.getEngineByName("scala").nn
55
println(e.eval("42"))
66
println(e.eval("Some(42)").asInstanceOf[Option[Int]].get)
77
println(e.eval(new java.io.StringReader("42")))

0 commit comments

Comments
 (0)