Skip to content

Commit 2633fb5

Browse files
committed
Move WConf cache to ContextBase
1 parent ccbe7da commit 2633fb5

File tree

4 files changed

+16
-26
lines changed

4 files changed

+16
-26
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,8 @@ object Contexts {
947947

948948
private[core] val reusableDataReader = ReusableInstance(new ReusableDataReader())
949949

950+
private[dotc] var wConfCache: (List[String], WConf) = _
951+
950952
def sharedCharArray(len: Int): Array[Char] =
951953
while len > charArray.length do
952954
charArray = new Array[Char](charArray.length * 2)

compiler/src/dotty/tools/dotc/reporting/WConf.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ final case class WConf(confs: List[(List[MessageFilter], Action)]):
3131
case (filters, action) if filters.forall(_.matches(message)) => action
3232
}.getOrElse(Action.Warning)
3333

34-
@sharable object WConf:
34+
object WConf:
3535
import Action._
3636
import MessageFilter._
3737

@@ -66,21 +66,21 @@ final case class WConf(confs: List[(List[MessageFilter], Action)]):
6666
case _ => Left(s"unknown filter: $s")
6767
}
6868

69-
private var parsedCache: (List[String], WConf) = null
7069
def parsed(using Context): WConf =
7170
val setting = ctx.settings.Wconf.value
72-
if parsedCache == null || parsedCache._1 != setting then
71+
def cached = ctx.base.wConfCache
72+
if cached == null || cached._1 != setting then
7373
val conf = fromSettings(setting)
74-
parsedCache = (setting, conf.getOrElse(WConf(Nil)))
74+
ctx.base.wConfCache = (setting, conf.getOrElse(WConf(Nil)))
7575
conf.swap.foreach(msgs =>
7676
val multiHelp =
77-
if (setting.sizeIs > 1)
77+
if setting.sizeIs > 1 then
7878
"""
7979
|Note: for multiple filters, use `-Wconf:filter1:action1,filter2:action2`
8080
| or alternatively `-Wconf:filter1:action1 -Wconf:filter2:action2`""".stripMargin
8181
else ""
8282
report.warning(s"Failed to parse `-Wconf` configuration: ${ctx.settings.Wconf.value.mkString(",")}\n${msgs.mkString("\n")}$multiHelp"))
83-
parsedCache._2
83+
cached._2
8484

8585
def fromSettings(settings: List[String]): Either[List[String], WConf] =
8686
if (settings.isEmpty) Right(WConf(Nil))

compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala

+8-4
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,19 @@ class ScalaSettingsTests:
6767
@Test def `WConf setting is parsed`: Unit =
6868
import reporting.{Action, Diagnostic, NoExplanation}
6969
val sets = new ScalaSettings
70-
val args = tokenize("-Wconf:cat=deprecation:w,cat=feature:w -Wconf:msg=message\\.pattern:s")
70+
val args = List("-Wconf:cat=deprecation:s,cat=feature:e", "-Wconf:msg=a problem\\.:s")
7171
val sumy = ArgsSummary(sets.defaultState, args, errors = Nil, warnings = Nil)
7272
val proc = sets.processArguments(sumy, processAll = true, skipped = Nil)
7373
val conf = sets.Wconf.valueIn(proc.sstate)
7474
val sut = reporting.WConf.fromSettings(conf).getOrElse(???)
7575
val msg = NoExplanation("There was a problem!")
76-
val diag = new Diagnostic.DeprecationWarning(msg, util.NoSourcePosition)
77-
assertEquals("Warns deprecation", Action.Warning, sut.action(diag))
76+
val depr = new Diagnostic.DeprecationWarning(msg, util.NoSourcePosition)
77+
assertEquals(Action.Silent, sut.action(depr))
7878
val feat = new Diagnostic.FeatureWarning(msg, util.NoSourcePosition)
79-
assertEquals("Warns feature", Action.Warning, sut.action(feat))
79+
assertEquals(Action.Error, sut.action(feat))
80+
val warn = new Diagnostic.Warning(msg, util.NoSourcePosition)
81+
assertEquals(Action.Warning, sut.action(warn))
82+
val nowr = new Diagnostic.Warning(NoExplanation("This is a problem."), util.NoSourcePosition)
83+
assertEquals(Action.Silent, sut.action(nowr))
8084

8185
end ScalaSettingsTests

compiler/test/dotty/tools/dotc/reporting/WConfTest.scala

-16
This file was deleted.

0 commit comments

Comments
 (0)