Skip to content

Commit

Permalink
Backport "Fix #20521: Optimise caching for computing atoms and widene…
Browse files Browse the repository at this point in the history
…d in OrTypes" to 3.5.2 (#21453)

Backports #21223 to the 3.5.2 branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Aug 27, 2024
2 parents 2fdbe37 + 164ef36 commit 7e1b595
Show file tree
Hide file tree
Showing 3 changed files with 814 additions and 6 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,12 @@ updates:
- hamzaremmal
reviewers:
- hamzaremmal
- package-ecosystem: bundler
directory: '/docs/_spec'
schedule:
interval: weekly
assignees:
- hamzaremmal
reviewers:
- hamzaremmal

11 changes: 5 additions & 6 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3695,6 +3695,7 @@ object Types extends TypeUtils {
myUnion

private var atomsRunId: RunId = NoRunId
private var widenedRunId: RunId = NoRunId
private var myAtoms: Atoms = uninitialized
private var myWidened: Type = uninitialized

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

private def ensureAtomsComputed()(using Context): Unit =
override def atoms(using Context): Atoms =
if atomsRunId != ctx.runId then
myAtoms = computeAtoms()
myWidened = computeWidenSingletons()
if !isProvisional then atomsRunId = ctx.runId

override def atoms(using Context): Atoms =
ensureAtomsComputed()
myAtoms

override def widenSingletons(skipSoftUnions: Boolean)(using Context): Type =
if isSoft && skipSoftUnions then this
else
ensureAtomsComputed()
if widenedRunId != ctx.runId then
myWidened = computeWidenSingletons()
if !isProvisional then widenedRunId = ctx.runId
myWidened

def derivedOrType(tp1: Type, tp2: Type, soft: Boolean = isSoft)(using Context): Type =
Expand Down
Loading

0 comments on commit 7e1b595

Please sign in to comment.