Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -337,25 +337,29 @@ trait ImplicitRunInfo { self: RunInfo =>
/** The implicit scope of type `tp`
* @param isLifted Type `tp` is the result of a `liftToClasses` application
*/
def iscope(tp: Type, isLifted: Boolean = false): OfTypeImplicits =
def iscope(tp: Type, isLifted: Boolean = false): OfTypeImplicits = {
def computeIScope(cacheResult: Boolean) = {
val savedEphemeral = ctx.typerState.ephemeral
ctx.typerState.ephemeral = false
try {
val liftedTp = if (isLifted) tp else liftToClasses(tp)
val result =
if (liftedTp ne tp) iscope(liftedTp, isLifted = true)
else ofTypeImplicits(collectCompanions(tp))
if (ctx.typerState.ephemeral) record("ephemeral cache miss: implicitScope")
else if(cacheResult) implicitScopeCache(tp) = result
result
}
finally ctx.typerState.ephemeral |= savedEphemeral
}

if (tp.hash == NotCached || !Config.cacheImplicitScopes)
ofTypeImplicits(collectCompanions(tp))
computeIScope(cacheResult = false)
else implicitScopeCache get tp match {
case Some(is) => is
case None =>
val savedEphemeral = ctx.typerState.ephemeral
ctx.typerState.ephemeral = false
try {
val liftedTp = if (isLifted) tp else liftToClasses(tp)
val result =
if (liftedTp ne tp) iscope(liftedTp, isLifted = true)
else ofTypeImplicits(collectCompanions(tp))
if (ctx.typerState.ephemeral) record("ephemeral cache miss: implicitScope")
else implicitScopeCache(tp) = result
result
}
finally ctx.typerState.ephemeral |= savedEphemeral
}
case None => computeIScope(cacheResult = true)
}
}

iscope(tp)
}
Expand Down