Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
38 changes: 32 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,15 @@ lazy val commonSettings = instanceSettings ++ clearSourceAndResourceDirectories
cleanFiles += (Compile / doc / target).value,
run / fork := true,
run / connectInput := true,
Compile / scalacOptions ++= Seq("-feature", "-Xlint",
Compile / scalacOptions ++= Seq("-Xlint", "-feature", "-Xsource:3-cross",
//"-Vprint",
//"-Xmaxerrs", "5", "-Xmaxwarns", "5", // uncomment for ease of development while breaking things
// work around https://github.com/scala/bug/issues/11534
"-Wconf:cat=unchecked&msg=The outer reference in this type test cannot be checked at run time.:s",
// optimizer warnings at INFO since `-Werror` may be turned on.
// optimizer runs in CI and release builds, though not in local development.
"-Wconf:cat=optimizer:is",
//"-Wconf:cat=optimizer:is",
"-Wopt",
// we use @nowarn for methods that are deprecated in JDK > 8, but CI/release is under JDK 8
"-Wconf:cat=unused-nowarn:s",
"-Wunnamed-boolean-literal-strict",
Expand Down Expand Up @@ -450,6 +451,10 @@ lazy val library = configureAsSubproject(project)
name := "scala-library",
description := "Scala Standard Library",
Compile / scalacOptions ++= Seq("-sourcepath", (Compile / scalaSource).value.toString),
Compile / scalacOptions ++= Seq("-Xsource-features:-case-companion-function"),
Compile / scalacOptions ++= Seq("-Wconf:cat=scala3-migration&msg=elidable&site=scala.Predef:s"),
//Compile / scalacOptions ++= Seq("-Wconf:msg=Synthetic case companion&src=src/library/scala/jdk/FunctionWrappers.scala:s"),
//Compile / scalacOptions ++= Seq("-Wconf:cat=scala3-migration&msg=constructor modifiers&site=scala.concurrent.duration.Deadline:s"), // for bootstrap until restarr
Compile / doc / scalacOptions ++= {
val libraryAuxDir = (ThisBuild / baseDirectory).value / "src/library-aux"
Seq(
Expand Down Expand Up @@ -502,6 +507,7 @@ lazy val reflect = configureAsSubproject(project)
Osgi.bundleName := "Scala Reflect",
Compile / scalacOptions ++= Seq(
"-Wconf:cat=deprecation&msg=early initializers:s", // compiler heavily relies upon early initializers
"-Wconf:cat=scala3-migration&msg=early initializers:s", // compiler heavily relies upon early initializers
),
Compile / doc / scalacOptions ++= Seq(
"-skip-packages", "scala.reflect.macros.internal:scala.reflect.internal:scala.reflect.io"
Expand Down Expand Up @@ -576,6 +582,7 @@ lazy val compiler = configureAsSubproject(project)
Compile / scalacOptions ++= Seq(
//"-Wunused", //"-Wnonunit-statement",
"-Wconf:cat=deprecation&msg=early initializers:s", // compiler heavily relies upon early initializers
"-Wconf:cat=scala3-migration&msg=early initializers:s", // compiler heavily relies upon early initializers
),
Compile / doc / scalacOptions ++= Seq(
"-doc-root-content", (Compile / sourceDirectory).value + "/rootdoc.txt"
Expand Down Expand Up @@ -614,15 +621,21 @@ lazy val interactive = configureAsSubproject(project)
.settings(
name := "scala-compiler-interactive",
description := "Scala Interactive Compiler",
Compile / scalacOptions ++= Seq("-Wconf:cat=deprecation&msg=early initializers:s"),
Compile / scalacOptions ++= Seq(
"-Wconf:cat=deprecation&msg=early initializers:s",
"-Wconf:cat=scala3-migration&msg=early initializers:s", // compiler heavily relies upon early initializers
)
)
.dependsOn(compiler)

lazy val repl = configureAsSubproject(project)
.settings(disableDocs)
.settings(fatalWarningsSettings)
.settings(publish / skip := true)
.settings(Compile / scalacOptions ++= Seq("-Wconf:cat=deprecation&msg=early initializers:s"))
.settings(Compile / scalacOptions ++= Seq(
"-Wconf:cat=deprecation&msg=early initializers:s",
"-Wconf:cat=scala3-migration&msg=early initializers:s",
))
.dependsOn(compiler, interactive)

lazy val replFrontend = configureAsSubproject(project, srcdir = Some("repl-frontend"))
Expand Down Expand Up @@ -651,6 +664,7 @@ lazy val scaladoc = configureAsSubproject(project)
Compile / resourceGenerators += ScaladocSettings.extractResourcesFromWebjar,
Compile / scalacOptions ++= Seq(
"-Wconf:cat=deprecation&msg=early initializers:s",
"-Wconf:cat=scala3-migration&msg=early initializers:s",
),
)
.dependsOn(compiler)
Expand All @@ -666,6 +680,7 @@ lazy val sbtBridge = configureAsSubproject(project, srcdir = Some("sbt-bridge"))
libraryDependencies += compilerInterfaceDep % Provided,
Compile / scalacOptions ++= Seq(
"-Wconf:cat=deprecation&msg=early initializers:s", // compiler heavily relies upon early initializers
"-Wconf:cat=scala3-migration&msg=early initializers:s", // compiler heavily relies upon early initializers
),
generateServiceProviderResources("xsbti.compile.CompilerInterface2" -> "scala.tools.xsbt.CompilerBridge"),
generateServiceProviderResources("xsbti.compile.ConsoleInterface1" -> "scala.tools.xsbt.ConsoleBridge"),
Expand Down Expand Up @@ -721,6 +736,14 @@ lazy val scalap = configureAsSubproject(project)
xs filter { x => !excluded(x.getName) }
},
Compile / headerResources := Nil,
Compile / scalacOptions ++= Seq(
"-Xsource:2.13",
"-Xsource-features:-case-apply-copy-access,-case-companion-function,-case-copy-by-name",
"-Xsource-features:-implicit-resolution,-infer-override,-any2stringadd,-unicode-escapes-raw",
"-Xsource-features:-string-context-scope,-leading-infix,-package-prefix-implicits,-double-definitions",
//"-Wconf:cat=scala3-migration&msg=inferred type:s",
//"-Wconf:cat=scala3-migration&msg=case companion:s",
),
)
.dependsOn(compiler)

Expand All @@ -735,6 +758,7 @@ lazy val partest = configureAsSubproject(project)
libraryDependencies ++= List(testInterfaceDep, diffUtilsDep, junitDep),
Compile / scalacOptions ++= Seq(
"-Wconf:cat=deprecation&msg=early initializers:s", // compiler heavily relies upon early initializers
"-Wconf:cat=scala3-migration&msg=early initializers:s", // compiler heavily relies upon early initializers
),
Compile / javacOptions ++= Seq("-XDenableSunApiLintControl", "-Xlint") ++
(if (fatalWarnings.value) Seq("-Werror") else Seq()),
Expand Down Expand Up @@ -807,8 +831,7 @@ lazy val bench = project.in(file("test") / "benchmarks")
if (benchmarkScalaVersion == "") Nil
else "org.scala-lang" % "scala-compiler" % benchmarkScalaVersion :: Nil
},
//scalacOptions ++= Seq("-feature", "-opt:inline:scala/**", "-Wopt"),
scalacOptions ++= Seq("-feature", "-opt:l:inline", "-opt-inline-from:scala/**", "-opt-warnings"),
scalacOptions ++= Seq("-feature", "-opt:inline:scala/**", "-Wopt"),
// Skips JMH source generators during IDE import to avoid needing to compile scala-library during the import
// should not be needed once sbt-jmh 0.4.3 is out (https://github.com/sbt/sbt-jmh/pull/207)
Jmh / bspEnabled := false
Expand Down Expand Up @@ -855,6 +878,8 @@ lazy val junit = project.in(file("test") / "junit")
"-Wconf:msg=match may not be exhaustive:s", // if we missed a case, all that happens is the test fails
"-Wconf:cat=lint-nullary-unit&site=.*Test:s", // normal unit test style
"-Ypatmat-exhaust-depth", "40", // despite not caring about patmat exhaustiveness, we still get warnings for this
"-Wconf:cat=deprecation&msg=early initializers:s",
"-Wconf:cat=scala3-migration&msg=early initializers:s",
),
Compile / javacOptions ++= Seq("-Xlint"),
libraryDependencies ++= Seq(junitInterfaceDep, jolDep, diffUtilsDep, compilerInterfaceDep),
Expand Down Expand Up @@ -902,6 +927,7 @@ lazy val tasty = project.in(file("test") / "tasty")
},
Compile / scalacOptions ++= Seq(
"-Wconf:cat=lint-nullary-unit&site=.*Test:s", // normal unit test style
raw"-Wconf:cat=optimizer&site=scala\.tools\.nsc\.tasty\.bridge\.TreeOps\.tpd\..*:s", // inline -> outline
),
)

