Skip to content

Commit 7e1b595

Browse files
Backport "Fix #20521: Optimise caching for computing atoms and widened in OrTypes" to 3.5.2 (#21453)
Backports #21223 to the 3.5.2 branch. PR submitted by the release tooling. [skip ci]
2 parents 2fdbe37 + 164ef36 commit 7e1b595

File tree

3 files changed

+814
-6
lines changed

3 files changed

+814
-6
lines changed

Diff for: .github/dependabot.yml

+9
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,12 @@ updates:
88
- hamzaremmal
99
reviewers:
1010
- hamzaremmal
11+
- package-ecosystem: bundler
12+
directory: '/docs/_spec'
13+
schedule:
14+
interval: weekly
15+
assignees:
16+
- hamzaremmal
17+
reviewers:
18+
- hamzaremmal
19+

Diff for: 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)