Skip to content

Commit 005a338

Browse files
committed
Reduce context creations in implicits
1 parent f204745 commit 005a338

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

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

+5-1
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

+4-2
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,12 @@ object Implicits:
245245
if refs.isEmpty && (!considerExtension || companionRefs.isEmpty) then
246246
Nil
247247
else
248-
val nestedCtx = ctx.fresh.addMode(Mode.TypevarsMissContext)
249248
val candidates = new mutable.ListBuffer[Candidate]
250249
def tryCandidate(extensionOnly: Boolean)(ref: ImplicitRef) =
251-
var ckind = explore(candidateKind(ref.underlyingRef))(using nestedCtx)
250+
var ckind = exploreInFreshCtx { (using ctx: FreshContext) =>
251+
ctx.setMode(ctx.mode | Mode.TypevarsMissContext)
252+
candidateKind(ref.underlyingRef)
253+
}
252254
if extensionOnly then ckind &= Candidate.Extension
253255
if ckind != Candidate.None then
254256
candidates += Candidate(ref, ckind, level)

0 commit comments

Comments
 (0)