Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find all implicits

Tags:

scala

Is there a way in Scala to find and display all uses of implicits in my code, or compile without implicits enabled (so I get compilation errors)? I'm hoping to identify places where I'm unintentionally allocating extra memory in inner loops.

like image 225
Mike Avatar asked Dec 31 '11 00:12

Mike


2 Answers

You can use -Xprint:typer option and look at how the inner loops of interest are typed checked. The implicit calls will appear in the printed source code. You may need to pipe the output to a file so that you can search for the interesting sections.

Also the Scala Eclipse IDE nightlies at http://scala-ide.org/download/nightly.html have a display implicit feature. You have to enable it in the Preferences, Scala, Implicits section.

The double arrows on the left margin shows that an implicit is used:

enter image description here

On hover, it shows the details:

enter image description here

The IDEA scala plugin can also show implicit conversions with underline, see the same piece of code:

enter image description here

It should also show which one is used using the CTRL-SHIFT-Q shortcut, but I had less success with it...

like image 165
huynhjl Avatar answered Sep 23 '22 04:09

huynhjl


As of yesterday (it's just a coincidence) there is -Xlog-implicit-conversions.

scalac -Xlog-implicit-conversions -d /tmp /scala/trunk/src/library/scala/util/Random.scala 
/scala/trunk/src/library/scala/util/Random.scala:115: applied implicit conversion from Int to ?{val to: ?} = implicit def intWrapper(x: Int): scala.runtime.RichInt
    for (n <- buf.length to 2 by -1) {
                  ^
like image 38
psp Avatar answered Sep 24 '22 04:09

psp