summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2013-07-25 12:58:56 -0700
committerSom Snytt <som.snytt@gmail.com>2013-08-21 18:02:35 -0700
commit1683c95e159006d40a8458d29ef266ca741752c7 (patch)
tree69d40c95510159340ed3e660f0809f1bfef97ed7 /src
parentf3731f9ace5d3d5e213ea786fe0027ea66c5358b (diff)
downloadscala-1683c95e159006d40a8458d29ef266ca741752c7.tar.gz
scala-1683c95e159006d40a8458d29ef266ca741752c7.tar.bz2
scala-1683c95e159006d40a8458d29ef266ca741752c7.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala2
-rw-r--r--src/compiler/scala/tools/nsc/backend/opt/ConstantOptimization.scala2
-rw-r--r--src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala2
-rw-r--r--src/compiler/scala/tools/nsc/backend/opt/InlineExceptionHandlers.scala2
-rw-r--r--src/compiler/scala/tools/nsc/backend/opt/Inliners.scala2
-rw-r--r--src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala2
-rw-r--r--src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala43
-rw-r--r--src/partest-extras/scala/tools/partest/IcodeComparison.scala73
8 files changed, 107 insertions, 21 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala b/src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala
index bde17b28fc..c49f23852f 100644
--- a/src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala
+++ b/src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala
@@ -18,6 +18,8 @@ abstract class ClosureElimination extends SubComponent {
val phaseName = "closelim"
+ override val enabled: Boolean = settings.Xcloselim
+
/** Create a new phase */
override def newPhase(p: Phase) = new ClosureEliminationPhase(p)
diff --git a/src/compiler/scala/tools/nsc/backend/opt/ConstantOptimization.scala b/src/compiler/scala/tools/nsc/backend/opt/ConstantOptimization.scala
index 43c8527f41..64a0727440 100644
--- a/src/compiler/scala/tools/nsc/backend/opt/ConstantOptimization.scala
+++ b/src/compiler/scala/tools/nsc/backend/opt/ConstantOptimization.scala
@@ -34,6 +34,8 @@ abstract class ConstantOptimization extends SubComponent {
/** Create a new phase */
override def newPhase(p: Phase) = new ConstantOptimizationPhase(p)
+ override val enabled: Boolean = settings.YconstOptimization
+
/**
* The constant optimization phase.
*/
diff --git a/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala b/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala
index 483bff6467..e373964987 100644
--- a/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala
+++ b/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala
@@ -22,6 +22,8 @@ abstract class DeadCodeElimination extends SubComponent {
val phaseName = "dce"
+ override val enabled: Boolean = settings.Xdce
+
/** Create a new phase */
override def newPhase(p: Phase) = new DeadCodeEliminationPhase(p)
diff --git a/src/compiler/scala/tools/nsc/backend/opt/InlineExceptionHandlers.scala b/src/compiler/scala/tools/nsc/backend/opt/InlineExceptionHandlers.scala
index cecabda171..f4e97a91d8 100644
--- a/src/compiler/scala/tools/nsc/backend/opt/InlineExceptionHandlers.scala
+++ b/src/compiler/scala/tools/nsc/backend/opt/InlineExceptionHandlers.scala
@@ -57,6 +57,8 @@ abstract class InlineExceptionHandlers extends SubComponent {
/** Create a new phase */
override def newPhase(p: Phase) = new InlineExceptionHandlersPhase(p)
+ override def enabled = settings.inlineHandlers
+
/**
* Inlining Exception Handlers
*/
diff --git a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala
index 09095879bf..181f4bde4e 100644
--- a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala
+++ b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala
@@ -49,6 +49,8 @@ abstract class Inliners extends SubComponent {
val phaseName = "inliner"
+ override val enabled: Boolean = settings.inline
+
/** Debug - for timing the inliner. */
/****
private def timed[T](s: String, body: => T): T = {
diff --git a/src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala b/src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala
index 29480576ea..98d0695865 100644
--- a/src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala
+++ b/src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala
@@ -8,7 +8,7 @@ trait CPSUtils {
val global: Global
import global._
- var cpsEnabled = false
+ val cpsEnabled: Boolean
val verbose: Boolean = System.getProperty("cpsVerbose", "false") == "true"
def vprintln(x: =>Any): Unit = if (verbose) println(x)
diff --git a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala
index d3b02d74f4..a7e82e949b 100644
--- a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala
+++ b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala
@@ -11,41 +11,44 @@ class SelectiveCPSPlugin(val global: Global) extends Plugin {
val name = "continuations"
val description = "applies selective cps conversion"
- val anfPhase = new {val global = SelectiveCPSPlugin.this.global } with SelectiveANFTransform() {
+ val pluginEnabled = options contains "enable"
+
+ val anfPhase = new {
+ val global = SelectiveCPSPlugin.this.global
+ val cpsEnabled = pluginEnabled
+ override val enabled = cpsEnabled
+ } with SelectiveANFTransform {
val runsAfter = List("pickler")
}
- val cpsPhase = new {val global = SelectiveCPSPlugin.this.global } with SelectiveCPSTransform() {
+ val cpsPhase = new {
+ val global = SelectiveCPSPlugin.this.global
+ val cpsEnabled = pluginEnabled
+ override val enabled = cpsEnabled
+ } with SelectiveCPSTransform {
val runsAfter = List("selectiveanf")
override val runsBefore = List("uncurry")
}
val components = List[PluginComponent](anfPhase, cpsPhase)
- val checker = new { val global: SelectiveCPSPlugin.this.global.type = SelectiveCPSPlugin.this.global } with CPSAnnotationChecker
+ val checker = new {
+ val global: SelectiveCPSPlugin.this.global.type = SelectiveCPSPlugin.this.global
+ val cpsEnabled = pluginEnabled
+ } with CPSAnnotationChecker
+
+ // TODO don't muck up global with unused checkers
global.addAnnotationChecker(checker.checker)
global.analyzer.addAnalyzerPlugin(checker.plugin)
global.log("instantiated cps plugin: " + this)
- def setEnabled(flag: Boolean) = {
- checker.cpsEnabled = flag
- anfPhase.cpsEnabled = flag
- cpsPhase.cpsEnabled = flag
- }
-
- // TODO: require -enabled command-line flag
-
- override def processOptions(options: List[String], error: String => Unit) = {
- var enabled = false
- for (option <- options) {
- if (option == "enable") {
- enabled = true
- } else {
- error("Option not understood: "+option)
- }
+ override def init(options: List[String], error: String => Unit) = {
+ options foreach {
+ case "enable" => // in initializer
+ case arg => error(s"Bad argument: $arg")
}
- setEnabled(enabled)
+ pluginEnabled
}
override val optionsHelp: Option[String] =
diff --git a/src/partest-extras/scala/tools/partest/IcodeComparison.scala b/src/partest-extras/scala/tools/partest/IcodeComparison.scala
new file mode 100644
index 0000000000..24b87e898f
--- /dev/null
+++ b/src/partest-extras/scala/tools/partest/IcodeComparison.scala
@@ -0,0 +1,73 @@
+/* NSC -- new Scala compiler
+ * Copyright 2005-2013 LAMP/EPFL
+ * @author Paul Phillips
+ */
+
+package scala.tools.partest
+
+import scala.tools.partest.nest.FileManager.compareContents
+import scala.compat.Platform.EOL
+
+/** A class for testing icode. All you need is this in a
+ * partest source file --
+ * {{{
+ * object Test extends IcodeComparison
+ * }}}
+ * -- and the generated output will be the icode for everything
+ * in that file. See scaladoc for possible customizations.
+ */
+abstract class IcodeComparison extends DirectTest {
+ /** The phase after which icode is printed.
+ * Override to check icode at a different point,
+ * but you can't print at a phase that is not enabled
+ * in this compiler run. Defaults to "icode".
+ */
+ def printIcodeAfterPhase = "icode"
+
+ /** When comparing the output of two phases, this is
+ * the other phase of interest, normally the preceding
+ * phase. Defaults to "icode" for tests of optimizer phases.
+ */
+ def printSuboptimalIcodeAfterPhase = "icode"
+
+ /** The source code to compile defaults to the test file.
+ * I.e., the test file compiles itself. For a comparison,
+ * the test file will be compiled three times.
+ */
+ def code = testPath.slurp()
+
+ /** By default, the test code is compiled with -usejavacp. */
+ override def extraSettings: String = "-usejavacp"
+
+ /** Compile the test code and return the contents of all
+ * (sorted) .icode files, which are immediately deleted.
+ * @param arg0 at least one arg is required
+ * @param args must include -Xprint-icode:phase
+ */
+ def collectIcode(arg0: String, args: String*): List[String] = {
+ compile("-d" :: testOutput.path :: arg0 :: args.toList : _*)
+ val icodeFiles = testOutput.files.toList filter (_ hasExtension "icode")
+
+ try icodeFiles sortBy (_.name) flatMap (f => f.lines.toList)
+ finally icodeFiles foreach (f => f.delete())
+ }
+
+ /** Collect icode at the default phase, `printIcodeAfterPhase`. */
+ def collectIcode(): List[String] = collectIcode(s"-Xprint-icode:$printIcodeAfterPhase")
+
+ /** Default show is showComparison. May be overridden for showIcode or similar. */
+ def show() = showComparison()
+
+ /** Compile the test code with and without optimization, and
+ * then print the diff of the icode.
+ */
+ def showComparison() = {
+ val lines1 = collectIcode(s"-Xprint-icode:$printSuboptimalIcodeAfterPhase")
+ val lines2 = collectIcode("-optimise", s"-Xprint-icode:$printIcodeAfterPhase")
+
+ println(compareContents(lines1, lines2))
+ }
+
+ /** Print icode at the default phase, `printIcodeAfterPhase`. */
+ def showIcode() = println(collectIcode() mkString EOL)
+}