Skip to content

Refactor settings & improve dx #19766

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

Merged
merged 15 commits into from
Mar 18, 2024
39 changes: 21 additions & 18 deletions compiler/src/dotty/tools/backend/jvm/BackendUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,7 @@ class BackendUtils(val postProcessor: PostProcessor) {
import bTypes.*
import coreBTypes.jliLambdaMetaFactoryAltMetafactoryHandle

// Keep synchronized with `minTargetVersion` and `maxTargetVersion` in ScalaSettings
lazy val classfileVersion: Int = compilerSettings.target match {
case "8" => asm.Opcodes.V1_8
case "9" => asm.Opcodes.V9
case "10" => asm.Opcodes.V10
case "11" => asm.Opcodes.V11
case "12" => asm.Opcodes.V12
case "13" => asm.Opcodes.V13
case "14" => asm.Opcodes.V14
case "15" => asm.Opcodes.V15
case "16" => asm.Opcodes.V16
case "17" => asm.Opcodes.V17
case "18" => asm.Opcodes.V18
case "19" => asm.Opcodes.V19
case "20" => asm.Opcodes.V20
case "21" => asm.Opcodes.V21
case "22" => asm.Opcodes.V22
}
lazy val classfileVersion: Int = BackendUtils.classfileVersionMap(compilerSettings.target.toInt)

lazy val extraProc: Int = {
import GenBCodeOps.addFlagIf
Expand Down Expand Up @@ -184,3 +167,23 @@ class BackendUtils(val postProcessor: PostProcessor) {
}
}
}

object BackendUtils {
lazy val classfileVersionMap: Map[Int, Int] = Map(
8 -> asm.Opcodes.V1_8,
9 -> asm.Opcodes.V9,
10 -> asm.Opcodes.V10,
11 -> asm.Opcodes.V11,
12 -> asm.Opcodes.V12,
13 -> asm.Opcodes.V13,
14 -> asm.Opcodes.V14,
15 -> asm.Opcodes.V15,
16 -> asm.Opcodes.V16,
17 -> asm.Opcodes.V17,
18 -> asm.Opcodes.V18,
19 -> asm.Opcodes.V19,
20 -> asm.Opcodes.V20,
21 -> asm.Opcodes.V21,
22 -> asm.Opcodes.V22,
)
}
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/CliCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ trait CliCommand:
protected def isVerbose(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): Boolean =
s.name.startsWith("-V") && s.name != "-V"
protected def isWarning(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): Boolean =
s.name.startsWith("-W") && s.name != "-W" || s.name == "-Xlint"
s.name.startsWith("-W") && s.name != "-W"
protected def isAdvanced(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): Boolean =
s.name.startsWith("-X") && s.name != "-X"
protected def isPrivate(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): Boolean =
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/config/CompilerCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import core.Contexts.*
abstract class CompilerCommand extends CliCommand:
type ConcreteSettings = ScalaSettings

final def helpMsg(using settings: ScalaSettings)(using SettingsState, Context): String =
final def helpMsg(using settings: ConcreteSettings)(using SettingsState, Context): String =
settings.allSettings.find(isHelping) match
case Some(s) => s.description
case _ =>
Expand All @@ -20,7 +20,7 @@ abstract class CompilerCommand extends CliCommand:
else if (settings.XshowPhases.value) phasesMessage
else ""

final def isHelpFlag(using settings: ScalaSettings)(using SettingsState): Boolean =
final def isHelpFlag(using settings: ConcreteSettings)(using SettingsState): Boolean =
import settings.*
val flags = Set(help, Vhelp, Whelp, Xhelp, Yhelp, showPlugins, XshowPhases)
flags.exists(_.value) || allSettings.exists(isHelping)
485 changes: 242 additions & 243 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions compiler/src/dotty/tools/dotc/config/ScalaSettingsProperties.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package dotty.tools.dotc
package config

import dotty.tools.backend.jvm.BackendUtils.classfileVersionMap
import dotty.tools.io.{AbstractFile, Directory, JDK9Reflectors, PlainDirectory, NoAbstractFile}
import scala.language.unsafeNulls

object ScalaSettingsProperties:

private lazy val minTargetVersion = classfileVersionMap.keysIterator.min
private lazy val maxTargetVersion = classfileVersionMap.keysIterator.max

def supportedTargetVersions: List[String] =
(minTargetVersion to maxTargetVersion).toList.map(_.toString)

def supportedReleaseVersions: List[String] =
if scala.util.Properties.isJavaAtLeast("9") then
val jdkVersion = JDK9Reflectors.runtimeVersionMajor(JDK9Reflectors.runtimeVersion()).intValue()
val maxVersion = Math.min(jdkVersion, maxTargetVersion)
(minTargetVersion to maxVersion).toList.map(_.toString)
else List(minTargetVersion).map(_.toString)

def supportedScalaReleaseVersions: List[String] =
ScalaRelease.values.toList.map(_.show)

def supportedSourceVersions: List[String] =
SourceVersion.values.toList.map(_.toString)

def defaultClasspath: String = sys.env.getOrElse("CLASSPATH", ".")

def defaultPageWidth: Int = {
val defaultWidth = 80
val columnsVar = System.getenv("COLUMNS")
if columnsVar != null then columnsVar.toInt
else if Properties.isWin then
val ansiconVar = System.getenv("ANSICON") // eg. "142x32766 (142x26)"
if ansiconVar != null && ansiconVar.matches("[0-9]+x.*") then
ansiconVar.substring(0, ansiconVar.indexOf("x")).toInt
else defaultWidth
else defaultWidth
}
Loading