Skip to content

Commit 30f3ea1

Browse files
committed
Avoid recomputation of companionRefs
The previous condition for caching companionRefs contained a condition result.companionRefs.forall(implicitScopeCache.contains) which was always false because we cache types in `implicitCodeCache`, not companion refs. The new logic fixes this and does not need a second traversal because it is integrated in `iscopeRefs`.
1 parent d087448 commit 30f3ea1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,9 @@ trait ImplicitRunInfo { self: RunInfo =>
380380
EmptyTermRefSet // on the other hand, the refs of `tp` are now not accurate, so `tp` is marked incomplete.
381381
} else {
382382
seen += t
383-
iscope(t).companionRefs
383+
val is = iscope(t)
384+
if (!implicitScopeCache.contains(t)) incomplete += tp
385+
is.companionRefs
384386
}
385387
}
386388

@@ -436,10 +438,8 @@ trait ImplicitRunInfo { self: RunInfo =>
436438
if (ctx.typerState.ephemeral)
437439
record("ephemeral cache miss: implicitScope")
438440
else if (canCache &&
439-
((tp eq rootTp) || // first type traversed is always cached
440-
!incomplete.contains(tp) && // other types are cached if they are not incomplete
441-
result.companionRefs.forall( // and all their companion refs are cached
442-
implicitScopeCache.contains)))
441+
((tp eq rootTp) || // first type traversed is always cached
442+
!incomplete.contains(tp))) // other types are cached if they are not incomplete
443443
implicitScopeCache(tp) = result
444444
result
445445
}

0 commit comments

Comments
 (0)