Scala Programming Language
  1. Scala Programming Language
  2. SI-7494

Each plugin must only be instantiated once.

    Details

      Description

      The meaning of the following comment in Plugins.scala is that `loadAllFrom` in Plugin.scala must ensure uniqueness.

      The continuations plugin relies on this behavior, for instance. Once instantiated, a plugin is free to muck with its global. (A Subcomponent has no lifecycle for init and destroy operations.)

      If two continuations plugins are specified, the second, "stale" checker will not be "enabled." The enabled flag is propagated from the (proper) plugin to its subcomponents and to its checkers.

      // Each plugin must only be instantiated once. A common pattern
      // is to register annotation checkers during object construction, so
      // creating multiple plugin instances will leave behind stale checkers.
      

      Sample confusing output, which also occurs on 2.10 if $CJ is a nefarious file name like my-continuations.jar:

      $ scalac -verbose -Ylog:all -P:continuations:enable -Xplugin:$CJ t1807.scala
      ***
      [log <no phase>] instantiated cps plugin: scala.tools.selectivecps.SelectiveCPSPlugin@6fc33c70
      [log <no phase>] instantiated cps plugin: scala.tools.selectivecps.SelectiveCPSPlugin@7ab51662
      [loaded plugin continuations]
      [skipping a repeated plugin: continuations]
      ***
      t1807.scala:10: error: this code must be compiled with the Scala continuations plugin enabled
            val f: (() => Int @cps[Int]) = () => 1
                               ^
      [loaded class file /home/apm/projects/scala-pick/build/pack/lib/scala-library.jar(scala/util/continuations/cpsPlus.class) in 1ms]
      t1807.scala:10: error: this code must be compiled with the Scala continuations plugin enabled
            val f: (() => Int @cps[Int]) = () => 1
                                                 ^
      ***
      four errors found
      

      That's one more error than if you don't specify -P::enabled at all, so go figure.

        Activity

        Hide
        A. P. Marki added a comment -

        https://github.com/scala/scala/pull/2562

        All is as it was before, and the timeline has been restored in which the duplication is silently glossed over.

        It might be nice to issue a warning, in case someone is actually trying to monkey with the plugin in question.

        The state of the class path is not specified, so it's not obvious whether it ought to prefer -Xpluginsdir or -Xplugin:myplugin.jar. Presumably the answer is either pluginsdir because it's either earlier on the class path or actually on a parent class loader, or myplugin.jar because I specifically asked for it.

        Show
        A. P. Marki added a comment - https://github.com/scala/scala/pull/2562 All is as it was before, and the timeline has been restored in which the duplication is silently glossed over. It might be nice to issue a warning, in case someone is actually trying to monkey with the plugin in question. The state of the class path is not specified, so it's not obvious whether it ought to prefer -Xpluginsdir or -Xplugin:myplugin.jar. Presumably the answer is either pluginsdir because it's either earlier on the class path or actually on a parent class loader, or myplugin.jar because I specifically asked for it.
        Hide
        Jason Zaugg added a comment -

        I think this is of sufficient importance to be the last change in 2.11.0-M3.

        Show
        Jason Zaugg added a comment - I think this is of sufficient importance to be the last change in 2.11.0-M3.

          People

          • Assignee:
            A. P. Marki
            Reporter:
            A. P. Marki
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development