Skip to content

Commit 43239f1

Browse files
committed
Reduce context creations in implicits
1 parent 42a15b4 commit 43239f1

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ object Contexts {
674674
final def retractMode(mode: Mode): c.type = c.setMode(c.mode &~ mode)
675675
}
676676

677-
private def exploreCtx(using Context): Context =
677+
private def exploreCtx(using Context): FreshContext =
678678
util.Stats.record("explore")
679679
val base = ctx.base
680680
import base._
@@ -701,6 +701,10 @@ object Contexts {
701701
val ectx = exploreCtx
702702
try op(using ectx) finally wrapUpExplore(ectx)
703703

704+
inline def exploreInFreshCtx[T](inline op: FreshContext ?=> T)(using Context): T =
705+
val ectx = exploreCtx
706+
try op(using ectx) finally wrapUpExplore(ectx)
707+
704708
private def changeOwnerCtx(owner: Symbol)(using Context): Context =
705709
val base = ctx.base
706710
import base._

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,12 @@ object Implicits:
239239
if refs.isEmpty && (!considerExtension || companionRefs.isEmpty) then
240240
Nil
241241
else
242-
val nestedCtx = ctx.fresh.addMode(Mode.TypevarsMissContext)
243242
val candidates = new mutable.ListBuffer[Candidate]
244243
def tryCandidate(extensionOnly: Boolean)(ref: ImplicitRef) =
245-
var ckind = explore(candidateKind(ref.underlyingRef))(using nestedCtx)
244+
var ckind = exploreInFreshCtx { (using ctx: FreshContext) =>
245+
ctx.setMode(ctx.mode | Mode.TypevarsMissContext)
246+
candidateKind(ref.underlyingRef)
247+
}
246248
if extensionOnly then ckind &= Candidate.Extension
247249
if ckind != Candidate.None then
248250
candidates += Candidate(ref, ckind, level)

0 commit comments

Comments
 (0)