Skip to content

Commit b195113

Browse files
authored
Fix atoms computation of OrType (#16697)
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.
2 parents 07af300 + 80d536f commit b195113

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
@@ -3444,20 +3444,19 @@ object Types {
34443444
val tp2w = tp2.widenSingletons
34453445
if ((tp1 eq tp1w) && (tp2 eq tp2w)) this else TypeComparer.lub(tp1w, tp2w, isSoft = isSoft)
34463446

3447-
private def ensureAtomsComputed()(using Context): Boolean =
3448-
if atomsRunId != ctx.runId && !isProvisional then
3447+
private def ensureAtomsComputed()(using Context): Unit =
3448+
if atomsRunId != ctx.runId then
34493449
myAtoms = computeAtoms()
34503450
myWidened = computeWidenSingletons()
3451-
atomsRunId = ctx.runId
3452-
true
3453-
else
3454-
false
3451+
if !isProvisional then atomsRunId = ctx.runId
34553452

34563453
override def atoms(using Context): Atoms =
3457-
if ensureAtomsComputed() then myAtoms else computeAtoms()
3454+
ensureAtomsComputed()
3455+
myAtoms
34583456

34593457
override def widenSingletons(using Context): Type =
3460-
if ensureAtomsComputed() then myWidened else computeWidenSingletons()
3458+
ensureAtomsComputed()
3459+
myWidened
34613460

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

0 commit comments

Comments
 (0)