File tree 8 files changed +24
-10
lines changed
compiler/src/dotty/tools/dotc/plugins
_docs/reference/changed-features
_spec/TODOreference/changed-features
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
13
13
import java .util .Properties
14
14
15
15
import scala .util .{ Try , Success , Failure }
16
+ import scala .annotation .nowarn
16
17
17
18
trait PluginPhase extends MiniPhase {
18
19
def runsBefore : Set [String ] = Set .empty
@@ -50,7 +51,19 @@ trait StandardPlugin extends Plugin {
50
51
* @param options commandline options to the plugin.
51
52
* @return a list of phases to be added to the phase plan
52
53
*/
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)
54
67
}
55
68
56
69
/** 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 {
125
125
}
126
126
127
127
// 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)) }
129
129
val updatedPlan = Plugins .schedule(plan, pluginPhases)
130
130
131
131
// add research plugins
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ class DivideZero extends StandardPlugin:
67
67
val name : String = " divideZero"
68
68
override val description : String = " divide zero check"
69
69
70
- def init (options : List [String ]): List [PluginPhase ] =
70
+ override def initialize (options : List [String ])( using Context ): List [PluginPhase ] =
71
71
(new DivideZeroPhase ) :: Nil
72
72
73
73
class DivideZeroPhase extends PluginPhase :
@@ -90,7 +90,7 @@ end DivideZeroPhase
90
90
```
91
91
92
92
The 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
94
94
and returns a list of ` PluginPhase ` s to be inserted into the compilation pipeline.
95
95
96
96
Our 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:
67
67
val name : String = " divideZero"
68
68
override val description : String = " divide zero check"
69
69
70
- def init (options : List [String ]): List [PluginPhase ] =
70
+ override def initialize (options : List [String ])( using Context ): List [PluginPhase ] =
71
71
(new DivideZeroPhase ) :: Nil
72
72
73
73
class DivideZeroPhase extends PluginPhase :
@@ -90,7 +90,7 @@ end DivideZeroPhase
90
90
```
91
91
92
92
The 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
94
94
and returns a list of ` PluginPhase ` s to be inserted into the compilation pipeline.
95
95
96
96
Our 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 {
21
21
val name : String = " initPlugin"
22
22
override val description : String = " checks that under -Yretain-trees we may get tree for all symbols"
23
23
24
- def init (options : List [String ]): List [PluginPhase ] =
24
+ override def initialize (options : List [String ])( using Context ): List [PluginPhase ] =
25
25
(new SetDefTree ) :: (new InitChecker ) :: Nil
26
26
}
27
27
Original file line number Diff line number Diff line change @@ -22,7 +22,8 @@ class DivideZero extends PluginPhase with StandardPlugin {
22
22
override val runsAfter = Set (Pickler .name)
23
23
override val runsBefore = Set (Staging .name)
24
24
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
26
27
27
28
private def isNumericDivide (sym : Symbol )(implicit ctx : Context ): Boolean = {
28
29
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 {
52
52
override val runsAfter = Set (SetDefTree .name)
53
53
override val runsBefore = Set (FirstTransform .name)
54
54
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
56
56
57
57
private def checkDef (tree : Tree )(implicit ctx : Context ): Tree = {
58
58
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 {
20
20
override val runsAfter = Set (Pickler .name)
21
21
override val runsBefore = Set (PickleQuotes .name)
22
22
23
- override def init (options : List [String ]): List [PluginPhase ] = this :: Nil
23
+ override def initialize (options : List [String ])( using Context ): List [PluginPhase ] = this :: Nil
24
24
25
25
private def isNumericDivide (sym : Symbol )(implicit ctx : Context ): Boolean = {
26
26
def test (tpe : String ): Boolean =
You can’t perform that action at this time.
0 commit comments