Skip to content

Commit adefc4a

Browse files
committed
optimize the uncachable check
1 parent b9b4767 commit adefc4a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

compiler/src/dotty/tools/dotc/cc/CapturingType.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ object CapturingType:
4848
EventuallyCapturingType.unapply(tp)
4949
else None
5050

51+
/** Check whether a type is uncachable when computing `baseType`.
52+
* - Avoid caching all the types during the setup phase, since at that point
53+
* the captrue set variables are not fully installed yet.
54+
* - Avoid caching capturing types when IgnoreCaptures mode is set, since the
55+
* capture sets may be thrown away in the computed base type.
56+
*/
57+
def isUncachable(tp: Type)(using Context): Boolean =
58+
ctx.phase == Phases.checkCapturesPhase &&
59+
(Setup.isDuringSetup || ctx.mode.is(Mode.IgnoreCaptures) && tp.isEventuallyCapturingType)
60+
5161
end CapturingType
5262

5363
/** An extractor for types that will be capturing types at phase CheckCaptures. Also

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,15 +2140,14 @@ object SymDenotations {
21402140
final def baseTypeOf(tp: Type)(using Context): Type = {
21412141
val btrCache = baseTypeCache
21422142
def inCache(tp: Type) = tp match
2143-
case EventuallyCapturingType(_, _) => false
21442143
case tp: CachedType => btrCache.contains(tp)
21452144
case _ => false
21462145
def record(tp: CachedType, baseTp: Type) = {
21472146
if (Stats.monitored) {
21482147
Stats.record("basetype cache entries")
21492148
if (!baseTp.exists) Stats.record("basetype cache NoTypes")
21502149
}
2151-
if (!tp.isProvisional && !tp.isEventuallyCapturingType && !Setup.isDuringSetup)
2150+
if (!tp.isProvisional && !CapturingType.isUncachable(tp))
21522151
btrCache(tp) = baseTp
21532152
else
21542153
btrCache.remove(tp) // Remove any potential sentinel value

0 commit comments

Comments
 (0)