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.
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:
On hover, it shows the details:
The IDEA scala plugin can also show implicit conversions with underline, see the same piece of code:
It should also show which one is used using the CTRL-SHIFT-Q shortcut, but I had less success with it...
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) {
^
© 2022 - 2024 — McMap. All rights reserved.