Skip to content

Commit 5079be7

Browse files
committed
Cache ctx.settings.Yscala2Stdlib.value
1 parent 2cd66da commit 5079be7

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import printing.Formatting.hl
1919
import config.Printers
2020

2121
import scala.annotation.internal.sharable
22+
import scala.annotation.threadUnsafe
2223

2324
object desugar {
2425
import untpd._
@@ -487,6 +488,7 @@ object desugar {
487488
def isNonEnumCase = !isEnumCase && (isCaseClass || isCaseObject)
488489
val isValueClass = parents.nonEmpty && isAnyVal(parents.head)
489490
// This is not watertight, but `extends AnyVal` will be replaced by `inline` later.
491+
val caseClassInScala2StdLib = isCaseClass && ctx.settings.Yscala2Stdlib.value
490492

491493
val originalTparams = constr1.leadingTypeParams
492494
val originalVparamss = asTermOnly(constr1.trailingParamss)
@@ -662,9 +664,7 @@ object desugar {
662664
// new C[...](p1, ..., pN)(moreParams)
663665
val (caseClassMeths, enumScaffolding) = {
664666
def syntheticProperty(name: TermName, tpt: Tree, rhs: Tree) =
665-
val mods =
666-
if ctx.settings.Yscala2Stdlib.value then synthetic | Inline
667-
else synthetic
667+
val mods = if caseClassInScala2StdLib then synthetic | Inline else synthetic
668668
DefDef(name, Nil, tpt, rhs).withMods(mods)
669669

670670
def productElemMeths =
@@ -782,7 +782,7 @@ object desugar {
782782
val unapplyParam = makeSyntheticParameter(tpt = classTypeRef)
783783
val unapplyRHS =
784784
if (arity == 0) Literal(Constant(true))
785-
else if ctx.settings.Yscala2Stdlib.value then scala2LibCompatUnapplyRhs(unapplyParam.name)
785+
else if caseClassInScala2StdLib then scala2LibCompatUnapplyRhs(unapplyParam.name)
786786
else Ident(unapplyParam.name)
787787
val unapplyResTp = if (arity == 0) Literal(Constant(true)) else TypeTree()
788788

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
8080
def newTransformer(using Context): Transformer =
8181
new PostTyperTransformer
8282

83+
private var compilingScala2StdLib = false
84+
override def initContext(ctx: FreshContext): Unit =
85+
compilingScala2StdLib = ctx.settings.Yscala2Stdlib.value(using ctx)
86+
8387
val superAcc: SuperAccessors = new SuperAccessors(thisPhase)
8488
val synthMbr: SyntheticMembers = new SyntheticMembers(thisPhase)
8589
val beanProps: BeanProperties = new BeanProperties(thisPhase)
@@ -536,7 +540,7 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
536540

537541
private def scala2LibPatch(tree: TypeDef)(using Context) =
538542
val sym = tree.symbol
539-
if ctx.settings.Yscala2Stdlib.value
543+
if compilingScala2StdLib
540544
&& sym.is(ModuleClass) && !sym.derivesFrom(defn.SerializableClass)
541545
&& sym.companionClass.derivesFrom(defn.SerializableClass)
542546
then
@@ -550,7 +554,7 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
550554
}
551555

552556
protected override def infoMayChange(sym: Symbol)(using Context): Boolean =
553-
ctx.settings.Yscala2Stdlib.value && sym.isAllOf(ModuleClass, butNot = Package)
557+
compilingScala2StdLib && sym.isAllOf(ModuleClass, butNot = Package)
554558

555559
def transformInfo(tp: Type, sym: Symbol)(using Context): Type = tp match
556560
case info: ClassInfo =>

0 commit comments

Comments
 (0)