Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use flexible types in dotty #21608

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/MainGenericCompiler.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package dotty.tools

import scala.language.unsafeNulls

import scala.annotation.tailrec
import scala.io.Source
import scala.util.Try
Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/backend/jvm/AsmUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package dotty.tools
package backend
package jvm

import scala.language.unsafeNulls

import scala.tools.asm.tree.{AbstractInsnNode}
import java.io.PrintWriter
import scala.tools.asm.util.{TraceClassVisitor, TraceMethodVisitor, Textifier}
Expand Down
14 changes: 6 additions & 8 deletions compiler/src/dotty/tools/backend/jvm/ClassfileWriters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import BTypes.InternalName
import scala.util.chaining.*
import dotty.tools.io.JarArchive

import scala.language.unsafeNulls

/** !!! This file is now copied in `dotty.tools.io.FileWriters` in a more general way that does not rely upon
* `PostProcessorFrontendAccess`, this should probably be changed to wrap that class instead.
*
Expand Down Expand Up @@ -54,11 +52,11 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
def close(): Unit

protected def classRelativePath(className: InternalName, suffix: String = ".class"): String =
className.replace('.', '/').nn + suffix
className.replace('.', '/') + suffix
}

object ClassfileWriter {
private def getDirectory(dir: String): Path = Paths.get(dir).nn
private def getDirectory(dir: String): Path = Paths.get(dir)

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

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

/** Can't output a file due to the state of the file system. */
class FileConflictException(msg: String, cause: Throwable = null) extends IOException(msg, cause)
class FileConflictException(msg: String, cause: Throwable | Null = null) extends IOException(msg, cause)
}
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/backend/jvm/PostProcessor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PostProcessor(val frontendAccess: PostProcessorFrontendAccess, val bTypes:
setInnerClasses(classNode)
serializeClass(classNode)
catch
case e: java.lang.RuntimeException if e.getMessage != null && e.getMessage.nn.contains("too large!") =>
case e: java.lang.RuntimeException if e.getMessage != null && e.getMessage.contains("too large!") =>
backendReporting.error(em"Could not write class $internalName because it exceeds JVM code size limits. ${e.getMessage}")
null
case ex: Throwable =>
Expand All @@ -58,8 +58,8 @@ class PostProcessor(val frontendAccess: PostProcessorFrontendAccess, val bTypes:
}

private def warnCaseInsensitiveOverwrite(clazz: GeneratedClass) = {
val name = clazz.classNode.name.nn
val lowerCaseJavaName = name.nn.toLowerCase
val name = clazz.classNode.name
val lowerCaseJavaName = name.toLowerCase
val clsPos = clazz.position
caseInsensitively.putIfAbsent(lowerCaseJavaName, (name, clsPos)) match {
case null => ()
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/Bench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object Bench extends Driver:
println(s"time elapsed: ${times(curRun)}ms")
if ctx.settings.Xprompt.value || waitAfter == curRun + 1 then
print("hit <return> to continue >")
System.in.nn.read()
System.in.read()
reporter

def extractNumArg(args: Array[String], name: String, default: Int = 1): (Int, Array[String]) = {
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Driver {
finish(compiler, run)
catch
case ex: FatalError =>
report.error(ex.getMessage.nn) // signals that we should fail compilation.
report.error(ex.getMessage) // signals that we should fail compilation.
case ex: Throwable if ctx.usedBestEffortTasty =>
report.bestEffortError(ex, "Some best-effort tasty files were not able to be read.")
throw ex
Expand Down Expand Up @@ -117,7 +117,7 @@ class Driver {
.distinct
val ctx1 = ctx.fresh
val fullClassPath =
(newEntries :+ ctx.settings.classpath.value).mkString(java.io.File.pathSeparator.nn)
(newEntries :+ ctx.settings.classpath.value).mkString(java.io.File.pathSeparator)
ctx1.setSetting(ctx1.settings.classpath, fullClassPath)
else ctx

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
try
trackProgress(_.cancel())
finally
Thread.currentThread().nn.interrupt()
Thread.currentThread().interrupt()

private def doAdvancePhase(currentPhase: Phase, wasRan: Boolean)(using Context): Unit =
trackProgress: progress =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/cc/CaptureSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ object CaptureSet:

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

/** The variable from which this variable is derived */
def source: Var
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ class CheckCaptures extends Recheck, SymTransformer:
trace.force(i"rechecking $tree with pt = $pt", recheckr, show = true):
super.recheck(tree, pt)
catch case ex: NoCommonRoot =>
report.error(ex.getMessage.nn)
report.error(ex.getMessage)
tree.tpe
finally curEnv = saved
if tree.isTerm then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ClassPathFactory {
for
file <- files
a <- ClassPath.expandManifestPath(file.absolutePath)
path = java.nio.file.Paths.get(a.toURI()).nn
path = java.nio.file.Paths.get(a.toURI())
if Files.exists(path)
yield
newClassPath(AbstractFile.getFile(path))
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/config/CommandLineParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ object CommandLineParser:
def expandArg(arg: String): List[String] =
val path = Paths.get(arg.stripPrefix("@"))
if !Files.exists(path) then
System.err.nn.println(s"Argument file ${path.nn.getFileName} could not be found")
System.err.println(s"Argument file ${path.getFileName} could not be found")
Nil
else
def stripComment(s: String) = s.indexOf('#') match { case -1 => s case i => s.substring(0, i) }
val lines = Files.readAllLines(path).nn
val params = lines.asScala.map(stripComment).filter(!_.nn.isEmpty).mkString(" ")
val lines = Files.readAllLines(path)
val params = lines.asScala.map(stripComment).filter(!_.isEmpty).mkString(" ")
tokenize(params)

class ParseException(msg: String) extends RuntimeException(msg)
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/Printers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import core.Contexts.{Context, ctx}
object Printers {

class Printer {
def println(msg: => String): Unit = System.out.nn.println(msg)
def println(msg: => String): Unit = System.out.println(msg)
}

object noPrinter extends Printer {
Expand Down
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dotty.tools.dotc
package config

import scala.language.unsafeNulls
import dotty.tools.dotc.config.PathResolver.Defaults
import dotty.tools.dotc.config.Settings.{Setting, SettingGroup, SettingCategory, Deprecation}
import dotty.tools.dotc.config.SourceVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package config
import Settings.Setting.ChoiceWithHelp
import dotty.tools.backend.jvm.BackendUtils.classfileVersionMap
import dotty.tools.io.{AbstractFile, Directory, JDK9Reflectors, PlainDirectory, NoAbstractFile}
import scala.language.unsafeNulls

object ScalaSettingsProperties:

Expand Down
10 changes: 4 additions & 6 deletions compiler/src/dotty/tools/dotc/config/ScalaVersion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
package dotty.tools
package dotc.config

import scala.language.unsafeNulls

import scala.annotation.internal.sharable
import scala.util.{Try, Success, Failure}

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

def toInt(s: String) = s match {
def toInt(s: String | Null) = s match {
case null | "" => 0
case _ => s.toInt
case _ => s.nn.toInt
}

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

import ScalaBuild.*

def toBuild(s: String) = s match {
def toBuild(s: String | Null) = s match {
case null | "FINAL" => Final
case s if (s.toUpperCase.startsWith("RC") && isInt(s.substring(2))) => RC(toInt(s.substring(2)))
case s if (s.toUpperCase.startsWith("M") && isInt(s.substring(1))) => Milestone(toInt(s.substring(1)))
case _ => Development(s)
case _ => Development(s.nn)
}

try versionString match {
Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/config/Settings.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package dotty.tools.dotc
package config

import scala.language.unsafeNulls

import core.Contexts.*

import dotty.tools.io.{AbstractFile, Directory, JarArchive, PlainDirectory}
Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Comments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package dotty.tools
package dotc
package core

import scala.language.unsafeNulls

import ast.{ untpd, tpd }
import Symbols.*, Contexts.*
import util.{SourceFile, ReadOnlyMap}
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Decorators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object Decorators {
if name.length != 0 then name.getChars(0, name.length, chars, s.length)
termName(chars, 0, len)
case name: TypeName => s.concat(name.toTermName)
case _ => termName(s.concat(name.toString).nn)
case _ => termName(s.concat(name.toString))

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

/** Returns the simple class name of `x`. */
def className: String = x.getClass.getSimpleName.nn
def className: String = x.getClass.getSimpleName

extension [T](x: T)
def assertingErrorsReported(using Context): T = {
Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/core/MacroClassLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ object MacroClassLoader {
ctx.setProperty(MacroClassLoaderKey, makeMacroClassLoader(using ctx))

private def makeMacroClassLoader(using Context): ClassLoader = trace("new macro class loader") {
import scala.language.unsafeNulls

val entries = ClassPath.expandPath(ctx.settings.classpath.value, expandStar=true)
val urls = entries.map(cp => java.nio.file.Paths.get(cp).toUri.toURL).toArray
val out = Option(ctx.settings.outputDir.value.toURL) // to find classes in case of suspended compilation
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/NameOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import nme.*
object NameOps {

object compactify {
lazy val md5: MessageDigest = MessageDigest.getInstance("MD5").nn
lazy val md5: MessageDigest = MessageDigest.getInstance("MD5")

inline val CLASSFILE_NAME_CHAR_LIMIT = 240

Expand Down Expand Up @@ -43,9 +43,9 @@ object NameOps {
val suffix = s.takeRight(edge)

val cs = s.toArray
val bytes = Codec.toUTF8(CharBuffer.wrap(cs).nn)
val bytes = Codec.toUTF8(CharBuffer.wrap(cs))
md5.update(bytes)
val md5chars = md5.digest().nn.map(b => (b & 0xFF).toHexString).mkString
val md5chars = md5.digest().map(b => (b & 0xFF).toHexString).mkString

prefix + marker + md5chars + marker + suffix
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Names.scala
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ object Names {
// because asserts are caught in exception handlers which might
// cause other failures. In that case the first, important failure
// is lost.
System.err.nn.println("Backend should not call Name#toString, Name#mangledString should be used instead.")
System.err.println("Backend should not call Name#toString, Name#mangledString should be used instead.")
Thread.dumpStack()
assert(false)
}
Expand All @@ -404,8 +404,8 @@ object Names {
* from GenBCode or it also contains one of the whitelisted methods below.
*/
private def toStringOK = {
val trace: Array[StackTraceElement] = Thread.currentThread.nn.getStackTrace.asInstanceOf[Array[StackTraceElement]]
!trace.exists(_.getClassName.nn.endsWith("GenBCode")) ||
val trace: Array[StackTraceElement] = Thread.currentThread.getStackTrace.asInstanceOf[Array[StackTraceElement]]
!trace.exists(_.getClassName.endsWith("GenBCode")) ||
trace.exists(elem =>
List(
"mangledString",
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/StdNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object StdNames {

@sharable
private val disallowed = java.util.regex.Pattern.compile("""[<>]""").nn
def sanitize(str: String): String = disallowed.matcher(str).nn.replaceAll("""\$""").nn
def sanitize(str: String): String = disallowed.matcher(str).replaceAll("""\$""").nn
}

abstract class DefinedNames[N <: Name] {
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeErrors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class TypeError(using creationContext: Context) extends Exception(""):
|| ctx.settings.YdebugCyclic.value

override def fillInStackTrace(): Throwable =
if computeStackTrace then super.fillInStackTrace().nn
if computeStackTrace then super.fillInStackTrace()
else this

/** Convert to message. This takes an additional Context, so that we
Expand Down Expand Up @@ -246,7 +246,7 @@ class UnpicklingError(denot: Denotation, where: String, cause: Throwable)(using
case cause: UnpicklingError => ""
case _ =>
if ctx.settings.YdebugUnpickling.value then
cause.getStackTrace().nn.mkString("\n ", "\n ", "")
cause.getStackTrace().mkString("\n ", "\n ", "")
else "\n\nRun with -Ydebug-unpickling to see full stack trace."
em"""Could not read definition $denot$where. Caused by the following exception:
|$cause$debugUnpickling"""
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeEval.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ object TypeEval:
val result =
try op
catch case e: Throwable =>
throw TypeError(em"${e.getMessage.nn}")
throw TypeError(em"${e.getMessage}")
ConstantType(Constant(result))

def fieldsOf: Option[Type] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package dotc
package core
package classfile

import scala.language.unsafeNulls

import java.lang.Float.intBitsToFloat
import java.lang.Double.longBitsToDouble
import java.io.{ByteArrayInputStream, DataInputStream}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dotty.tools.dotc
package core.tasty

import scala.language.unsafeNulls
import scala.collection.immutable.BitSet
import scala.collection.immutable.TreeMap

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object TastyPrinter:
else if arg.endsWith(".tasty") || (allowBetasty && arg.endsWith(".betasty")) then
val path = Paths.get(arg)
if Files.exists(path) then
printTasty(arg, Files.readAllBytes(path).nn, arg.endsWith(".betasty"))
printTasty(arg, Files.readAllBytes(path), arg.endsWith(".betasty"))
else
println("File not found: " + arg)
System.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/JavaScanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ object JavaScanners {
val limit: Double =
if (token == DOUBLELIT) Double.MaxValue else Float.MaxValue
try {
val value: Double = java.lang.Double.valueOf(strVal.toString).nn.doubleValue()
val value: Double = java.lang.Double.valueOf(strVal.toString).doubleValue()
if (value > limit)
error(em"floating point number too large")
if (negated) -value else value
Expand Down
Loading
Loading