Skip to content

Commit

Permalink
Optimize caching for computing atoms and widened in OrTypes
Browse files Browse the repository at this point in the history
[Cherry-picked ba0d8cb]
  • Loading branch information
noti0na1 authored and WojciechMazur committed Aug 27, 2024
1 parent 7ceaf40 commit c8d78a3
Show file tree
Hide file tree
Showing 2 changed files with 805 additions and 6 deletions.
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 c8d78a3

Please sign in to comment.