Skip to content

Commit 31a4874

Browse files
committed
Track some implicit timings
If Stats is enabled, track total time spent in - implicit search overall - searching implicits in context / in type scope - typedImplicit
1 parent 9f42ffa commit 31a4874

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,7 @@ trait Implicits:
976976
*/
977977
def inferImplicit(pt: Type, argument: Tree, span: Span)(using Context): SearchResult =
978978
trace(s"search implicit ${pt.show}, arg = ${argument.show}: ${argument.tpe.show}", implicits, show = true) {
979+
Stats.trackTime("inferImplicit ms") {
979980
record("inferImplicit")
980981
assert(ctx.phase.allowsImplicitSearch,
981982
if (argument.isEmpty) i"missing implicit parameter of type $pt after typer"
@@ -1015,12 +1016,12 @@ trait Implicits:
10151016
}
10161017
// If we are at the outermost implicit search then emit the implicit dictionary, if any.
10171018
ctx.searchHistory.emitDictionary(span, result)
1018-
}
1019+
}}
10191020

10201021
/** Try to typecheck an implicit reference */
10211022
def typedImplicit(cand: Candidate, pt: Type, argument: Tree, span: Span)(using Context): SearchResult = trace(i"typed implicit ${cand.ref}, pt = $pt, implicitsEnabled == ${ctx.mode is ImplicitsEnabled}", implicits, show = true) {
10221023
if ctx.run.isCancelled then NoMatchingImplicitsFailure
1023-
else
1024+
else Stats.trackTime("typed implicit ms") {
10241025
record("typedImplicit")
10251026
val ref = cand.ref
10261027
val generated: Tree = tpd.ref(ref).withSpan(span.startPos)
@@ -1083,7 +1084,7 @@ trait Implicits:
10831084
if (cand.isExtension) Applications.ExtMethodApply(adapted)
10841085
else adapted
10851086
SearchSuccess(returned, ref, cand.level)(ctx.typerState, ctx.gadt)
1086-
}
1087+
}}
10871088

10881089
/** An implicit search; parameters as in `inferImplicit` */
10891090
class ImplicitSearch(protected val pt: Type, protected val argument: Tree, span: Span)(using Context):
@@ -1299,8 +1300,14 @@ trait Implicits:
12991300

13001301
private def searchImplicit(contextual: Boolean): SearchResult =
13011302
val eligible =
1302-
if contextual then ctx.implicits.eligible(wildProto)
1303-
else implicitScope(wildProto).eligible
1303+
if contextual then
1304+
Stats.trackTime("contextual eligible ms") {
1305+
ctx.implicits.eligible(wildProto)
1306+
}
1307+
else
1308+
Stats.trackTime("implicit scope eligible ms") {
1309+
implicitScope(wildProto).eligible
1310+
}
13041311
searchImplicit(eligible, contextual) match
13051312
case result: SearchSuccess =>
13061313
result

0 commit comments

Comments
 (0)