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 LTS (#22073)

Backports #21223 to the 3.3.5.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Dec 3, 2024
2 parents cd902ac + 937afaa commit b8d4b7d
Show file tree
Hide file tree
Showing 2 changed files with 807 additions and 8 deletions.
15 changes: 7 additions & 8 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3510,8 +3510,9 @@ object Types extends TypeUtils {
myUnion

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

private def computeAtoms()(using Context): Atoms =
if tp1.hasClassSymbol(defn.NothingClass) then tp2.atoms
Expand All @@ -3523,18 +3524,16 @@ 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(using Context): Type =
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 b8d4b7d

Please sign in to comment.