Skip to content

Commit 743c812

Browse files
committed
Try provisional state in OrType
1 parent e38f059 commit 743c812

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

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

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3687,22 +3687,24 @@ object Types extends TypeUtils {
36873687
}
36883688

36893689
private var myUnion: Type = uninitialized
3690+
private var myUnionProvStatus: ProvisionalState | Null = null
36903691
private var myUnionPeriod: Period = Nowhere
36913692

36923693
override def widenUnionWithoutNull(using Context): Type =
3693-
if myUnionPeriod != ctx.period then
3694+
if myUnionPeriod != ctx.period
3695+
|| !isCacheUpToDate(currentProvisionalState, myUnionProvStatus) then
36943696
val union = TypeComparer.lub(
36953697
tp1.widenUnionWithoutNull, tp2.widenUnionWithoutNull, canConstrain = isSoft, isSoft = isSoft)
36963698
myUnion = union match
36973699
case union: OrType if isSoft => union.join
36983700
case _ => union
3699-
if !isProvisional then myUnionPeriod = ctx.period
3701+
myUnionProvStatus = currentProvisionalState
3702+
myUnionPeriod = ctx.period
37003703
myUnion
37013704

3702-
private var atomsRunId: RunId = NoRunId
3703-
private var widenedRunId: RunId = NoRunId
37043705
private var myAtoms: Atoms = uninitialized
3705-
private var myWidened: Type = uninitialized
3706+
private var myAtomsProvStatus: ProvisionalState | Null = null
3707+
private var myAtomsRunId: RunId = NoRunId
37063708

37073709
private def computeAtoms()(using Context): Atoms =
37083710
val tp1n = tp1.normalized
@@ -3711,23 +3713,31 @@ object Types extends TypeUtils {
37113713
else if tp2n.hasClassSymbol(defn.NothingClass) then tp1.atoms
37123714
else tp1n.atoms | tp2n.atoms
37133715

3716+
override def atoms(using Context): Atoms =
3717+
if myAtomsRunId != ctx.runId
3718+
|| !isCacheUpToDate(currentProvisionalState, myAtomsProvStatus) then
3719+
myAtoms = computeAtoms()
3720+
myAtomsProvStatus = currentProvisionalState
3721+
myAtomsRunId = ctx.runId
3722+
myAtoms
3723+
3724+
private var myWidened: Type = uninitialized
3725+
private var myWidenedProvStatus: ProvisionalState | Null = null
3726+
private var myWidenedRunId: RunId = NoRunId
3727+
37143728
private def computeWidenSingletons()(using Context): Type =
37153729
val tp1w = tp1.widenSingletons()
37163730
val tp2w = tp2.widenSingletons()
37173731
if ((tp1 eq tp1w) && (tp2 eq tp2w)) this else TypeComparer.lub(tp1w, tp2w, isSoft = isSoft)
37183732

3719-
override def atoms(using Context): Atoms =
3720-
if atomsRunId != ctx.runId then
3721-
myAtoms = computeAtoms()
3722-
if !isProvisional then atomsRunId = ctx.runId
3723-
myAtoms
3724-
37253733
override def widenSingletons(skipSoftUnions: Boolean)(using Context): Type =
37263734
if isSoft && skipSoftUnions then this
37273735
else
3728-
if widenedRunId != ctx.runId then
3736+
if myWidenedRunId != ctx.runId
3737+
|| !isCacheUpToDate(currentProvisionalState, myWidenedProvStatus) then
37293738
myWidened = computeWidenSingletons()
3730-
if !isProvisional then widenedRunId = ctx.runId
3739+
myWidenedProvStatus = currentProvisionalState
3740+
myWidenedRunId = ctx.runId
37313741
myWidened
37323742

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

0 commit comments

Comments
 (0)