Skip to content

Commit ce64c43

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

File tree

4 files changed

+25
-40
lines changed

4 files changed

+25
-40
lines changed

Diff for: 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)

Diff for: compiler/src/dotty/tools/dotc/reporting/WConf.scala

+15-20
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import dotty.tools.dotc.core.Contexts._
66
import dotty.tools.dotc.util.SourcePosition
77

88
import java.util.regex.PatternSyntaxException
9-
import scala.annotation.internal.sharable
109
import scala.collection.mutable.ListBuffer
1110
import scala.util.matching.Regex
1211

@@ -31,7 +30,7 @@ final case class WConf(confs: List[(List[MessageFilter], Action)]):
3130
case (filters, action) if filters.forall(_.matches(message)) => action
3231
}.getOrElse(Action.Warning)
3332

34-
@sharable object WConf:
33+
object WConf:
3534
import Action._
3635
import MessageFilter._
3736

@@ -49,38 +48,34 @@ final case class WConf(confs: List[(List[MessageFilter], Action)]):
4948
try Right(s.r)
5049
catch { case e: PatternSyntaxException => Left(s"invalid pattern `$s`: ${e.getMessage}") }
5150

52-
val splitter = raw"([^=]+)=(.+)".r
53-
54-
def parseFilter(s: String): Either[String, MessageFilter] = s match {
55-
case "any" => Right(Any)
56-
case splitter(filter, conf) => filter match {
57-
case "msg" => regex(conf).map(MessagePattern.apply)
58-
case "cat" =>
59-
conf match {
51+
def parseFilter(s: String): Either[String, MessageFilter] =
52+
val splitter = raw"([^=]+)=(.+)".r
53+
s match
54+
case "any" => Right(Any)
55+
case splitter(filter, conf) => filter match
56+
case "msg" => regex(conf).map(MessagePattern.apply)
57+
case "cat" => conf match
6058
case "deprecation" => Right(Deprecated)
6159
case "feature" => Right(Feature)
6260
case _ => Left(s"unknown category: $conf")
63-
}
64-
case _ => Left(s"unknown filter: $filter")
65-
}
66-
case _ => Left(s"unknown filter: $s")
67-
}
61+
case _ => Left(s"unknown filter: $filter")
62+
case _ => Left(s"unknown filter: $s")
6863

69-
private var parsedCache: (List[String], WConf) = null
7064
def parsed(using Context): WConf =
7165
val setting = ctx.settings.Wconf.value
72-
if parsedCache == null || parsedCache._1 != setting then
66+
def cached = ctx.base.wConfCache
67+
if cached == null || cached._1 != setting then
7368
val conf = fromSettings(setting)
74-
parsedCache = (setting, conf.getOrElse(WConf(Nil)))
69+
ctx.base.wConfCache = (setting, conf.getOrElse(WConf(Nil)))
7570
conf.swap.foreach(msgs =>
7671
val multiHelp =
77-
if (setting.sizeIs > 1)
72+
if setting.sizeIs > 1 then
7873
"""
7974
|Note: for multiple filters, use `-Wconf:filter1:action1,filter2:action2`
8075
| or alternatively `-Wconf:filter1:action1 -Wconf:filter2:action2`""".stripMargin
8176
else ""
8277
report.warning(s"Failed to parse `-Wconf` configuration: ${ctx.settings.Wconf.value.mkString(",")}\n${msgs.mkString("\n")}$multiHelp"))
83-
parsedCache._2
78+
cached._2
8479

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

Diff for: 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

Diff for: compiler/test/dotty/tools/dotc/reporting/WConfTest.scala

-16
This file was deleted.

0 commit comments

Comments
 (0)