Does the Scala REPL ignore plugins?


#1

Hi,

I’m currently working on a codebase that has a custom Scala compiler plugin and they created a REPL for it that is initialized by doing:

settings.plugin.value ++= MagicPrivatePlugin :: Nil
sharedLoop.settings = settings

Where sharedLoop is a subclass of ILoop. Now all works fine and peachy with regard to compilation (no errors on the custom annotations, i.e. they are picked up correctly from the codebase), but if I enter a large block of code that contains the annotations that should trigger the plugin transformation (or even if i define things line by line) don’t happen and the block of code is compiled using the “normal” java compiler. This happens in both paste and one-line-at-a-time pmodes.

It seems to me that there is a problem with plugins (or, also, in the way these are attached to the repl), and wanted to ask if anyone else had this experience and if there is a workaround or if I’m going at this the wrong way?


#2

Showing a sample plugin in REPL:

$ scalam -Xplugin:. -Xplugin-list 
ploogin - A sample plugin for testing.
$ scalam -Xplugin:. -Xdev
[info] started at Wed Nov 21 03:18:12 PST 2018
Welcome to Scala 2.13.0-M5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_144).
Type in expressions for evaluation. Or try :help.

scala 2.13.0-M5> My phase name is ploogin
My phase name is ploogin
My phase name is ploogin


scala 2.13.0-M5> 42
My phase name is ploogin
My phase name is ploogin
res0: Int = 42

How are you launching the REPL?

Are you trying to mutate the settings after the compiler is constructed? I would expect that not to work.

-Xplugin takes paths to scan for scalac-plugin.xml. Use -Xplugin-require with your plugin name (per the xml) to ensure it was discovered.

  val plugin             = MultiStringSetting  ("-Xplugin", "paths", "Load a plugin from each classpath.")
  val disable            = MultiStringSetting  ("-Xplugin-disable", "plugin", "Disable plugins by name.")
  val showPlugins        = BooleanSetting      ("-Xplugin-list", "Print a synopsis of loaded plugins.")
  val require            = MultiStringSetting  ("-Xplugin-require", "plugin", "Abort if a named plugin is not loaded.")
  val pluginsDir         = StringSetting       ("-Xpluginsdir", "path", "Path to search for plugin archives.", Defaults.scalaPluginPath)