Skip to content

Commit 1e81135

Browse files
committed
Cache ictx.settings.Yscala2Stdlib.value
1 parent 94ff3f2 commit 1e81135

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

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

Lines changed: 5 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._
@@ -440,6 +441,8 @@ object desugar {
440441

441442
/** The expansion of a class definition. See inline comments for what is involved */
442443
def classDef(cdef: TypeDef)(using Context): Tree = {
444+
@threadUnsafe lazy val compilingScala2StdLib = ctx.settings.Yscala2Stdlib.value
445+
443446
val impl @ Template(constr0, _, self, _) = cdef.rhs: @unchecked
444447
val className = normalizeName(cdef, impl).asTypeName
445448
val parents = impl.parents
@@ -662,9 +665,7 @@ object desugar {
662665
// new C[...](p1, ..., pN)(moreParams)
663666
val (caseClassMeths, enumScaffolding) = {
664667
def syntheticProperty(name: TermName, tpt: Tree, rhs: Tree) =
665-
val mods =
666-
if ctx.settings.Yscala2Stdlib.value then synthetic | Inline
667-
else synthetic
668+
val mods = if compilingScala2StdLib then synthetic | Inline else synthetic
668669
DefDef(name, Nil, tpt, rhs).withMods(mods)
669670

670671
def productElemMeths =
@@ -778,7 +779,7 @@ object desugar {
778779
val unapplyParam = makeSyntheticParameter(tpt = classTypeRef)
779780
val unapplyRHS =
780781
if (arity == 0) Literal(Constant(true))
781-
else if ctx.settings.Yscala2Stdlib.value then scala2LibCompatUnapplyRhs(unapplyParam.name)
782+
else if compilingScala2StdLib then scala2LibCompatUnapplyRhs(unapplyParam.name)
782783
else Ident(unapplyParam.name)
783784
val unapplyResTp = if (arity == 0) Literal(Constant(true)) else TypeTree()
784785

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import util.SrcPos
2020
import reporting._
2121
import NameKinds.WildcardParamName
2222

23+
import scala.annotation.{constructorOnly, threadUnsafe}
24+
2325
object PostTyper {
2426
val name: String = "posttyper"
2527
val description: String = "additional checks and cleanups after type checking"
@@ -78,7 +80,7 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
7880
override def transformPhase(using Context): Phase = thisPhase.next
7981

8082
def newTransformer(using Context): Transformer =
81-
new PostTyperTransformer
83+
new PostTyperTransformer(ctx)
8284

8385
val superAcc: SuperAccessors = new SuperAccessors(thisPhase)
8486
val synthMbr: SyntheticMembers = new SyntheticMembers(thisPhase)
@@ -93,7 +95,9 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
9395
// TODO fill in
9496
}
9597

96-
class PostTyperTransformer extends Transformer {
98+
class PostTyperTransformer(@constructorOnly ictx: Context) extends Transformer {
99+
100+
@threadUnsafe private val compilingScala2StdLib = ictx.settings.Yscala2Stdlib.value(using ictx)
97101

98102
private var inJavaAnnot: Boolean = false
99103

@@ -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

0 commit comments

Comments
 (0)