aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-01-29 17:34:56 +0100
committerMartin Odersky <odersky@gmail.com>2014-01-29 17:34:56 +0100
commit818d42d20bae1c446e9d540ce801d63b0eb4450a (patch)
treeef1f9ab88d077a5928082fa0523cf3bcfca2f151 /src/dotty/tools/dotc
parenta4b3494a7fcdcb3513afd73099a12108d87e4e48 (diff)
downloaddotty-818d42d20bae1c446e9d540ce801d63b0eb4450a.tar.gz
dotty-818d42d20bae1c446e9d540ce801d63b0eb4450a.tar.bz2
dotty-818d42d20bae1c446e9d540ce801d63b0eb4450a.zip
Add early discarding of methods for eligible check.
MethodTypes and PolyTypes now check their argument for compatibility before setting up a complete isApplicable test.
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r--src/dotty/tools/dotc/core/StdNames.scala5
-rw-r--r--src/dotty/tools/dotc/typer/Inferencing.scala34
2 files changed, 33 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/core/StdNames.scala b/src/dotty/tools/dotc/core/StdNames.scala
index 5549ddd92..a20d26e42 100644
--- a/src/dotty/tools/dotc/core/StdNames.scala
+++ b/src/dotty/tools/dotc/core/StdNames.scala
@@ -26,7 +26,7 @@ object StdNames {
}
abstract class ScalaNames[N <: Name] extends DefinedNames[N] {
- private def encode(s: String): N = fromName(fromString(s).encode)
+ protected def encode(s: String): N = fromName(fromString(s).encode)
// Keywords, need to come first -----------------------
@@ -636,8 +636,7 @@ object StdNames {
class ScalaTypeNames extends ScalaNames[TypeName] {
protected implicit def fromString(s: String): TypeName = typeName(s)
- @switch def syntheticTypeParamName(i: Int): TypeName =
- typeName("T"+i)
+ @switch def syntheticTypeParamName(i: Int): TypeName = "T"+i
def syntheticTypeParamNames(num: Int): List[TypeName] =
(0 until num).map(syntheticTypeParamName)(breakOut)
diff --git a/src/dotty/tools/dotc/typer/Inferencing.scala b/src/dotty/tools/dotc/typer/Inferencing.scala
index c7945e3b5..28c406a47 100644
--- a/src/dotty/tools/dotc/typer/Inferencing.scala
+++ b/src/dotty/tools/dotc/typer/Inferencing.scala
@@ -208,8 +208,36 @@ object Inferencing {
// case rt: SelectionProto => rt.name.toString == "info"
// case _ => false
// }
- def isMatchedBy(tp: Type)(implicit ctx: Context) = /*ctx.conditionalTraceIndented(lookingForInfo, i"?.info isMatchedBy $tp ${tp.getClass}")*/ {
- ctx.typer.isApplicable(tp, argType :: Nil, resultType)
+ def isMatchedBy(tp: Type)(implicit ctx: Context): Boolean = /*ctx.conditionalTraceIndented(lookingForInfo, i"?.info isMatchedBy $tp ${tp.getClass}")*/ {
+ def discard(tp: Type): Boolean = tp.widen match {
+ case tpw: MethodType =>
+ tpw.isImplicit ||
+ tpw.paramTypes.length != 1 ||
+ !(argType <:< tpw.paramTypes.head)(ctx.fresh.withExploreTyperState)
+ case tpw: PolyType =>
+ discard((new WildApprox) apply tpw.resultType)
+// case tpw: TermRef =>
+// false
+ case _ =>
+ false
+ /* not yet
+ case tpw =>
+ def isConforms(sym: Symbol) =
+ sym.exists && sym.owner == defn.ScalaPredefModule.moduleClass && sym.name == tpnme.Conforms
+ if (isConforms(tpw.typeSymbol)) false
+ else {
+ if (ctx.typer.isApplicable(tp, argType :: Nil, resultType))
+ println(i"??? $tp is applicable to $this / typeSymbol = ${tpw.typeSymbol}")
+ true
+ }
+ */
+ }
+
+ if (discard(tp)) {
+ Stats.record("discarded eligible")
+ false
+ }
+ else ctx.typer.isApplicable(tp, argType :: Nil, resultType)
}
def derivedViewProto(argType: Type, resultType: Type)(implicit ctx: Context) =
@@ -285,7 +313,7 @@ object Inferencing {
*/
def normalize(tp: Type, pt: Type)(implicit ctx: Context): Type = Stats.track("normalize") {
tp.widenSingleton match {
- case pt: PolyType => normalize(constrained(pt).resultType, pt)
+ case poly: PolyType => normalize(constrained(poly).resultType, pt)
case mt: MethodType if !mt.isDependent /*&& !pt.isInstanceOf[ApplyingProto]*/ =>
if (mt.isImplicit) mt.resultType
else {