Expand Down
3 changes: 1 addition & 2 deletions project/ScriptCommands.scala
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ object ScriptCommands {
}

private[this] val enableOptimizer = Seq(
//ThisBuild / Compile / scalacOptions ++= Seq("-opt:inline:scala/**")
ThisBuild / Compile / scalacOptions ++= Seq("-opt:l:inline", "-opt-inline-from:scala/**")
ThisBuild / Compile / scalacOptions ++= Seq("-opt:inline:scala/**")
)

val noDocs = Seq(
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/GenericRunnerSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ class GenericRunnerSettings(error: String => Unit, pathFactory: PathFactory) ext
"-nc",
"do not use the legacy fsc compilation daemon").withAbbreviation("-nocompdaemon").withAbbreviation("--no-compilation-daemon")
.withDeprecationMessage("scripts use cold compilation by default; use -Yscriptrunner for custom behavior")
.withPostSetHook { x: BooleanSetting => Yscriptrunner.value = if (x.value) "default" else "resident" }
.withPostSetHook { (x: BooleanSetting) => Yscriptrunner.value = if (x.value) "default" else "resident" }
}
3 changes: 2 additions & 1 deletion src/compiler/scala/tools/nsc/Global.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1704,8 +1704,9 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
*/
@tailrec
private def resetPackageClass(pclazz: Symbol): Unit = if (typerPhase != NoPhase) {
val pinfo = enteringPhase(typerPhase)(pclazz.info)
enteringPhase[Unit](firstPhase) {
pclazz.setInfo(enteringPhase(typerPhase)(pclazz.info))
pclazz.setInfo(pinfo)
}
if (!pclazz.isRoot) resetPackageClass(pclazz.owner)
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/PipelineMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class PipelineMainClass(argFiles: Seq[Path], pipelineSettings: PipelineMain.Pipe
}
strategy match {
case OutlineTypePipeline =>
projects.foreach { p: Task =>
projects.foreach { (p: Task) =>
val depsReady = Future.traverse(dependsOn.getOrElse(p, Nil))(task => p.dependencyReadyFuture(task))
val f = for {
_ <- depsReady
Expand Down
10 changes: 5 additions & 5 deletions src/compiler/scala/tools/nsc/Reporting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -832,15 +832,15 @@ object Reporting {
if (s == "any") {
Right(Any)
} else if (s.startsWith("msg=")) {
regex(s.substring(4)).map(MessagePattern)
regex(s.substring(4)).map(MessagePattern(_))
} else if (s.startsWith("cat=")) {
val cs = s.substring(4)
val c = WarningCategory.all.get(cs).map(Category)
val c = WarningCategory.all.get(cs).map(Category(_))
c.toRight(s"Unknown category: `$cs`")
} else if (s.startsWith("site=")) {
regex(s.substring(5)).map(SitePattern)
regex(s.substring(5)).map(SitePattern(_))
} else if (s.startsWith("origin=")) {
regex(s.substring(7)).map(DeprecatedOrigin)
regex(s.substring(7)).map(DeprecatedOrigin(_))
} else if (s.startsWith("since")) {
def fail = Left(s"invalid since filter: `$s`; required shape: `since<1.2.3`, `since=3.2`, `since>2`")
if (s.length < 6) fail
Expand All @@ -867,7 +867,7 @@ object Reporting {
if (!rootDir.endsWith("/") && !arg.startsWith("/")) pat += '/'
pat ++= arg
if (!arg.endsWith("$")) pat += '$'
regex(pat.toString).map(SourcePattern)
regex(pat.toString).map(SourcePattern(_))
} else {
Left(s"unknown filter: $s")
}
Expand Down
19 changes: 10 additions & 9 deletions src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ trait ParsersCommon extends ScannersCommon {

/** Creates an actual Parens node (only used during parsing.)
*/
@inline final def makeParens(body: => List[Tree]): Parens =
Parens(inParens(if (in.token == RPAREN) Nil else body))
@inline final def makeParens(body: => List[Tree]): Parens = {
val body0 = inParens(if (in.token == RPAREN) Nil else body)
Parens(body0)
}

/** {{{ { `sep` part } }}}. */
def tokenSeparated[T](separator: Token, part: => T): List[T] = {
Expand Down Expand Up @@ -544,7 +546,7 @@ self =>
val assumedClosingParens = mutable.Map(RPAREN -> 0, RBRACKET -> 0, RBRACE -> 0)

private var inFunReturnType = false
@inline private def fromWithinReturnType[T](body: => T): T = {
private def fromWithinReturnType[T](body: => T): T = {
val saved = inFunReturnType
inFunReturnType = true
try body
Expand Down Expand Up @@ -1877,7 +1879,7 @@ self =>
def prefixExpr(): Tree =
if (isUnaryOp) {
val start = in.offset
atPos(start) {
val result =
if (lookingAhead(isExprIntro)) {
val namePos = in.offset
val uname = nme.toUnaryName(rawIdent().toTermName)
Expand All @@ -1888,7 +1890,7 @@ self =>
Select(stripParens(simpleExpr()), uname)
}
else simpleExpr()
}
atPos(start)(result)
} else simpleExpr()

def xmlLiteral(): Tree
Expand Down Expand Up @@ -3237,9 +3239,8 @@ self =>
migrationWarning(in.offset, "type parameters should not follow newline", since = "2.13.7")
def orStart(p: Offset) = if (name == tpnme.ERROR) start else p
val namePos = NamePos(r2p(orStart(nameOffset), orStart(nameOffset)))
atPos(start, orStart(nameOffset)) {
savingClassContextBounds {
val contextBoundBuf = new ListBuffer[Tree]
def finish = savingClassContextBounds {
val contextBoundBuf = ListBuffer.empty[Tree]
val tparams = typeParamClauseOpt(name, contextBoundBuf, ParamOwner.Class)
classContextBounds = contextBoundBuf.toList
val tstart = (in.offset :: classContextBounds.map(_.pos.start)).min
Expand All @@ -3260,7 +3261,7 @@ self =>
ensureNonOverlapping(template, tparams)
result
}
}
atPos(start, orStart(nameOffset))(finish)
}

/** {{{
Expand Down
14 changes: 7 additions & 7 deletions src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ trait Scanners extends ScannersCommon {
if (token == CHARLIT && !negated) charVal.toLong else intConvert
}

@`inline` def intVal: Long = intVal(negated = false)
@inline final def intVal: Long = intVal(negated = false)

private val zeroFloat = raw"[0.]+(?:[eE][+-]?[0-9]+)?[fFdD]?".r

Expand All @@ -1321,7 +1321,7 @@ trait Scanners extends ScannersCommon {
}
}

@`inline` def floatVal: Float = floatVal(negated = false)
@inline final def floatVal: Float = floatVal(negated = false)

/** Convert current strVal, base to double value.
*/
Expand All @@ -1341,15 +1341,15 @@ trait Scanners extends ScannersCommon {
}
}

@`inline` def doubleVal: Double = doubleVal(negated = false)
@inline final def doubleVal: Double = doubleVal(negated = false)

@`inline` def checkNoLetter(): Unit = if (isIdentifierPart(ch) && ch >= ' ') syntaxError("invalid literal number")
@inline final def checkNoLetter(): Unit = if (isIdentifierPart(ch) && ch >= ' ') syntaxError("invalid literal number")

@`inline` private def isNumberSeparator(c: Char): Boolean = c == '_'
@inline final private def isNumberSeparator(c: Char): Boolean = c == '_'

@`inline` private def removeNumberSeparators(s: String): String = if (s.indexOf('_') > 0) s.replace("_", "") else s
@inline final private def removeNumberSeparators(s: String): String = if (s.indexOf('_') > 0) s.replace("_", "") else s

@`inline` private def numberOffset = offset + (if (base == 10) 0 else 2)
@inline final private def numberOffset = offset + (if (base == 10) 0 else 2)

// disallow trailing numeric separator char
def checkNoTrailingSeparator(): Unit =
Expand Down
19 changes: 19 additions & 0 deletions src/compiler/scala/tools/nsc/backend/ScalaPrimitives.scala
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,24 @@ abstract class ScalaPrimitives {
primitives(s) = code
}

def addPrimitives(cls: Symbol, method: Name, code: Int): Unit =
cls.info.member(method).alternatives match {
case alts if alts.isEmpty => inform(s"Unknown primitive method $cls.$method")
case alts =>
for (alt <- alts) {
val code1 = code match {
case ADD =>
val info = exitingTyper(alt.info)
info.paramTypes match {
case tp :: _ if tp =:= StringTpe => CONCAT
case _ => code
}
case code => code
}
addPrimitive(alt, code1)
}
}
/*
def addPrimitives(cls: Symbol, method: Name, code: Int): Unit = {
val alts = (cls.info member method).alternatives
if (alts.isEmpty)
Expand All @@ -461,6 +479,7 @@ abstract class ScalaPrimitives {
)
)
}
*/

def isCoercion(code: Int): Boolean = (code >= B2B) && (code <= D2D)

Expand Down
3 changes: 2 additions & 1 deletion src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ abstract class BCodeHelpers extends BCodeIdiomatic {
// we prevent this, see `nonAnon` in LambdaLift.
// phase travel necessary: after flatten, the name includes the name of outer classes.
// if some outer name contains $lambda, a non-lambda class is considered lambda.
assert(exitingPickler(!classSym.isDelambdafyFunction), classSym.name)
val ok = exitingPickler(!classSym.isDelambdafyFunction)
assert(ok, classSym.name)
}
r
}
Expand Down
11 changes: 7 additions & 4 deletions src/compiler/scala/tools/nsc/backend/jvm/BTypesFromSymbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class BTypesFromSymbols[G <: Global](val global: G) extends BTypes {
import codeGen.CodeGenImpl._
import postProcessor.{bTypesFromClassfile, byteCodeRepository}

val coreBTypes = new CoreBTypesFromSymbols[G] {
val coreBTypes: CoreBTypesFromSymbols[G] { val bTypes: BTypesFromSymbols.this.type} = new CoreBTypesFromSymbols[G] {
val bTypes: BTypesFromSymbols.this.type = BTypesFromSymbols.this
}
import coreBTypes._
Expand Down Expand Up @@ -352,7 +352,8 @@ abstract class BTypesFromSymbols[G <: Global](val global: G) extends BTypes {
* declared but not otherwise referenced in C (from the bytecode or a method / field signature).
* We collect them here.
*/
lazy val nestedClassSymbols = {
lazy val nestedClassSymbols = nestedClassSymbolsComputed
def nestedClassSymbolsComputed = {
val linkedClass = exitingPickler(classSym.linkedClassOfClass) // linkedCoC does not work properly in late phases

// The lambdalift phase lifts all nested classes to the enclosing class, so if we collect
Expand Down Expand Up @@ -493,7 +494,8 @@ abstract class BTypesFromSymbols[G <: Global](val global: G) extends BTypes {
exitingPickler(innerClassSym.rawowner.linkedClassOfClass) match {
case NoSymbol =>
// For top-level modules without a companion class, see doc of mirrorClassClassBType.
mirrorClassClassBType(exitingPickler(innerClassSym.rawowner))
val rawowner = exitingPickler(innerClassSym.rawowner)
mirrorClassClassBType(rawowner)

case companionClass =>
classBTypeFromSymbol(companionClass)
Expand All @@ -515,7 +517,8 @@ abstract class BTypesFromSymbols[G <: Global](val global: G) extends BTypes {
else Some(s"${innerClassSym.rawname}${innerClassSym.moduleSuffix}") // moduleSuffix for module classes
}

Some(NestedInfo(enclosingClass, outerName, innerName, isStaticNestedClass, enteringTyper(innerClassSym.isPrivate)))
val isPrivate = enteringTyper(innerClassSym.isPrivate)
Some(NestedInfo(enclosingClass, outerName, innerName, isStaticNestedClass, isPrivate))
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ abstract class ClassfileWriters {
if (distinctOutputs.size == 1) new SingleClassWriter(FileWriter(global, distinctOutputs.head, jarManifestMainClass))
else {
val sourceToOutput: Map[AbstractFile, AbstractFile] = global.currentRun.units.map(unit => (unit.source.file, frontendAccess.compilerSettings.outputDirectory(unit.source.file))).toMap
new MultiClassWriter(sourceToOutput, distinctOutputs.iterator.map { output: AbstractFile => output -> FileWriter(global, output, jarManifestMainClass) }.toMap)
new MultiClassWriter(sourceToOutput, distinctOutputs.iterator.map { (output: AbstractFile) => output -> FileWriter(global, output, jarManifestMainClass) }.toMap)
}
}

Expand Down
Loading
Loading