Skip to content

Commit c5e2283

Browse files
committed
Cache AppliedType#isStable
1 parent 2f16376 commit c5e2283

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ object Types {
175175
// see: tests/explicit-nulls/pos/flow-stable.scala.disabled
176176
tp.tp1.isStable && (realizability(tp.tp2) eq Realizable) ||
177177
tp.tp2.isStable && (realizability(tp.tp1) eq Realizable)
178-
case AppliedType(tycon: TypeRef, args) if defn.isCompiletimeAppliedType(tycon.symbol) && args.forall(_.isStable) => true
178+
case tp: AppliedType => tp.appliedTypeIsStable
179179
case _ => false
180180
}
181181

@@ -4161,11 +4161,23 @@ object Types {
41614161
// Boolean caches: 0 = uninitialized, -1 = false, 1 = true
41624162
private var myStableHash: Byte = 0
41634163
private var myGround: Byte = 0
4164+
private var myIsStable: Byte = 0
4165+
41644166

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

4171+
inline def appliedTypeIsStable(using Context): Boolean =
4172+
if myIsStable == 0 then
4173+
val isStable: Byte = tycon match
4174+
case tycon: TypeRef if defn.isCompiletimeAppliedType(tycon.symbol) && args.forall(_.isStable) => 1
4175+
case _ => -1
4176+
if !isProvisional then myIsStable = isStable
4177+
isStable > 0
4178+
else
4179+
myIsStable > 0
4180+
41694181
override def underlying(using Context): Type = tycon
41704182

41714183
override def superType(using Context): Type =

0 commit comments

Comments
 (0)