diff options
author | Martin Odersky <odersky@gmail.com> | 2014-02-02 13:32:06 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-02-02 13:32:52 +0100 |
commit | d4f3dfee061de3a03bae59bea102d2796d724f81 (patch) | |
tree | 7fdf39450a29320e04670bcc08cdebc9814a462c /src/dotty/tools/dotc/typer/Implicits.scala | |
parent | 4d1213579885144ebb9653007e64065ff4a62e2e (diff) | |
download | dotty-d4f3dfee061de3a03bae59bea102d2796d724f81.tar.gz dotty-d4f3dfee061de3a03bae59bea102d2796d724f81.tar.bz2 dotty-d4f3dfee061de3a03bae59bea102d2796d724f81.zip |
Cheaper eligibility test for PolyTypes.
Instead of doing a wildApprox of the whole type, we fuse with the logix for method types and just do a wild approx of the single method type argument we have to test.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Implicits.scala')
-rw-r--r-- | src/dotty/tools/dotc/typer/Implicits.scala | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala index 358f20510..9eded7900 100644 --- a/src/dotty/tools/dotc/typer/Implicits.scala +++ b/src/dotty/tools/dotc/typer/Implicits.scala @@ -45,14 +45,21 @@ object Implicits { protected def filterMatching(pt: Type)(implicit ctx: Context): List[TermRef] = track("filterMatching") { def refMatches(ref: TermRef)(implicit ctx: Context) = { - + def discardForView(tpw: Type, argType: Type): Boolean = tpw match { - case tpw: MethodType => - tpw.isImplicit || - tpw.paramTypes.length != 1 || - !(argType <:< tpw.paramTypes.head)(ctx.fresh.withExploreTyperState) - case tpw: PolyType => - discardForView((new WildApprox) apply tpw.resultType, argType) + case mt: MethodType => + mt.isImplicit || + mt.paramTypes.length != 1 || + !(argType <:< mt.paramTypes.head)(ctx.fresh.withExploreTyperState) + case poly: PolyType => + poly.resultType match { + case mt: MethodType => + mt.isImplicit || + mt.paramTypes.length != 1 || + !(argType <:< ((new WildApprox) apply mt.paramTypes.head))(ctx.fresh.withExploreTyperState) + case rtp => + discardForView((new WildApprox) apply rtp, argType) + } case tpw: TermRef => false // can't discard overloaded refs case tpw => @@ -65,7 +72,7 @@ object Implicits { true } } - + def discardForValueType(tpw: Type): Boolean = tpw match { case mt: MethodType => !mt.isImplicit case mt: PolyType => discardForValueType(tpw.resultType) @@ -74,7 +81,7 @@ object Implicits { def discard = pt match { case pt: ViewProto => discardForView(ref.widen, pt.argType) - case _: ValueType => !defn.isFunctionType(pt) && discardForValueType(ref.widen) + case _: ValueType => !defn.isFunctionType(pt) && discardForValueType(ref.widen) case _ => false } @@ -146,7 +153,7 @@ object Implicits { } } - private def computeEligible(tp: Type): List[TermRef] = ctx.traceIndented(i"computeEligible $tp in $refs%, %", implicitsDetailed) { + private def computeEligible(tp: Type): List[TermRef] = /*>|>*/ ctx.traceIndented(i"computeEligible $tp in $refs%, %", implicitsDetailed) /*<|<*/ { if (monitored) record(s"check eligible refs in ctx", refs.length) val ownEligible = filterMatching(tp) if (outerCtx == NoContext) ownEligible |