Skip to content

Commit b6704d7

Browse files
committed
Cache AppliedType.isStable
1 parent 9ca8891 commit b6704d7

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ object Types {
165165
case _: SingletonType | NoPrefix => true
166166
case tp: RefinedOrRecType => tp.parent.isStable
167167
case tp: ExprType => tp.resultType.isStable
168-
case AppliedType(tycon: TypeRef, args: List[Type])
169-
if defn.isCompiletimeAppliedType(tycon.symbol) && args.forall(_.isStable) => true
168+
case tp: AppliedType => tp.appliedTypeIsStable
170169
case tp: AnnotatedType =>
171170
// NOTE UncheckedStableAnnot was originally meant to be put on fields,
172171
// not on types. Allowing it on types is a Scala 3 extension. See:
@@ -4162,11 +4161,22 @@ object Types {
41624161
// Boolean caches: 0 = uninitialized, -1 = false, 1 = true
41634162
private var myStableHash: Byte = 0
41644163
private var myGround: Byte = 0
4164+
private var myIsStable: Boolean = false
4165+
private var myIsStableComputed: Boolean = false
4166+
41654167

41664168
def isGround(acc: TypeAccumulator[Boolean])(using Context): Boolean =
41674169
if myGround == 0 then myGround = if acc.foldOver(true, this) then 1 else -1
41684170
myGround > 0
41694171

4172+
def appliedTypeIsStable(using Context): Boolean =
4173+
if !myIsStableComputed then
4174+
myIsStable = tycon match
4175+
case tycon: TypeRef => defn.isCompiletimeAppliedType(tycon.symbol) && args.forall(_.isStable)
4176+
case _ => false
4177+
myIsStableComputed = true
4178+
myIsStable
4179+
41704180
override def underlying(using Context): Type = tycon
41714181

41724182
override def superType(using Context): Type =

0 commit comments

Comments
 (0)