Skip to content

Commit 80d536f

Browse files
committed
Fix atoms computation of OrType
Previously, pos/i7034.scala took more than a minute to compile on my M1 MacBook Pro. Now it takes 5 seconds. The file consists of an IArray with over 4000 string literal elements. The previous caching logic was faulty, which means there was a lot of repeated computation of large immutable sets.
1 parent ed81385 commit 80d536f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,20 +3441,19 @@ object Types {
34413441
val tp2w = tp2.widenSingletons
34423442
if ((tp1 eq tp1w) && (tp2 eq tp2w)) this else TypeComparer.lub(tp1w, tp2w, isSoft = isSoft)
34433443

3444-
private def ensureAtomsComputed()(using Context): Boolean =
3445-
if atomsRunId != ctx.runId && !isProvisional then
3444+
private def ensureAtomsComputed()(using Context): Unit =
3445+
if atomsRunId != ctx.runId then
34463446
myAtoms = computeAtoms()
34473447
myWidened = computeWidenSingletons()
3448-
atomsRunId = ctx.runId
3449-
true
3450-
else
3451-
false
3448+
if !isProvisional then atomsRunId = ctx.runId
34523449

34533450
override def atoms(using Context): Atoms =
3454-
if ensureAtomsComputed() then myAtoms else computeAtoms()
3451+
ensureAtomsComputed()
3452+
myAtoms
34553453

34563454
override def widenSingletons(using Context): Type =
3457-
if ensureAtomsComputed() then myWidened else computeWidenSingletons()
3455+
ensureAtomsComputed()
3456+
myWidened
34583457

34593458
def derivedOrType(tp1: Type, tp2: Type, soft: Boolean = isSoft)(using Context): Type =
34603459
if ((tp1 eq this.tp1) && (tp2 eq this.tp2) && soft == isSoft) this

0 commit comments

Comments
 (0)