Skip to content
This repository was archived by the owner on Jun 23, 2020. It is now read-only.

Commit 41dd9e5

Browse files
som-snyttadriaanm
authored andcommitted
SI-7622 Clean Up Phase Assembly
Let optimiser components and continuations plugin opt-out when required flags are not set. Wasted time on a whitespace error in check file, so let --debug dump the processed check file and its diff.
1 parent 87ac204 commit 41dd9e5

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ trait CPSUtils {
88
val global: Global
99
import global._
1010

11-
var cpsEnabled = false
11+
val cpsEnabled: Boolean
1212
val verbose: Boolean = System.getProperty("cpsVerbose", "false") == "true"
1313
def vprintln(x: =>Any): Unit = if (verbose) println(x)
1414

src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,44 @@ class SelectiveCPSPlugin(val global: Global) extends Plugin {
1111
val name = "continuations"
1212
val description = "applies selective cps conversion"
1313

14-
val anfPhase = new {val global = SelectiveCPSPlugin.this.global } with SelectiveANFTransform() {
14+
val pluginEnabled = options contains "enable"
15+
16+
val anfPhase = new {
17+
val global = SelectiveCPSPlugin.this.global
18+
val cpsEnabled = pluginEnabled
19+
override val enabled = cpsEnabled
20+
} with SelectiveANFTransform {
1521
val runsAfter = List("pickler")
1622
}
1723

18-
val cpsPhase = new {val global = SelectiveCPSPlugin.this.global } with SelectiveCPSTransform() {
24+
val cpsPhase = new {
25+
val global = SelectiveCPSPlugin.this.global
26+
val cpsEnabled = pluginEnabled
27+
override val enabled = cpsEnabled
28+
} with SelectiveCPSTransform {
1929
val runsAfter = List("selectiveanf")
2030
override val runsBefore = List("uncurry")
2131
}
2232

2333
val components = List[PluginComponent](anfPhase, cpsPhase)
2434

25-
val checker = new { val global: SelectiveCPSPlugin.this.global.type = SelectiveCPSPlugin.this.global } with CPSAnnotationChecker
35+
val checker = new {
36+
val global: SelectiveCPSPlugin.this.global.type = SelectiveCPSPlugin.this.global
37+
val cpsEnabled = pluginEnabled
38+
} with CPSAnnotationChecker
39+
40+
// TODO don't muck up global with unused checkers
2641
global.addAnnotationChecker(checker.checker)
2742
global.analyzer.addAnalyzerPlugin(checker.plugin)
2843

2944
global.log("instantiated cps plugin: " + this)
3045

31-
def setEnabled(flag: Boolean) = {
32-
checker.cpsEnabled = flag
33-
anfPhase.cpsEnabled = flag
34-
cpsPhase.cpsEnabled = flag
35-
}
36-
37-
// TODO: require -enabled command-line flag
38-
39-
override def processOptions(options: List[String], error: String => Unit) = {
40-
var enabled = false
41-
for (option <- options) {
42-
if (option == "enable") {
43-
enabled = true
44-
} else {
45-
error("Option not understood: "+option)
46-
}
46+
override def init(options: List[String], error: String => Unit) = {
47+
options foreach {
48+
case "enable" => // in initializer
49+
case arg => error(s"Bad argument: $arg")
4750
}
48-
setEnabled(enabled)
51+
pluginEnabled
4952
}
5053

5154
override val optionsHelp: Option[String] =

0 commit comments

Comments
 (0)