From e8748e29279f30167516ef7ca8d24f4e4229687f Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 27 Mar 2014 13:51:30 +0100 Subject: Take phase control settings into account Run now interprets correctly -YstopBefore -YstopAfter -Yskip -Tprint phase settings. For now, we stop by default before erasure, until erasure is fully debugged. --- src/dotty/tools/dotc/Compiler.scala | 2 +- src/dotty/tools/dotc/Run.scala | 22 +++++++++++++++++++--- src/dotty/tools/dotc/config/ScalaSettings.scala | 8 ++++---- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/dotty/tools/dotc/Compiler.scala b/src/dotty/tools/dotc/Compiler.scala index ccbcf1696..709f4b2db 100644 --- a/src/dotty/tools/dotc/Compiler.scala +++ b/src/dotty/tools/dotc/Compiler.scala @@ -22,7 +22,7 @@ class Compiler { List(new FrontEnd), List(new LazyValsCreateCompanionObjects), //force separataion between lazyVals and LVCreateCO List(new LazyValTranformContext().transformer, new TypeTestsCasts), - // List(new Erasure), + List(new Erasure), List(new UncurryTreeTransform) ) diff --git a/src/dotty/tools/dotc/Run.scala b/src/dotty/tools/dotc/Run.scala index 89ca45071..972e3aa86 100644 --- a/src/dotty/tools/dotc/Run.scala +++ b/src/dotty/tools/dotc/Run.scala @@ -2,7 +2,7 @@ package dotty.tools package dotc import core._ -import Contexts._, Periods._, Symbols._ +import Contexts._, Periods._, Symbols._, Phases._, Decorators._ import io.PlainFile import util.{SourceFile, NoSource, Stats, SimpleMap} import reporting.Reporter @@ -30,13 +30,29 @@ class Run(comp: Compiler)(implicit ctx: Context) { def compileSources(sources: List[SourceFile]) = Stats.monitorHeartBeat { if (sources forall (_.exists)) { units = sources map (new CompilationUnit(_)) - for (phase <- ctx.allPhases.init) { - if (!ctx.reporter.hasErrors) + def stoppedBefore(phase: Phase) = + ctx.settings.YstopBefore.value.containsPhase(phase) || + ctx.settings.YstopAfter.value.containsPhase(phase.prev) + val phasesToRun = ctx.allPhases.init + .takeWhile(!stoppedBefore(_)) + .filterNot(ctx.settings.Yskip.value.containsPhase(_)) + for (phase <- phasesToRun) { + if (!ctx.reporter.hasErrors) { phase.runOn(units) + if (ctx.settings.Xprint.value.containsPhase(phase)) + for (unit <- units) + printTree(ctx.fresh.withNewPhase(phase).withCompilationUnit(unit)) + } } } } + private def printTree(implicit ctx: Context) = { + val unit = ctx.compilationUnit + println(s"result of $unit after ${ctx.phase}:") + println(unit.tpdTree.show) + } + def compile(sourceCode: String): Unit = { val virtualFile = new VirtualFile(sourceCode) // use source code as name as it's used for equals val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8")) // buffering is still advised by javadoc diff --git a/src/dotty/tools/dotc/config/ScalaSettings.scala b/src/dotty/tools/dotc/config/ScalaSettings.scala index aaf3b8385..8ed725e36 100644 --- a/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -125,12 +125,12 @@ class ScalaSettings extends Settings.SettingGroup { val XshowtreesStringified = BooleanSetting("-Yshow-trees-stringified", "(Requires -Xprint:) Print stringifications along with detailed ASTs.") val Yshowsyms = BooleanSetting("-Yshow-syms", "Print the AST symbol hierarchy after each phase.") val Yshowsymkinds = BooleanSetting("-Yshow-symkinds", "Print abbreviated symbol kinds next to symbol names.") - val skip = PhasesSetting("-Yskip", "Skip") + val Yskip = PhasesSetting("-Yskip", "Skip") val Ygenjavap = StringSetting("-Ygen-javap", "dir", "Generate a parallel output directory of .javap files.", "") val Ydumpclasses = StringSetting("-Ydump-classes", "dir", "Dump the generated bytecode to .class files (useful for reflective compilation that utilizes in-memory classloaders).", "") val Ynosqueeze = BooleanSetting("-Yno-squeeze", "Disable creation of compact code in matching.") - val stopAfter = PhasesSetting("-Ystop-after", "Stop after") withAbbreviation ("-stop") // backward compat - val stopBefore = PhasesSetting("-Ystop-before", "Stop before") + val YstopAfter = PhasesSetting("-Ystop-after", "Stop after") withAbbreviation ("-stop") // backward compat + val YstopBefore = PhasesSetting("-Ystop-before", "Stop before", "erasure") // stop before erasure as long as we have not debugged it fully val refinementMethodDispatch = ChoiceSetting("-Ystruct-dispatch", "policy", "structural method dispatch policy", List("no-cache", "mono-cache", "poly-cache", "invoke-dynamic"), "poly-cache") val Yrangepos = BooleanSetting("-Yrangepos", "Use range positions for syntax trees.") val Ybuilderdebug = ChoiceSetting("-Ybuilder-debug", "manager", "Compile using the specified build manager.", List("none", "refined", "simple"), "none") @@ -144,7 +144,7 @@ class ScalaSettings extends Settings.SettingGroup { val YshowSuppressedErrors = BooleanSetting("-Yshow-suppressed-errors", "Also show follow-on errors and warnings that are normally supressed.") val Yheartbeat = BooleanSetting("-Yheartbeat", "show heartbeat stack trace of compiler operations.") val Yprintpos = BooleanSetting("-Yprintpos", "show tree positions") - def stop = stopAfter + def stop = YstopAfter /** Area-specific debug output. */ -- cgit v1.2.3