Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
918 views
in Technique[技术] by (71.8m points)

scala - Find all implicits

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...