From 03d0ffc637d650da2678619cfb84a09b08273787 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 27 Jan 2014 19:29:20 +0100 Subject: Better tracking of implicit search We now track eligible calls and the number of refs tested in an eligible call. --- .gitignore | 1 + src/dotty/tools/dotc/typer/Implicits.scala | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 4ac590576..af401d568 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ bin/ # idea .idea .idea_modules +/.worksheet/ diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala index a8985cf36..bbf7a5924 100644 --- a/src/dotty/tools/dotc/typer/Implicits.scala +++ b/src/dotty/tools/dotc/typer/Implicits.scala @@ -5,7 +5,7 @@ package typer import core._ import ast.{Trees, untpd, tpd, TreeInfo} import util.Positions._ -import util.Stats.track +import util.Stats.{track, record, monitored} import printing.Showable import Contexts._ import Types._ @@ -46,7 +46,8 @@ object Implicits { def refMatches(ref: TermRef)(implicit ctx: Context) = (ref.symbol isAccessibleFrom ref.prefix) && NoViewsAllowed.isCompatible(normalize(ref, pt), pt) - refs filter (refMatches(_)(ctx.fresh.withExploreTyperState.addMode(Mode.TypevarsMissContext))) // create a defensive copy of ctx to avoid constraint pollution + if (refs.isEmpty) refs + else refs filter (refMatches(_)(ctx.fresh.withExploreTyperState.addMode(Mode.TypevarsMissContext))) // create a defensive copy of ctx to avoid constraint pollution } } @@ -63,7 +64,13 @@ object Implicits { } /** The implicit references that are eligible for expected type `tp` */ - lazy val eligible: List[TermRef] = ctx.traceIndented(i"eligible($tp), companions = ${companionRefs.toList}%, %", implicits, show = true)(filterMatching(tp)) + lazy val eligible: List[TermRef] = + /*>|>*/ track("eligible in tpe") /*<|<*/ { + /*>|>*/ ctx.traceIndented(i"eligible($tp), companions = ${companionRefs.toList}%, %", implicits, show = true) /*<|<*/ { + if (refs.nonEmpty && monitored) record(s"check eligible refs in tpe", refs.length) + filterMatching(tp) + } + } override def toString = i"OfTypeImplicits($tp), companions = ${companionRefs.toList}%, %; refs = $refs%, %." @@ -80,11 +87,13 @@ object Implicits { private val eligibleCache = new mutable.LinkedHashMap[Type, List[TermRef]] /** The implicit references that are eligible for type `tp`. */ - def eligible(tp: Type): List[TermRef] = + def eligible(tp: Type): List[TermRef] = /*>|>*/ track(s"eligible in ctx") /*<|<*/ { if (tp.hash == NotCached) computeEligible(tp) else eligibleCache.getOrElseUpdate(tp, computeEligible(tp)) + } private def computeEligible(tp: Type): List[TermRef] = { + if (refs.nonEmpty && monitored) record(s"check eligible refs in ctx", refs.length) val ownEligible = filterMatching(tp) if (outerCtx == NoContext) ownEligible else ownEligible ::: { -- cgit v1.2.3