Skip to content

Commit da9cc38

Browse files
authored
Use more flexible types in dotty (#21608)
2 parents 16a67dc + eb269c8 commit da9cc38

File tree

77 files changed

+126
-168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+126
-168
lines changed

compiler/src/dotty/tools/MainGenericCompiler.scala

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package dotty.tools
22

3-
import scala.language.unsafeNulls
4-
53
import scala.annotation.tailrec
64
import scala.io.Source
75
import scala.util.Try

compiler/src/dotty/tools/MainGenericRunner.scala

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package dotty.tools
22

3-
import scala.language.unsafeNulls
4-
53
import scala.annotation.tailrec
64
import scala.io.Source
75
import scala.util.Try

compiler/src/dotty/tools/backend/jvm/AsmUtils.scala

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package dotty.tools
22
package backend
33
package jvm
44

5-
import scala.language.unsafeNulls
6-
75
import scala.tools.asm.tree.{AbstractInsnNode}
86
import java.io.PrintWriter
97
import scala.tools.asm.util.{TraceClassVisitor, TraceMethodVisitor, Textifier}

compiler/src/dotty/tools/backend/jvm/ClassfileWriters.scala

+6-8
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import dotty.tools.io.PlainFile.toPlainFile
1818
import BTypes.InternalName
1919
import dotty.tools.io.JarArchive
2020

21-
import scala.language.unsafeNulls
22-
2321
/** !!! This file is now copied in `dotty.tools.io.FileWriters` in a more general way that does not rely upon
2422
* `PostProcessorFrontendAccess`, this should probably be changed to wrap that class instead.
2523
*
@@ -54,11 +52,11 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
5452
def close(): Unit
5553

5654
protected def classRelativePath(className: InternalName, suffix: String = ".class"): String =
57-
className.replace('.', '/').nn + suffix
55+
className.replace('.', '/') + suffix
5856
}
5957

6058
object ClassfileWriter {
61-
private def getDirectory(dir: String): Path = Paths.get(dir).nn
59+
private def getDirectory(dir: String): Path = Paths.get(dir)
6260

6361
def apply(): ClassfileWriter = {
6462
val jarManifestMainClass: Option[String] = compilerSettings.mainClass.orElse {
@@ -137,7 +135,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
137135
new JarEntryWriter(jarFile, jarManifestMainClass, jarCompressionLevel)
138136
}
139137
else if (file.isVirtual) new VirtualFileWriter(file)
140-
else if (file.isDirectory) new DirEntryWriter(file.file.toPath.nn)
138+
else if (file.isDirectory) new DirEntryWriter(file.file.nn.toPath)
141139
else throw new IllegalStateException(s"don't know how to handle an output of $file [${file.getClass}]")
142140
}
143141

@@ -151,7 +149,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
151149
val jarWriter: JarOutputStream = {
152150
import scala.util.Properties.*
153151
val manifest = new Manifest
154-
val attrs = manifest.getMainAttributes.nn
152+
val attrs = manifest.getMainAttributes
155153
attrs.put(MANIFEST_VERSION, "1.0")
156154
attrs.put(ScalaCompilerVersion, versionNumberString)
157155
mainClass.foreach(c => attrs.put(MAIN_CLASS, c))
@@ -184,7 +182,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
184182
// important detail here, even on Windows, Zinc expects the separator within the jar
185183
// to be the system default, (even if in the actual jar file the entry always uses '/').
186184
// see https://github.com/sbt/zinc/blob/dcddc1f9cfe542d738582c43f4840e17c053ce81/internal/compiler-bridge/src/main/scala/xsbt/JarUtils.scala#L47
187-
val pathInJar =
185+
val pathInJar =
188186
if File.separatorChar == '/' then relativePath
189187
else relativePath.replace('/', File.separatorChar)
190188
PlainFile.toPlainFile(Paths.get(s"${file.absolutePath}!$pathInJar"))
@@ -293,5 +291,5 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
293291
}
294292

295293
/** Can't output a file due to the state of the file system. */
296-
class FileConflictException(msg: String, cause: Throwable = null) extends IOException(msg, cause)
294+
class FileConflictException(msg: String, cause: Throwable | Null = null) extends IOException(msg, cause)
297295
}

