Skip to content

Commit e8748e2

Browse files
oderskyDarkDimius
authored andcommitted
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.
1 parent 35de6f1 commit e8748e2

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Compiler {
2222
List(new FrontEnd),
2323
List(new LazyValsCreateCompanionObjects), //force separataion between lazyVals and LVCreateCO
2424
List(new LazyValTranformContext().transformer, new TypeTestsCasts),
25-
// List(new Erasure),
25+
List(new Erasure),
2626
List(new UncurryTreeTransform)
2727
)
2828

src/dotty/tools/dotc/Run.scala

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotty.tools
22
package dotc
33

44
import core._
5-
import Contexts._, Periods._, Symbols._
5+
import Contexts._, Periods._, Symbols._, Phases._, Decorators._
66
import io.PlainFile
77
import util.{SourceFile, NoSource, Stats, SimpleMap}
88
import reporting.Reporter
@@ -30,13 +30,29 @@ class Run(comp: Compiler)(implicit ctx: Context) {
3030
def compileSources(sources: List[SourceFile]) = Stats.monitorHeartBeat {
3131
if (sources forall (_.exists)) {
3232
units = sources map (new CompilationUnit(_))
33-
for (phase <- ctx.allPhases.init) {
34-
if (!ctx.reporter.hasErrors)
33+
def stoppedBefore(phase: Phase) =
34+
ctx.settings.YstopBefore.value.containsPhase(phase) ||
35+
ctx.settings.YstopAfter.value.containsPhase(phase.prev)
36+
val phasesToRun = ctx.allPhases.init
37+
.takeWhile(!stoppedBefore(_))
38+
.filterNot(ctx.settings.Yskip.value.containsPhase(_))
39+
for (phase <- phasesToRun) {
40+
if (!ctx.reporter.hasErrors) {
3541
phase.runOn(units)
42+
if (ctx.settings.Xprint.value.containsPhase(phase))
43+
for (unit <- units)
44+
printTree(ctx.fresh.withNewPhase(phase).withCompilationUnit(unit))
45+
}
3646
}
3747
}
3848
}
3949

50+
private def printTree(implicit ctx: Context) = {
51+
val unit = ctx.compilationUnit
52+
println(s"result of $unit after ${ctx.phase}:")
53+
println(unit.tpdTree.show)
54+
}
55+
4056
def compile(sourceCode: String): Unit = {
4157
val virtualFile = new VirtualFile(sourceCode) // use source code as name as it's used for equals
4258
val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8")) // buffering is still advised by javadoc

src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ class ScalaSettings extends Settings.SettingGroup {
125125
val XshowtreesStringified = BooleanSetting("-Yshow-trees-stringified", "(Requires -Xprint:) Print stringifications along with detailed ASTs.")
126126
val Yshowsyms = BooleanSetting("-Yshow-syms", "Print the AST symbol hierarchy after each phase.")
127127
val Yshowsymkinds = BooleanSetting("-Yshow-symkinds", "Print abbreviated symbol kinds next to symbol names.")
128-
val skip = PhasesSetting("-Yskip", "Skip")
128+
val Yskip = PhasesSetting("-Yskip", "Skip")
129129
val Ygenjavap = StringSetting("-Ygen-javap", "dir", "Generate a parallel output directory of .javap files.", "")
130130
val Ydumpclasses = StringSetting("-Ydump-classes", "dir", "Dump the generated bytecode to .class files (useful for reflective compilation that utilizes in-memory classloaders).", "")
131131
val Ynosqueeze = BooleanSetting("-Yno-squeeze", "Disable creation of compact code in matching.")
132-
val stopAfter = PhasesSetting("-Ystop-after", "Stop after") withAbbreviation ("-stop") // backward compat
133-
val stopBefore = PhasesSetting("-Ystop-before", "Stop before")
132+
val YstopAfter = PhasesSetting("-Ystop-after", "Stop after") withAbbreviation ("-stop") // backward compat
133+
val YstopBefore = PhasesSetting("-Ystop-before", "Stop before", "erasure") // stop before erasure as long as we have not debugged it fully
134134
val refinementMethodDispatch = ChoiceSetting("-Ystruct-dispatch", "policy", "structural method dispatch policy", List("no-cache", "mono-cache", "poly-cache", "invoke-dynamic"), "poly-cache")
135135
val Yrangepos = BooleanSetting("-Yrangepos", "Use range positions for syntax trees.")
136136
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 {
144144
val YshowSuppressedErrors = BooleanSetting("-Yshow-suppressed-errors", "Also show follow-on errors and warnings that are normally supressed.")
145145
val Yheartbeat = BooleanSetting("-Yheartbeat", "show heartbeat stack trace of compiler operations.")
146146
val Yprintpos = BooleanSetting("-Yprintpos", "show tree positions")
147-
def stop = stopAfter
147+
def stop = YstopAfter
148148

149149
/** Area-specific debug output.
150150
*/

0 commit comments

Comments
 (0)