Skip to content

Commit 27d7ff6

Browse files
committed
Keep ScalaSettings as a class
1 parent 1196ceb commit 27d7ff6

File tree

7 files changed

+23
-22
lines changed

7 files changed

+23
-22
lines changed

Diff for: compiler/src/dotty/tools/dotc/Driver.scala

-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ class Driver {
200200
}
201201

202202
def main(args: Array[String]): Unit = {
203-
println("settings: " + ScalaSettings.allSettings)
204203
// Preload scala.util.control.NonFatal. Otherwise, when trying to catch a StackOverflowError,
205204
// we may try to load it but fail with another StackOverflowError and lose the original exception,
206205
// see <https://groups.google.com/forum/#!topic/scala-user/kte6nak-zPM>.

Diff for: compiler/src/dotty/tools/dotc/config/CompilerCommand.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Settings.*
55
import core.Contexts.*
66

77
abstract class CompilerCommand extends CliCommand:
8-
type ConcreteSettings = ScalaSettings.type
8+
type ConcreteSettings = ScalaSettings
99

1010
final def helpMsg(using settings: ConcreteSettings)(using SettingsState, Context): String =
1111
settings.allSettings.find(isHelping) match

Diff for: compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

+14-13
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,7 @@ object ScalaSettingCategories:
2323
val AdvancedSetting = "X"
2424
val VerboseSetting = "V"
2525

26-
object ScalaSettings extends SettingGroup with AllScalaSettings:
27-
28-
val settingsByCategory: Map[String, List[Setting[_]]] =
29-
allSettings.groupBy(_.category)
30-
.view.mapValues(_.toList).toMap
31-
.withDefaultValue(Nil)
32-
def categories: List[String] = settingsByCategory.keys.toList
33-
val rootSettings: List[Setting[_]] = settingsByCategory(RootSetting)
34-
val warningSettings: List[Setting[_]] = settingsByCategory(WarningSetting)
35-
val forkSettings: List[Setting[_]] = settingsByCategory(ForkSetting)
36-
val advancedSettings: List[Setting[_]] = settingsByCategory(AdvancedSetting)
37-
val verboseSettings: List[Setting[_]] = settingsByCategory(VerboseSetting)
38-
val settingsByAliases: Map[String, Setting[_]] = allSettings.flatMap(s => s.aliases.map(_ -> s)).toMap
26+
object ScalaSettings:
3927

4028
private lazy val minTargetVersion = classfileVersionMap.keysIterator.map(_.toInt).min
4129
private lazy val maxTargetVersion = classfileVersionMap.keysIterator.map(_.toInt).max
@@ -69,6 +57,19 @@ object ScalaSettings extends SettingGroup with AllScalaSettings:
6957
else defaultWidth
7058
else defaultWidth
7159
}
60+
61+
class ScalaSettings extends SettingGroup, AllScalaSettings:
62+
val settingsByCategory: Map[String, List[Setting[_]]] =
63+
allSettings.groupBy(_.category)
64+
.view.mapValues(_.toList).toMap
65+
.withDefaultValue(Nil)
66+
def categories: List[String] = settingsByCategory.keys.toList
67+
val rootSettings: List[Setting[_]] = settingsByCategory(RootSetting)
68+
val warningSettings: List[Setting[_]] = settingsByCategory(WarningSetting)
69+
val forkSettings: List[Setting[_]] = settingsByCategory(ForkSetting)
70+
val advancedSettings: List[Setting[_]] = settingsByCategory(AdvancedSetting)
71+
val verboseSettings: List[Setting[_]] = settingsByCategory(VerboseSetting)
72+
val settingsByAliases: Map[String, Setting[_]] = allSettings.flatMap(s => s.aliases.map(_ -> s)).toMap
7273

7374
trait AllScalaSettings extends CommonScalaSettings, PluginSettings, VerboseSettings, WarningSettings, XSettings, YSettings:
7475
self: SettingGroup =>