compiler/src/dotty/tools/backend/jvm/PostProcessor.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class PostProcessor(val frontendAccess: PostProcessorFrontendAccess, val bTypes:
3636
setInnerClasses(classNode)
3737
serializeClass(classNode)
3838
catch
39-
case e: java.lang.RuntimeException if e.getMessage != null && e.getMessage.nn.contains("too large!") =>
39+
case e: java.lang.RuntimeException if e.getMessage != null && e.getMessage.contains("too large!") =>
4040
backendReporting.error(em"Could not write class $internalName because it exceeds JVM code size limits. ${e.getMessage}")
4141
null
4242
case ex: Throwable =>
@@ -58,8 +58,8 @@ class PostProcessor(val frontendAccess: PostProcessorFrontendAccess, val bTypes:
5858
}
5959

6060
private def warnCaseInsensitiveOverwrite(clazz: GeneratedClass) = {
61-
val name = clazz.classNode.name.nn
62-
val lowerCaseJavaName = name.nn.toLowerCase
61+
val name = clazz.classNode.name
62+
val lowerCaseJavaName = name.toLowerCase
6363
val clsPos = clazz.position
6464
caseInsensitively.putIfAbsent(lowerCaseJavaName, (name, clsPos)) match {
6565
case null => ()
@@ -71,7 +71,7 @@ class PostProcessor(val frontendAccess: PostProcessorFrontendAccess, val bTypes:
7171
val locationAddendum =
7272
if pos1.source.path == pos2.source.path then ""
7373
else s" (defined in ${pos2.source.file.name})"
74-
def nicify(name: String): String = name.replace('/', '.').nn
74+
def nicify(name: String): String = name.replace('/', '.')
7575
if name1 == name2 then
7676
backendReporting.error(
7777
em"${nicify(name1)} and ${nicify(name2)} produce classes that overwrite one another", pos1)

compiler/src/dotty/tools/backend/jvm/PostProcessorFrontendAccess.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ object PostProcessorFrontendAccess {
146146
override def backendReporting: BackendReporting = {
147147
val local = localReporter.get()
148148
if local eq null then directBackendReporting
149-
else local.nn
149+
else local
150150
}
151151

152152
override object directBackendReporting extends BackendReporting {

compiler/src/dotty/tools/dotc/Bench.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ object Bench extends Driver:
3030
println(s"time elapsed: ${times(curRun)}ms")
3131
if ctx.settings.Xprompt.value || waitAfter == curRun + 1 then
3232
print("hit <return> to continue >")
33-
System.in.nn.read()
33+
System.in.read()
3434
reporter
3535

3636
def extractNumArg(args: Array[String], name: String, default: Int = 1): (Int, Array[String]) = {

compiler/src/dotty/tools/dotc/Driver.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Driver {
3838
finish(compiler, run)
3939
catch
4040
case ex: FatalError =>
41-
report.error(ex.getMessage.nn) // signals that we should fail compilation.
41+
report.error(ex.getMessage) // signals that we should fail compilation.
4242
case ex: Throwable if ctx.usedBestEffortTasty =>
4343
report.bestEffortError(ex, "Some best-effort tasty files were not able to be read.")
4444
throw ex
@@ -117,7 +117,7 @@ class Driver {
117117
.distinct
118118
val ctx1 = ctx.fresh
119119
val fullClassPath =
120-
(newEntries :+ ctx.settings.classpath.value).mkString(java.io.File.pathSeparator.nn)
120+
(newEntries :+ ctx.settings.classpath.value).mkString(java.io.File.pathSeparator)
121121
ctx1.setSetting(ctx1.settings.classpath, fullClassPath)
122122
else ctx
123123

compiler/src/dotty/tools/dotc/Run.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ extends ImplicitRunInfo, ConstraintRunInfo, cc.CaptureRunInfo {
236236
try
237237
trackProgress(_.cancel())
238238
finally
239-
Thread.currentThread().nn.interrupt()
239+
Thread.currentThread().interrupt()
240240

241241
private def doAdvancePhase(currentPhase: Phase, wasRan: Boolean)(using Context): Unit =
242242
trackProgress: progress =>

compiler/src/dotty/tools/dotc/cc/CaptureSet.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,8 @@ object CaptureSet:
777777
extends Var(owner, initialElems):
778778

779779
// For debugging: A trace where a set was created. Note that logically it would make more
780-
// sense to place this variable in BiMapped, but that runs afoul of the initializatuon checker.
781-
// val stack = if debugSets && this.isInstanceOf[BiMapped] then (new Throwable).getStackTrace().nn.take(20) else null
780+
// sense to place this variable in Mapped, but that runs afoul of the initialization checker.
781+
// val stack = if debugSets && this.isInstanceOf[Mapped] then (new Throwable).getStackTrace().take(20) else null
782782

783783
/** The variable from which this variable is derived */
784784
def source: Var

compiler/src/dotty/tools/dotc/cc/Setup.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
445445
CapturingType(parent2, ann.tree.toCaptureSet)
446446
catch case ex: IllegalCaptureRef =>
447447
if !tptToCheck.isEmpty then
448-
report.error(em"Illegal capture reference: ${ex.getMessage.nn}", tptToCheck.srcPos)
448+
report.error(em"Illegal capture reference: ${ex.getMessage}", tptToCheck.srcPos)
449449
parent2
450450
else if ann.symbol == defn.UncheckedCapturesAnnot then
451451
makeUnchecked(apply(parent))
@@ -938,7 +938,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
938938
val refs =
939939
try refTree.toCaptureRefs
940940
catch case ex: IllegalCaptureRef =>
941-
report.error(em"Illegal capture reference: ${ex.getMessage.nn}", refTree.srcPos)
941+
report.error(em"Illegal capture reference: ${ex.getMessage}", refTree.srcPos)
942942
Nil
943943
for ref <- refs do
944944
def pos =

compiler/src/dotty/tools/dotc/classpath/AggregateClassPath.scala

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
package dotty.tools
55
package dotc.classpath
66

7-
import scala.language.unsafeNulls
8-
97
import java.net.URL
108
import scala.collection.mutable.ArrayBuffer
119
import scala.collection.immutable.ArraySeq

compiler/src/dotty/tools/dotc/classpath/ClassPathFactory.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class ClassPathFactory {
6767
for
6868
file <- files
6969
a <- ClassPath.expandManifestPath(file.absolutePath)
70-
path = java.nio.file.Paths.get(a.toURI()).nn
70+
path = java.nio.file.Paths.get(a.toURI())
7171
if Files.exists(path)
7272
yield
7373
newClassPath(AbstractFile.getFile(path))
@@ -82,7 +82,7 @@ class ClassPathFactory {
8282
if (file.isJarOrZip)
8383
ZipAndJarSourcePathFactory.create(file)
8484
else if (file.isDirectory)
85-
new DirectorySourcePath(file.file)
85+
new DirectorySourcePath(file.file.nn)
8686
else
8787
sys.error(s"Unsupported sourcepath element: $file")
8888
}
@@ -94,7 +94,7 @@ object ClassPathFactory {
9494
if (file.isJarOrZip)
9595
ZipAndJarClassPathFactory.create(file)
9696
else if (file.isDirectory)
97-
new DirectoryClassPath(file.file)
97+
new DirectoryClassPath(file.file.nn)
9898
else
9999
sys.error(s"Unsupported classpath element: $file")
100100
}

compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
*/
44
package dotty.tools.dotc.classpath
55

6-
import scala.language.unsafeNulls
7-
86
import java.io.{File => JFile}
97
import java.net.{URI, URL}
108
import java.nio.file.{FileSystems, Files}
@@ -119,7 +117,7 @@ trait JFileDirectoryLookup[FileEntryType <: ClassRepresentation] extends Directo
119117
protected def toAbstractFile(f: JFile): AbstractFile = f.toPath.toPlainFile
120118
protected def isPackage(f: JFile): Boolean = f.isPackage
121119

122-
assert(dir != null, "Directory file in DirectoryFileLookup cannot be null")
120+
assert(dir.asInstanceOf[JFile | Null] != null, "Directory file in DirectoryFileLookup cannot be null")
123121

124122
def asURLs: Seq[URL] = Seq(dir.toURI.toURL)
125123
def asClassPathStrings: Seq[String] = Seq(dir.getPath)
@@ -216,7 +214,7 @@ final class JrtClassPath(fs: java.nio.file.FileSystem) extends ClassPath with No
216214
final class CtSymClassPath(ctSym: java.nio.file.Path, release: Int) extends ClassPath with NoSourcePaths {
217215
import java.nio.file.Path, java.nio.file.*
218216

219-
private val fileSystem: FileSystem = FileSystems.newFileSystem(ctSym, null: ClassLoader)
217+
private val fileSystem: FileSystem = FileSystems.newFileSystem(ctSym, null: ClassLoader | Null)
220218
private val root: Path = fileSystem.getRootDirectories.iterator.next
221219
private val roots = Files.newDirectoryStream(root).iterator.asScala.toList
222220

compiler/src/dotty/tools/dotc/classpath/FileUtils.scala

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
package dotty.tools
55
package dotc.classpath
66

7-
import scala.language.unsafeNulls
8-
97
import java.io.{File => JFile, FileFilter}
108
import java.net.URL
119
import dotty.tools.io.AbstractFile

compiler/src/dotty/tools/dotc/classpath/VirtualDirectoryClassPath.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ case class VirtualDirectoryClassPath(dir: VirtualDirectory) extends ClassPath wi
1111
type F = AbstractFile
1212

1313
// From AbstractFileClassLoader
14-
private final def lookupPath(base: AbstractFile)(pathParts: Seq[String], directory: Boolean): AbstractFile = {
15-
var file: AbstractFile = base
14+
private final def lookupPath(base: AbstractFile)(pathParts: Seq[String], directory: Boolean): AbstractFile | Null = {
15+
var file: AbstractFile | Null = base
1616
val dirParts = pathParts.init.iterator
1717
while (dirParts.hasNext) {
1818
val dirPart = dirParts.next

compiler/src/dotty/tools/dotc/config/CommandLineParser.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ object CommandLineParser:
114114
def expandArg(arg: String): List[String] =
115115
val path = Paths.get(arg.stripPrefix("@"))
116116
if !Files.exists(path) then
117-
System.err.nn.println(s"Argument file ${path.nn.getFileName} could not be found")
117+
System.err.println(s"Argument file ${path.getFileName} could not be found")
118118
Nil
119119
else
120120
def stripComment(s: String) = s.indexOf('#') match { case -1 => s case i => s.substring(0, i) }
121-
val lines = Files.readAllLines(path).nn
122-
val params = lines.asScala.map(stripComment).filter(!_.nn.isEmpty).mkString(" ")
121+
val lines = Files.readAllLines(path)
122+
val params = lines.asScala.map(stripComment).filter(!_.isEmpty).mkString(" ")
123123
tokenize(params)
124124

125125
class ParseException(msg: String) extends RuntimeException(msg)

compiler/src/dotty/tools/dotc/config/Printers.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import core.Contexts.{Context, ctx}
55
object Printers {
66

77
class Printer {
8-
def println(msg: => String): Unit = System.out.nn.println(msg)
8+
def println(msg: => String): Unit = System.out.println(msg)
99
}
1010

1111
object noPrinter extends Printer {

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dotty.tools.dotc
22
package config
33

4-
import scala.language.unsafeNulls
54
import dotty.tools.dotc.config.PathResolver.Defaults
65
import dotty.tools.dotc.config.Settings.{Setting, SettingGroup, SettingCategory, Deprecation}
76
import dotty.tools.dotc.config.SourceVersion

compiler/src/dotty/tools/dotc/config/ScalaSettingsProperties.scala

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package config
44
import Settings.Setting.ChoiceWithHelp
55
import dotty.tools.backend.jvm.BackendUtils.classfileVersionMap
66
import dotty.tools.io.{AbstractFile, Directory, JDK9Reflectors, PlainDirectory, NoAbstractFile}
7-
import scala.language.unsafeNulls
87

98
object ScalaSettingsProperties:
109

compiler/src/dotty/tools/dotc/config/ScalaVersion.scala

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
package dotty.tools
44
package dotc.config
55

6-
import scala.language.unsafeNulls
7-
86
import scala.annotation.internal.sharable
97
import scala.util.{Try, Success, Failure}
108

@@ -82,20 +80,20 @@ case class SpecificScalaVersion(major: Int, minor: Int, rev: Int, build: ScalaBu
8280
"The minor and revision parts are optional."
8381
))
8482

85-
def toInt(s: String) = s match {
83+
def toInt(s: String | Null) = s match {
8684
case null | "" => 0
87-
case _ => s.toInt
85+
case _ => s.nn.toInt
8886
}
8987

9088
def isInt(s: String) = Try(toInt(s)).isSuccess
9189

9290
import ScalaBuild.*
9391

94-
def toBuild(s: String) = s match {
92+
def toBuild(s: String | Null) = s match {
9593
case null | "FINAL" => Final
9694
case s if (s.toUpperCase.startsWith("RC") && isInt(s.substring(2))) => RC(toInt(s.substring(2)))
9795
case s if (s.toUpperCase.startsWith("M") && isInt(s.substring(1))) => Milestone(toInt(s.substring(1)))
98-
case _ => Development(s)
96+
case _ => Development(s.nn)
9997
}
10098

10199
try versionString match {

compiler/src/dotty/tools/dotc/config/Settings.scala

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package dotty.tools.dotc
22
package config
33

4-
import scala.language.unsafeNulls
5-
64
import core.Contexts.*
75

86
import dotty.tools.io.{AbstractFile, Directory, JarArchive, PlainDirectory}

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

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package dotty.tools
22
package dotc
33
package core
44

5-
import scala.language.unsafeNulls
6-
75
import ast.{ untpd, tpd }
86
import Symbols.*, Contexts.*
97
import util.{SourceFile, ReadOnlyMap}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ object Decorators {
5151
if name.length != 0 then name.getChars(0, name.length, chars, s.length)
5252
termName(chars, 0, len)
5353
case name: TypeName => s.concat(name.toTermName)
54-
case _ => termName(s.concat(name.toString).nn)
54+
case _ => termName(s.concat(name.toString))
5555

5656
def indented(width: Int): String =
5757
val padding = " " * width
@@ -289,10 +289,10 @@ object Decorators {
289289
case NonFatal(ex)
290290
if !ctx.settings.YshowPrintErrors.value =>
291291
s"... (cannot display due to ${ex.className} ${ex.getMessage}) ..."
292-
case _ => String.valueOf(x).nn
292+
case _ => String.valueOf(x)
293293

294294
/** Returns the simple class name of `x`. */
295-
def className: String = if x == null then "<null>" else x.getClass.getSimpleName.nn
295+
def className: String = if x == null then "<null>" else x.getClass.getSimpleName
296296

297297
extension [T](x: T)
298298
def assertingErrorsReported(using Context): T = {

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

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ object MacroClassLoader {
1919
ctx.setProperty(MacroClassLoaderKey, makeMacroClassLoader(using ctx))
2020

2121
private def makeMacroClassLoader(using Context): ClassLoader = trace("new macro class loader") {
22-
import scala.language.unsafeNulls
23-
2422
val entries = ClassPath.expandPath(ctx.settings.classpath.value, expandStar=true)
2523
val urls = entries.map(cp => java.nio.file.Paths.get(cp).toUri.toURL).toArray
2624
val out = Option(ctx.settings.outputDir.value.toURL) // to find classes in case of suspended compilation

0 commit comments

Comments
 (0)