Skip to content

Commit 1c399d2

Browse files
committed
Fix base type computation
Previous algorithm was very slow for compileStdLib, because many intermediate applied typeds were computed. new algorithm computes significantly fewer types.
1 parent ddf4b16 commit 1c399d2

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

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

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,8 +1631,10 @@ object SymDenotations {
16311631
case _: TypeErasure.ErasedValueType => false
16321632
case tp: TypeRef if tp.symbol.isClass => true
16331633
case tp: TypeVar => tp.inst.exists && inCache(tp.inst)
1634-
case tp: TypeProxy => inCache(tp.underlying)
1635-
case tp: AndOrType => inCache(tp.tp1) && inCache(tp.tp2)
1634+
//case tp: TypeProxy => inCache(tp.underlying) // disabled, can re-enable insyead of last two lines for performance testing
1635+
//case tp: AndOrType => inCache(tp.tp1) && inCache(tp.tp2)
1636+
case tp: TypeProxy => isCachable(tp.underlying, btrCache)
1637+
case tp: AndOrType => isCachable(tp.tp1, btrCache) && isCachable(tp.tp2, btrCache)
16361638
case _ => true
16371639
}
16381640
}
@@ -1643,16 +1645,33 @@ object SymDenotations {
16431645
Stats.record(s"computeBaseType, ${tp.getClass}")
16441646
}
16451647
if (symbol.isStatic && tp.derivesFrom(symbol) && symbol.typeParams.isEmpty)
1646-
symbol.appliedRef
1648+
symbol.typeRef
16471649
else tp match {
1648-
case tp: RefType =>
1649-
val subcls = tp.symbol
1650-
if (subcls eq symbol)
1651-
tp
1652-
else subcls.denot match {
1653-
case cdenot: ClassDenotation =>
1654-
if (cdenot.baseClassSet contains symbol) foldGlb(NoType, tp.parentsNEW)
1655-
else NoType
1650+
case tp @ TypeRef(prefix, _) =>
1651+
val subsym = tp.symbol
1652+
if (subsym eq symbol) tp
1653+
else subsym.denot match {
1654+
case clsd: ClassDenotation =>
1655+
val owner = clsd.owner
1656+
val isOwnThis = prefix match {
1657+
case prefix: ThisType => prefix.cls eq owner
1658+
case NoPrefix => true
1659+
case _ => false
1660+
}
1661+
if (isOwnThis)
1662+
if (clsd.baseClassSet.contains(symbol)) foldGlb(NoType, clsd.classParentsNEW)
1663+
else NoType
1664+
else
1665+
baseTypeOf(clsd.typeRef).asSeenFrom(prefix, owner)
1666+
case _ =>
1667+
baseTypeOf(tp.superType)
1668+
}
1669+
case tp @ AppliedType(tycon, args) =>
1670+
val subsym = tycon.typeSymbol
1671+
if (subsym eq symbol) tp
1672+
else subsym.denot match {
1673+
case clsd: ClassDenotation =>
1674+
baseTypeOf(tycon).subst(clsd.typeParams, args)
16561675
case _ =>
16571676
baseTypeOf(tp.superType)
16581677
}
@@ -1671,7 +1690,7 @@ object SymDenotations {
16711690

16721691
/*>|>*/ ctx.debugTraceIndented(s"$tp.baseType($this)") /*<|<*/ {
16731692
Stats.record("baseTypeOf")
1674-
tp match {
1693+
tp.stripTypeVar match { // @!!! dealias?
16751694
case tp: CachedType =>
16761695
val btrCache = baseTypeCache
16771696
try {
@@ -1695,7 +1714,7 @@ object SymDenotations {
16951714
btrCache.put(tp, null)
16961715
throw ex
16971716
}
1698-
case _ =>
1717+
case tp =>
16991718
computeBaseTypeOf(tp)
17001719
}
17011720
}

0 commit comments

Comments
 (0)