diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-08-06 14:10:30 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-08-06 14:10:30 +1000 |
commit | 39ea54bf3eb681de7b0484f60e80002d45ebe7ba (patch) | |
tree | f0c45484118f6194dc78a41bd364db098533b2aa | |
parent | ccded7d179625b38d01a031a0d0f6aaa1bb658a7 (diff) | |
download | scala-39ea54bf3eb681de7b0484f60e80002d45ebe7ba.tar.gz scala-39ea54bf3eb681de7b0484f60e80002d45ebe7ba.tar.bz2 scala-39ea54bf3eb681de7b0484f60e80002d45ebe7ba.zip |
Fix tracing of implicit search under -Ytyper-debug
The log messages intented to chronicle implicit search were
always being filtered out by virtue of the fact that the the tree
passed to `printTyping` was already typed, (e.g. with an implicit
MethodType.)
This commit enabled printing in this case, although it still
filters out trees that are deemed unfit for typer tracing,
such as `()`. In the context of implicit search, this happens
to filter out the noise of:
```
| | | [search #2] start `()`, searching for adaptation to pt=Unit => Foo[Int,Int] (silent: value <local Test> in Test) implicits disabled
| | | [search #3] start `()`, searching for adaptation to pt=(=> Unit) => Foo[Int,Int] (silent: value <local Test> in Test) implicits disabled
| | | \-> <error>
```
... which I think is desirable.
The motivation for this fix was to better display the interaction
between implicit search and type inference. For instance:
```
class Foo[A, B]
class Test {
implicit val f: Foo[Int, String] = ???
def t[A, B](a: A)(implicit f: Foo[A, B]) = ???
t(1)
}
```
````
% scalac -Ytyper-debug sandbox/instantiate.scala
...
| |-- t(1) BYVALmode-EXPRmode (site: value <local Test> in Test)
| | |-- t BYVALmode-EXPRmode-FUNmode-POLYmode (silent: value <local Test> in Test)
| | | [adapt] [A, B](a: A)(implicit f: Foo[A,B])Nothing adapted to [A, B](a: A)(implicit f: Foo[A,B])Nothing
| | | \-> (a: A)(implicit f: Foo[A,B])Nothing
| | |-- 1 BYVALmode-EXPRmode-POLYmode (site: value <local Test> in Test)
| | | \-> Int(1)
| | solving for (A: ?A, B: ?B)
| | solving for (B: ?B)
| | [search #1] start `[A, B](a: A)(implicit f: Foo[A,B])Nothing` inferring type B, searching for adaptation to pt=Foo[Int,B] (silent: value <local Test> in Test) implicits disabled
| | [search #1] considering f
| | [adapt] f adapted to => Foo[Int,String] based on pt Foo[Int,B]
| | [search #1] solve tvars=?B, tvars.constr= >: String <: String
| | solving for (B: ?B)
| | [search #1] success inferred value of type Foo[Int,=?String] is SearchResult(Test.this.f, TreeTypeSubstituter(List(type B),List(String)))
| | |-- [A, B](a: A)(implicit f: Foo[A,B])Nothing BYVALmode-EXPRmode (site: value <local Test> in Test)
| | | \-> Nothing
| | [adapt] [A, B](a: A)(implicit f: Foo[A,B])Nothing adapted to [A, B](a: A)(implicit f: Foo[A,B])Nothing
| | \-> Nothing
```
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Implicits.scala | 6 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/TypersTracking.scala | 2 |
2 files changed, 5 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 7ec9cd74a4..14a64abfe2 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -324,8 +324,10 @@ trait Implicits { */ class ImplicitSearch(tree: Tree, pt: Type, isView: Boolean, context0: Context, pos0: Position = NoPosition) extends Typer(context0) with ImplicitsContextErrors { val searchId = implicitSearchId() - private def typingLog(what: String, msg: => String) = - typingStack.printTyping(tree, f"[search #$searchId] $what $msg") + private def typingLog(what: String, msg: => String) = { + if (printingOk(tree)) + typingStack.printTyping(f"[search #$searchId] $what $msg") + } import infer._ if (Statistics.canEnable) Statistics.incCounter(implicitSearchCount) diff --git a/src/compiler/scala/tools/nsc/typechecker/TypersTracking.scala b/src/compiler/scala/tools/nsc/typechecker/TypersTracking.scala index 550fd4e68d..37fbb73b85 100644 --- a/src/compiler/scala/tools/nsc/typechecker/TypersTracking.scala +++ b/src/compiler/scala/tools/nsc/typechecker/TypersTracking.scala @@ -159,7 +159,7 @@ trait TypersTracking { // Some trees which are typed with mind-numbing frequency and // which add nothing by being printed. Did () type to Unit? Let's // gamble on yes. - private def printingOk(t: Tree) = printTypings && (settings.debug.value || !noPrint(t)) + def printingOk(t: Tree) = printTypings && (settings.debug.value || !noPrint(t)) def noPrintTyping(t: Tree) = (t.tpe ne null) || !printingOk(t) def noPrintAdapt(tree1: Tree, tree2: Tree) = !printingOk(tree1) || ( (tree1.tpe == tree2.tpe) |