Diff for: compiler/src/dotty/tools/dotc/core/Contexts.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ object Contexts {
513513
s"""Context(
514514
|${outersIterator.map(ctx => cinfo(using ctx)).mkString("\n\n")})""".stripMargin
515515

516-
def settings: ScalaSettings.type = base.settings
516+
def settings: ScalaSettings = base.settings
517517
def definitions: Definitions = base.definitions
518518
def platform: Platform = base.platform
519519
def pendingUnderlying: util.HashSet[Type] = base.pendingUnderlying
@@ -861,7 +861,7 @@ object Contexts {
861861
with Phases.PhasesBase
862862
with Plugins {
863863

864-
val settings: ScalaSettings.type = ScalaSettings
864+
val settings: ScalaSettings = new ScalaSettings()
865865

866866
/** The initial context */
867867
val initialCtx: Context = FreshContext.initial(this: @unchecked, settings)

Diff for: compiler/test/dotty/tools/dotc/ScalaCommandTest.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ScalaCommandTest:
1717
def temporaryFolder = _temporaryFolder
1818

1919
@Test def `Simple one parameter`: Unit = inContext {
20-
val settings = config.ScalaSettings
20+
val settings = new config.ScalaSettings()
2121
val args = "-cp path/to/classes1:other/path/to/classes2 files".split(" ")
2222
val summary = ScalacCommand.distill(args, settings)()
2323
given SettingsState = summary.sstate
@@ -26,7 +26,7 @@ class ScalaCommandTest:
2626
}
2727

2828
@Test def `Unfold @file`: Unit = inContext {
29-
val settings = config.ScalaSettings
29+
val settings = new config.ScalaSettings()
3030
val file = temporaryFolder.newFile("config")
3131
val writer = java.io.FileWriter(file);
3232
writer.write("-sourceroot myNewRoot someMoreFiles");

Diff for: compiler/test/dotty/tools/dotc/TastyBootstrapTests.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class TastyBootstrapTests {
5151
Properties.compilerInterface, Properties.scalaLibrary, Properties.scalaAsm,
5252
Properties.dottyInterfaces, Properties.jlineTerminal, Properties.jlineReader,
5353
).mkString(File.pathSeparator),
54-
Array("-Ycheck-reentrant", "-language:postfixOps", "-Xsemanticdb")
54+
Array("-Ycheck-reentrant", "-Ylog:checkReentrant+", "-language:postfixOps", "-Xsemanticdb")
5555
)
5656

5757
val libraryDirs = List(Paths.get("library/src"), Paths.get("library/src-bootstrapped"))
@@ -61,6 +61,7 @@ class TastyBootstrapTests {
6161
compileList("lib", librarySources,
6262
defaultOptions.and("-Ycheck-reentrant",
6363
"-language:experimental.erasedDefinitions", // support declaration of scala.compiletime.erasedValue
64+
"-Ylog:checkReentrant+",
6465
// "-source", "future", // TODO: re-enable once library uses updated syntax for vararg splices, wildcard imports, and import renaming
6566
))(libGroup)
6667

Diff for: compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class ScalaSettingsTests:
6767

6868
@Test def `WConf setting is parsed`: Unit =
6969
import reporting.{Action, Diagnostic, NoExplanation}
70-
val sets = ScalaSettings
70+
val sets = new ScalaSettings()
7171
val args = List("-Wconf:cat=deprecation:s,cat=feature:e", "-Wconf:msg=a problem\\.:s")
7272
val sumy = ArgsSummary(sets.defaultState, args, errors = Nil, warnings = Nil)
7373
val proc = sets.processArguments(sumy, processAll = true, skipped = Nil)
@@ -85,7 +85,7 @@ class ScalaSettingsTests:
8585

8686
@Test def `i18367 rightmost WConf flags take precedence over flags to the left`: Unit =
8787
import reporting.{Action, Diagnostic}
88-
val sets = ScalaSettings
88+
val sets = new ScalaSettings()
8989
val args = List("-Wconf:cat=deprecation:e", "-Wconf:cat=deprecation:s")
9090
val sumy = ArgsSummary(sets.defaultState, args, errors = Nil, warnings = Nil)
9191
val proc = sets.processArguments(sumy, processAll = true, skipped = Nil)

0 commit comments

Comments
 (0)