Skip to content

Commit 5e0a433

Browse files
committed
Delay creation of TypeAccumulator in depStatus
1 parent f3f7643 commit 5e0a433

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3286,32 +3286,37 @@ object Types {
32863286
private var myDependencyStatus: DependencyStatus = Unknown
32873287
private var myParamDependencyStatus: DependencyStatus = Unknown
32883288

3289-
private def depStatus(initial: DependencyStatus, tp: Type)(using Context): DependencyStatus = {
3290-
def combine(x: DependencyStatus, y: DependencyStatus) = {
3289+
private def depStatus(initial: DependencyStatus, tp: Type)(using Context): DependencyStatus =
3290+
def combine(x: DependencyStatus, y: DependencyStatus) =
32913291
val status = (x & StatusMask) max (y & StatusMask)
32923292
val provisional = (x | y) & Provisional
3293-
(if (status == TrueDeps) status else status | provisional).toByte
3294-
}
3295-
val depStatusAcc = new TypeAccumulator[DependencyStatus] {
3296-
def apply(status: DependencyStatus, tp: Type) =
3297-
if (status == TrueDeps) status
3298-
else
3299-
tp match {
3300-
case TermParamRef(`thisLambdaType`, _) => TrueDeps
3301-
case tp: TypeRef =>
3302-
val status1 = foldOver(status, tp)
3303-
tp.info match { // follow type alias to avoid dependency
3304-
case TypeAlias(alias) if status1 == TrueDeps && status != TrueDeps =>
3305-
combine(apply(status, alias), FalseDeps)
3306-
case _ =>
3307-
status1
3308-
}
3309-
case tp: TypeVar if !tp.isInstantiated => combine(status, Provisional)
3310-
case _ => foldOver(status, tp)
3293+
(if status == TrueDeps then status else status | provisional).toByte
3294+
def compute(status: DependencyStatus, tp: Type, theAcc: TypeAccumulator[DependencyStatus]): DependencyStatus =
3295+
def applyPrefix(tp: NamedType) =
3296+
if tp.currentSymbol.isStatic then status
3297+
else compute(status, tp.prefix, theAcc)
3298+
if status == TrueDeps then status
3299+
else tp match
3300+
case tp: TypeRef =>
3301+
val status1 = applyPrefix(tp)
3302+
tp.info match { // follow type alias to avoid dependency
3303+
case TypeAlias(alias) if status1 == TrueDeps =>
3304+
combine(compute(status, alias, theAcc), FalseDeps)
3305+
case _ =>
3306+
status1
33113307
}
3312-
}
3313-
depStatusAcc(initial, tp)
3314-
}
3308+
case tp: TypeVar if !tp.isInstantiated => combine(status, Provisional)
3309+
case TermParamRef(`thisLambdaType`, _) => TrueDeps
3310+
case tp: TermRef => applyPrefix(tp)
3311+
case _: ThisType | _: BoundType | NoPrefix => status
3312+
case _ =>
3313+
val acc =
3314+
if theAcc != null then theAcc
3315+
else new TypeAccumulator[DependencyStatus]:
3316+
def apply(status: DependencyStatus, tp: Type) = compute(status, tp, this)
3317+
acc.foldOver(status, tp)
3318+
compute(initial, tp, null)
3319+
end depStatus
33153320

33163321
/** The dependency status of this method. Some examples:
33173322
*

0 commit comments

Comments
 (0)