Skip to content

Commit eee223b

Browse files
committed
Cache -Xsource comparisons in currentRun
1 parent c7c5d8e commit eee223b

File tree

15 files changed

+32
-24
lines changed

15 files changed

+32
-24
lines changed

src/compiler/scala/tools/nsc/Global.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,12 @@ class Global(var currentSettings: Settings, reporter0: LegacyReporter)
11291129
val profiler: Profiler = Profiler(settings)
11301130
keepPhaseStack = settings.log.isSetByUser
11311131

1132+
// We hit these checks regularly. They shouldn't change inside the same run, so cache the comparisons here.
1133+
val isScala212: Boolean = settings.isScala212
1134+
val isScala213: Boolean = settings.isScala213
1135+
val isScala214: Boolean = settings.isScala214
1136+
val isScala300: Boolean = settings.isScala300
1137+
11321138
// used in sbt
11331139
def uncheckedWarnings: List[(Position, String)] = reporting.uncheckedWarnings.map{case (pos, (msg, since)) => (pos, msg)}
11341140
// used in sbt

src/compiler/scala/tools/nsc/Parsing.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ trait Parsing { self : Positions with Reporting =>
2222

2323
trait RunParsing {
2424
val parsing: PerRunParsing = new PerRunParsing
25+
def isScala213: Boolean
26+
def isScala214: Boolean
2527
}
2628

2729
class PerRunParsing {

src/compiler/scala/tools/nsc/ast/parser/Parsers.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,7 +1901,7 @@ self =>
19011901
def msg(what: String, instead: String): String = s"`val` keyword in for comprehension is $what: $instead"
19021902
if (hasEq) {
19031903
val without = "instead, bind the value without `val`"
1904-
if (settings.isScala214) syntaxError(in.offset, msg("unsupported", without))
1904+
if (currentRun.isScala214) syntaxError(in.offset, msg("unsupported", without))
19051905
else deprecationWarning(in.offset, msg("deprecated", without), "2.10.0")
19061906
}
19071907
else syntaxError(in.offset, msg("unsupported", "just remove `val`"))
@@ -2324,7 +2324,7 @@ self =>
23242324
if (vds.isEmpty)
23252325
syntaxError(start, s"case classes must have a parameter list; try 'case class $name()' or 'case object $name'")
23262326
else if (vds.head.nonEmpty && vds.head.head.mods.isImplicit) {
2327-
if (settings.isScala213)
2327+
if (currentRun.isScala213)
23282328
syntaxError(start, s"case classes must have a non-implicit parameter list; try 'case class $name()$elliptical'")
23292329
else {
23302330
deprecationWarning(start, s"case classes should have a non-implicit parameter list; adapting to 'case class $name()$elliptical'", "2.12.2")
@@ -2455,7 +2455,7 @@ self =>
24552455
def msg(what: String) = s"""view bounds are $what; use an implicit parameter instead.
24562456
| example: instead of `def f[A <% Int](a: A)` use `def f[A](a: A)(implicit ev: A => Int)`""".stripMargin
24572457
while (in.token == VIEWBOUND) {
2458-
if (settings.isScala214) syntaxError(in.offset, msg("unsupported"))
2458+
if (currentRun.isScala214) syntaxError(in.offset, msg("unsupported"))
24592459
else deprecationWarning(in.offset, msg("deprecated"), "2.12.0")
24602460
contextBoundBuf += atPos(in.skipToken())(makeFunctionTypeTree(List(Ident(pname)), typ()))
24612461
}
@@ -2766,14 +2766,14 @@ self =>
27662766
val rhs =
27672767
if (isStatSep || in.token == RBRACE) {
27682768
if (restype.isEmpty) {
2769-
if (settings.isScala214) syntaxError(in.lastOffset, msg("unsupported", ": Unit"))
2769+
if (currentRun.isScala214) syntaxError(in.lastOffset, msg("unsupported", ": Unit"))
27702770
else deprecationWarning(in.lastOffset, msg("deprecated", ": Unit"), "2.13.0")
27712771
restype = scalaUnitConstr
27722772
}
27732773
newmods |= Flags.DEFERRED
27742774
EmptyTree
27752775
} else if (restype.isEmpty && in.token == LBRACE) {
2776-
if (settings.isScala214) syntaxError(in.offset, msg("unsupported", ": Unit ="))
2776+
if (currentRun.isScala214) syntaxError(in.offset, msg("unsupported", ": Unit ="))
27772777
else deprecationWarning(in.offset, msg("deprecated", ": Unit ="), "2.13.0")
27782778
restype = scalaUnitConstr
27792779
blockExpr()
@@ -2915,7 +2915,7 @@ self =>
29152915
classContextBounds = contextBoundBuf.toList
29162916
val tstart = (in.offset :: classContextBounds.map(_.pos.start)).min
29172917
if (!classContextBounds.isEmpty && mods.isTrait) {
2918-
val viewBoundsExist = if (settings.isScala214) "" else " nor view bounds `<% ...`"
2918+
val viewBoundsExist = if (currentRun.isScala214) "" else " nor view bounds `<% ...`"
29192919
syntaxError(s"traits cannot have type parameters with context bounds `: ...`$viewBoundsExist", skipIt = false)
29202920
classContextBounds = List()
29212921
}
@@ -3009,7 +3009,7 @@ self =>
30093009
val (self, body) = templateBody(isPre = true)
30103010
if (in.token == WITH && (self eq noSelfType)) {
30113011
val advice =
3012-
if (settings.isScala214) "use trait parameters instead."
3012+
if (currentRun.isScala214) "use trait parameters instead."
30133013
else "they will be replaced by trait parameters in 2.14, see the migration guide on avoiding var/val in traits."
30143014
deprecationWarning(braceOffset, s"early initializers are deprecated; $advice", "2.13.0")
30153015
val earlyDefs: List[Tree] = body.map(ensureEarlyDef).filter(_.nonEmpty)
@@ -3032,7 +3032,7 @@ self =>
30323032
copyValDef(vdef)(mods = mods | Flags.PRESUPER)
30333033
case tdef @ TypeDef(mods, name, tparams, rhs) =>
30343034
def msg(what: String): String = s"early type members are $what: move them to the regular body; the semantics are the same"
3035-
if (settings.isScala214) syntaxError(tdef.pos.point, msg("unsupported"))
3035+
if (currentRun.isScala214) syntaxError(tdef.pos.point, msg("unsupported"))
30363036
else deprecationWarning(tdef.pos.point, msg("deprecated"), "2.11.0")
30373037
treeCopy.TypeDef(tdef, mods | Flags.PRESUPER, name, tparams, rhs)
30383038
case docdef @ DocDef(comm, rhs) =>

src/compiler/scala/tools/nsc/ast/parser/Scanners.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ trait Scanners extends ScannersCommon {
577577
val isEmptyCharLit = (ch == '\'')
578578
getLitChar()
579579
if (ch == '\'') {
580-
if (isEmptyCharLit && settings.isScala213)
580+
if (isEmptyCharLit && currentRun.isScala213)
581581
syntaxError("empty character literal (use '\\'' for single quote)")
582582
else {
583583
if (isEmptyCharLit)

src/compiler/scala/tools/nsc/transform/UnCurry.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ abstract class UnCurry extends InfoTransform
436436
if (sym.isMethod) level < settings.elidebelow.value
437437
else {
438438
// TODO: report error? It's already done in RefChecks. https://github.com/scala/scala/pull/5539#issuecomment-331376887
439-
if (settings.isScala213) reporter.error(sym.pos, s"${sym.name}: Only methods can be marked @elidable.")
439+
if (currentRun.isScala213) reporter.error(sym.pos, s"${sym.name}: Only methods can be marked @elidable.")
440440
false
441441
}
442442
}

src/compiler/scala/tools/nsc/typechecker/Adaptations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ trait Adaptations {
9292
true // keep adaptation
9393
}
9494
if (args.isEmpty) {
95-
if (settings.isScala300) noAdaptation else deprecatedAdaptation
95+
if (currentRun.isScala300) noAdaptation else deprecatedAdaptation
9696
} else
9797
warnAdaptation
9898
}

src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ trait ContextErrors {
105105
def issueTypeError(err: AbsTypeError)(implicit context: Context): Unit = { context.issue(err) }
106106

107107
def typeErrorMsg(context: Context, found: Type, req: Type) =
108-
if (context.openImplicits.nonEmpty && !settings.XlogImplicits.value && settings.isScala213)
108+
if (context.openImplicits.nonEmpty && !settings.XlogImplicits.value && currentRun.isScala213)
109109
// OPT: avoid error string creation for errors that won't see the light of day, but predicate
110110
// this on -Xsource:2.13 for bug compatibility with https://github.com/scala/scala/pull/7147#issuecomment-418233611
111111
"type mismatch"

src/compiler/scala/tools/nsc/typechecker/Contexts.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,13 +1029,13 @@ trait Contexts { self: Analyzer =>
10291029
sym.isImplicit &&
10301030
isAccessible(sym, pre) &&
10311031
!(
1032-
// [eed3si9n] ideally I'd like to do this: val fd = settings.isScala214 && sym.isDeprecated
1032+
// [eed3si9n] ideally I'd like to do this: val fd = currentRun.isScala214 && sym.isDeprecated
10331033
// but implicit caching currently does not report sym.isDeprecated correctly.
1034-
settings.isScala214 && (sym == currentRun.runDefinitions.Predef_any2stringaddMethod)
1034+
currentRun.isScala214 && (sym == currentRun.runDefinitions.Predef_any2stringaddMethod)
10351035
) &&
10361036
!(imported && {
10371037
val e = scope.lookupEntry(name)
1038-
(e ne null) && (e.owner == scope) && (!settings.isScala212 || e.sym.exists)
1038+
(e ne null) && (e.owner == scope) && (!currentRun.isScala212 || e.sym.exists)
10391039
})
10401040

10411041
/** Do something with the symbols with name `name` imported via the import in `imp`,

src/compiler/scala/tools/nsc/typechecker/Implicits.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ trait Implicits {
10841084
result
10851085
}
10861086

1087-
if (settings.isScala213) matches
1087+
if (currentRun.isScala213) matches
10881088
else {
10891089
// most frequent one first under Scala 2.12 mode. We've turned this optimization off to avoid
10901090
// compilation order variation in whether a search succeeds or diverges.
@@ -1130,7 +1130,7 @@ trait Implicits {
11301130
foreach2(undetParams, savedInfos){ (up, si) => up.setInfo(si) }
11311131
}
11321132
}
1133-
if (typedFirstPending.isFailure && settings.isScala213)
1133+
if (typedFirstPending.isFailure && currentRun.isScala213)
11341134
undoLog.undoTo(mark) // Don't accumulate constraints from typechecking or type error message creation for failed candidates
11351135

11361136
// Pass the errors to `DivergentImplicitRecovery` so that it can note
@@ -1231,7 +1231,7 @@ trait Implicits {
12311231
* bound, the implicits infos which are members of these companion objects.
12321232
*/
12331233
private def companionImplicitMap(tp: Type): InfoMap = {
1234-
val isScala213 = settings.isScala213
1234+
val isScala213 = currentRun.isScala213
12351235

12361236
/* Populate implicit info map by traversing all parts of type `tp`.
12371237
* Parameters as for `getParts`.

src/compiler/scala/tools/nsc/typechecker/Infer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ trait Infer extends Checkable {
865865
case _ =>
866866
tpe2 match {
867867
case PolyType(tparams2, rtpe2) => isAsSpecificValueType(tpe1, rtpe2, undef1, undef2 ::: tparams2)
868-
case _ if !settings.isScala300 => existentialAbstraction(undef1, tpe1) <:< existentialAbstraction(undef2, tpe2)
868+
case _ if !currentRun.isScala300 => existentialAbstraction(undef1, tpe1) <:< existentialAbstraction(undef2, tpe2)
869869
case _ =>
870870
// Backport of fix for https://github.com/scala/bug/issues/2509
871871
// from Dotty https://github.com/lampepfl/dotty/commit/89540268e6c49fb92b9ca61249e46bb59981bf5a

src/compiler/scala/tools/nsc/typechecker/Namers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,7 @@ trait Namers extends MethodSynthesis {
16831683
val valOwner = owner.owner
16841684
// there's no overriding outside of classes, and we didn't use to do this in 2.11, so provide opt-out
16851685

1686-
if (!settings.isScala212 || !valOwner.isClass) WildcardType
1686+
if (!currentRun.isScala212 || !valOwner.isClass) WildcardType
16871687
else {
16881688
// normalize to getter so that we correctly consider a val overriding a def
16891689
// (a val's name ends in a " ", so can't compare to def)

src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ trait NamesDefaults { self: Analyzer =>
530530
val NamedArg(Ident(name), rhs) = arg
531531
params indexWhere (p => matchesName(p, name, argIndex)) match {
532532
case -1 =>
533-
val warnVariableInScope = !settings.isScala214 && context0.lookupSymbol(name, _.isVariable).isSuccess
533+
val warnVariableInScope = !currentRun.isScala214 && context0.lookupSymbol(name, _.isVariable).isSuccess
534534
UnknownParameterNameNamesDefaultError(arg, name, warnVariableInScope)
535535
case paramPos if argPos contains paramPos =>
536536
val existingArgIndex = argPos.indexWhere(_ == paramPos)

src/compiler/scala/tools/nsc/typechecker/RefChecks.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ abstract class RefChecks extends Transform {
14681468
reporter.error(sym.pos, s"${sym.name}: Only concrete methods can be marked @elidable.$rest")
14691469
}
14701470
}
1471-
if (settings.isScala213) checkIsElidable(tree.symbol)
1471+
if (currentRun.isScala213) checkIsElidable(tree.symbol)
14721472

14731473
tree match {
14741474
case m: MemberDef =>

src/compiler/scala/tools/nsc/typechecker/Unapplies.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ trait Unapplies extends ast.TreeDSL {
132132
case _ => nme.unapply
133133
}
134134
val cparams = List(ValDef(Modifiers(PARAM | SYNTHETIC), unapplyParamName, classType(cdef, tparams), EmptyTree))
135-
val resultType = if (!settings.isScala212) TypeTree() else { // fix for scala/bug#6541 under -Xsource:2.12
135+
val resultType = if (!currentRun.isScala212) TypeTree() else { // fix for scala/bug#6541 under -Xsource:2.12
136136
def repeatedToSeq(tp: Tree) = tp match {
137137
case AppliedTypeTree(Select(_, tpnme.REPEATED_PARAM_CLASS_NAME), tps) => AppliedTypeTree(gen.rootScalaDot(tpnme.Seq), tps)
138138
case _ => tp

src/reflect/scala/reflect/runtime/Settings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@ private[reflect] class Settings extends MutableSettings {
6161

6262
val Yrecursion = new IntSetting(0)
6363
def isScala212 = true
64-
private[scala] def isScala213 = false
64+
private[scala] def isScala213 = true
6565
}

0 commit comments

Comments
 (0)