File tree Expand file tree Collapse file tree 8 files changed +24
-10
lines changed
compiler/src/dotty/tools/dotc/plugins
_docs/reference/changed-features
_spec/TODOreference/changed-features Expand file tree Collapse file tree 8 files changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import java.io.InputStream
1313import java .util .Properties
1414
1515import scala .util .{ Try , Success , Failure }
16+ import scala .annotation .nowarn
1617
1718trait PluginPhase extends MiniPhase {
1819 def runsBefore : Set [String ] = Set .empty
@@ -50,7 +51,19 @@ trait StandardPlugin extends Plugin {
5051 * @param options commandline options to the plugin.
5152 * @return a list of phases to be added to the phase plan
5253 */
53- def init (options : List [String ]): List [PluginPhase ]
54+ @ deprecated(" `init` does not allow to access `Context`, use `initialize` instead." , since = " 3.5.0" )
55+ def init (options : List [String ]): List [PluginPhase ] = Nil
56+
57+ /** Non-research plugins should override this method to return the phases
58+ *
59+ * The phases returned must be freshly constructed (not reused
60+ * and returned again on subsequent calls).
61+ *
62+ * @param options commandline options to the plugin.
63+ * @return a list of phases to be added to the phase plan
64+ */
65+ @ nowarn(" cat=deprecation" )
66+ def initialize (options : List [String ])(using Context ): List [PluginPhase ] = init(options)
5467}
5568
5669/** A research plugin may customize the compilation pipeline freely
Original file line number Diff line number Diff line change @@ -125,7 +125,7 @@ trait Plugins {
125125 }
126126
127127 // schedule plugins according to ordering constraints
128- val pluginPhases = plugins.collect { case p : StandardPlugin => p }.flatMap { plug => plug.init (options(plug)) }
128+ val pluginPhases = plugins.collect { case p : StandardPlugin => p }.flatMap { plug => plug.initialize (options(plug)) }
129129 val updatedPlan = Plugins .schedule(plan, pluginPhases)
130130
131131 // add research plugins
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ class DivideZero extends StandardPlugin:
6767 val name : String = " divideZero"
6868 override val description : String = " divide zero check"
6969
70- def init (options : List [String ]): List [PluginPhase ] =
70+ override def initialize (options : List [String ])( using Context ): List [PluginPhase ] =
7171 (new DivideZeroPhase ) :: Nil
7272
7373class DivideZeroPhase extends PluginPhase :
@@ -90,7 +90,7 @@ end DivideZeroPhase
9090```
9191
9292The plugin main class (` DivideZero ` ) must extend the trait ` StandardPlugin `
93- and implement the method ` init ` that takes the plugin's options as argument
93+ and implement the method ` initialize ` that takes the plugin's options as argument
9494and returns a list of ` PluginPhase ` s to be inserted into the compilation pipeline.
9595
9696Our plugin adds one compiler phase to the pipeline. A compiler phase must extend
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ class DivideZero extends StandardPlugin:
6767 val name : String = " divideZero"
6868 override val description : String = " divide zero check"
6969
70- def init (options : List [String ]): List [PluginPhase ] =
70+ override def initialize (options : List [String ])( using Context ): List [PluginPhase ] =
7171 (new DivideZeroPhase ) :: Nil
7272
7373class DivideZeroPhase extends PluginPhase :
@@ -90,7 +90,7 @@ end DivideZeroPhase
9090```
9191
9292The plugin main class (` DivideZero ` ) must extend the trait ` StandardPlugin `
93- and implement the method ` init ` that takes the plugin's options as argument
93+ and implement the method ` initialize ` that takes the plugin's options as argument
9494and returns a list of ` PluginPhase ` s to be inserted into the compilation pipeline.
9595
9696Our plugin adds one compiler phase to the pipeline. A compiler phase must extend
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ class InitPlugin extends StandardPlugin {
2121 val name : String = " initPlugin"
2222 override val description : String = " checks that under -Yretain-trees we may get tree for all symbols"
2323
24- def init (options : List [String ]): List [PluginPhase ] =
24+ override def initialize (options : List [String ])( using Context ): List [PluginPhase ] =
2525 (new SetDefTree ) :: (new InitChecker ) :: Nil
2626}
2727
Original file line number Diff line number Diff line change @@ -22,7 +22,8 @@ class DivideZero extends PluginPhase with StandardPlugin {
2222 override val runsAfter = Set (Pickler .name)
2323 override val runsBefore = Set (Staging .name)
2424
25- def init (options : List [String ]): List [PluginPhase ] = this :: Nil
25+ // We keep using deprecated variant here just to ensure it still works correctly
26+ override def init (options : List [String ]): List [PluginPhase ] = this :: Nil
2627
2728 private def isNumericDivide (sym : Symbol )(implicit ctx : Context ): Boolean = {
2829 def test (tpe : String ): Boolean =
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ class InitChecker extends PluginPhase with StandardPlugin {
5252 override val runsAfter = Set (SetDefTree .name)
5353 override val runsBefore = Set (FirstTransform .name)
5454
55- def init (options : List [String ]): List [PluginPhase ] = this :: (new SetDefTree ) :: Nil
55+ override def initialize (options : List [String ])( using Context ): List [PluginPhase ] = this :: (new SetDefTree ) :: Nil
5656
5757 private def checkDef (tree : Tree )(implicit ctx : Context ): Tree = {
5858 if (tree.symbol.defTree.isEmpty)
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ class DivideZero extends PluginPhase with StandardPlugin {
2020 override val runsAfter = Set (Pickler .name)
2121 override val runsBefore = Set (PickleQuotes .name)
2222
23- override def init (options : List [String ]): List [PluginPhase ] = this :: Nil
23+ override def initialize (options : List [String ])( using Context ): List [PluginPhase ] = this :: Nil
2424
2525 private def isNumericDivide (sym : Symbol )(implicit ctx : Context ): Boolean = {
2626 def test (tpe : String ): Boolean =
You can’t perform that action at this time.
0 commit comments