Skip to content

Commit d4f3dfe

Browse files
committed
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.
1 parent 4d12135 commit d4f3dfe

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,21 @@ object Implicits {
4545
protected def filterMatching(pt: Type)(implicit ctx: Context): List[TermRef] = track("filterMatching") {
4646

4747
def refMatches(ref: TermRef)(implicit ctx: Context) = {
48-
48+
4949
def discardForView(tpw: Type, argType: Type): Boolean = tpw match {
50-
case tpw: MethodType =>
51-
tpw.isImplicit ||
52-
tpw.paramTypes.length != 1 ||
53-
!(argType <:< tpw.paramTypes.head)(ctx.fresh.withExploreTyperState)
54-
case tpw: PolyType =>
55-
discardForView((new WildApprox) apply tpw.resultType, argType)
50+
case mt: MethodType =>
51+
mt.isImplicit ||
52+
mt.paramTypes.length != 1 ||
53+
!(argType <:< mt.paramTypes.head)(ctx.fresh.withExploreTyperState)
54+
case poly: PolyType =>
55+
poly.resultType match {
56+
case mt: MethodType =>
57+
mt.isImplicit ||
58+
mt.paramTypes.length != 1 ||
59+
!(argType <:< ((new WildApprox) apply mt.paramTypes.head))(ctx.fresh.withExploreTyperState)
60+
case rtp =>
61+
discardForView((new WildApprox) apply rtp, argType)
62+
}
5663
case tpw: TermRef =>
5764
false // can't discard overloaded refs
5865
case tpw =>
@@ -65,7 +72,7 @@ object Implicits {
6572
true
6673
}
6774
}
68-
75+
6976
def discardForValueType(tpw: Type): Boolean = tpw match {
7077
case mt: MethodType => !mt.isImplicit
7178
case mt: PolyType => discardForValueType(tpw.resultType)
@@ -74,7 +81,7 @@ object Implicits {
7481

7582
def discard = pt match {
7683
case pt: ViewProto => discardForView(ref.widen, pt.argType)
77-
case _: ValueType => !defn.isFunctionType(pt) && discardForValueType(ref.widen)
84+
case _: ValueType => !defn.isFunctionType(pt) && discardForValueType(ref.widen)
7885
case _ => false
7986
}
8087

@@ -146,7 +153,7 @@ object Implicits {
146153
}
147154
}
148155

149-
private def computeEligible(tp: Type): List[TermRef] = ctx.traceIndented(i"computeEligible $tp in $refs%, %", implicitsDetailed) {
156+
private def computeEligible(tp: Type): List[TermRef] = /*>|>*/ ctx.traceIndented(i"computeEligible $tp in $refs%, %", implicitsDetailed) /*<|<*/ {
150157
if (monitored) record(s"check eligible refs in ctx", refs.length)
151158
val ownEligible = filterMatching(tp)
152159
if (outerCtx == NoContext) ownEligible

test/dotc/tests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class tests extends CompilerTest {
4343
@Test def neg_typedidents() = compileFile(negDir, "typedidents", xerrors = 2)
4444
@Test def neg_assignments() = compileFile(negDir, "assignments", xerrors = 3)
4545
@Test def neg_typers() = compileFile(negDir, "typers", xerrors = 10)
46+
//@Test def neg_rootImports = compileFile(negDir, "rootImplicits", xerrors = 2)
4647

4748
@Test def dotc = compileDir(dotcDir + "tools/dotc")
4849
@Test def dotc_ast = compileDir(dotcDir + "tools/dotc/ast")

0 commit comments

Comments
 (0)