Skip to content

Commit c8d78a3

Browse files
noti0na1WojciechMazur
authored andcommitted
Optimize caching for computing atoms and widened in OrTypes
[Cherry-picked ba0d8cb]
1 parent 7ceaf40 commit c8d78a3

File tree

2 files changed

+805
-6
lines changed

2 files changed

+805
-6
lines changed

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

+5-6
Original file line numberDiff line numberDiff line change
@@ -3695,6 +3695,7 @@ object Types extends TypeUtils {
36953695
myUnion
36963696

36973697
private var atomsRunId: RunId = NoRunId
3698+
private var widenedRunId: RunId = NoRunId
36983699
private var myAtoms: Atoms = uninitialized
36993700
private var myWidened: Type = uninitialized
37003701

@@ -3710,20 +3711,18 @@ object Types extends TypeUtils {
37103711
val tp2w = tp2.widenSingletons()
37113712
if ((tp1 eq tp1w) && (tp2 eq tp2w)) this else TypeComparer.lub(tp1w, tp2w, isSoft = isSoft)
37123713

3713-
private def ensureAtomsComputed()(using Context): Unit =
3714+
override def atoms(using Context): Atoms =
37143715
if atomsRunId != ctx.runId then
37153716
myAtoms = computeAtoms()
3716-
myWidened = computeWidenSingletons()
37173717
if !isProvisional then atomsRunId = ctx.runId
3718-
3719-
override def atoms(using Context): Atoms =
3720-
ensureAtomsComputed()
37213718
myAtoms
37223719

37233720
override def widenSingletons(skipSoftUnions: Boolean)(using Context): Type =
37243721
if isSoft && skipSoftUnions then this
37253722
else
3726-
ensureAtomsComputed()
3723+
if widenedRunId != ctx.runId then
3724+
myWidened = computeWidenSingletons()
3725+
if !isProvisional then widenedRunId = ctx.runId
37273726
myWidened
37283727

37293728
def derivedOrType(tp1: Type, tp2: Type, soft: Boolean = isSoft)(using Context): Type =

0 commit comments

Comments
 (0)