Skip to content

Commit f3c0eaa

Browse files
committed
Merge pull request #308 from smarter/change/Ylog-2
-Ylog:X now only log phase X, use -Ylog:X+ to also log phase X+1
2 parents 83c3f7a + 7bef54d commit f3c0eaa

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ object CompilerCommand extends DotClass {
1919
|Where multiple values are accepted, they should be comma-separated.
2020
| example: -Xplugin:plugin1,plugin2
2121
|<phases> means one or a comma-separated list of:
22-
| (partial) phase names, phase ids, phase id ranges, or the string "all".
22+
| - (partial) phase names with an optional "+" suffix to include the next phase
23+
| - the string "all"
2324
| example: -Xprint:all prints all phases.
24-
| example: -Xprint:expl,24-26 prints phases explicitouter, closelim, dce, jvm.
25-
| example: -Xprint:-4 prints only the phases up to typer.
26-
|
25+
| example: -Xprint:front,mixin prints the frontend and mixin phases.
26+
| example: -Ylog:erasure+ logs the erasure phase and the phase after the erasure phase.
27+
| This is useful because during the tree transform of phase X, we often
28+
| already are in phase X+1.
2729
""".stripMargin.trim + "\n"
2830

2931
def shortUsage = s"Usage: $cmdName <options> <source files>"

src/dotty/tools/dotc/core/Decorators.scala

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,22 @@ object Decorators {
128128
def show(implicit ctx: Context) = text.mkString(ctx.settings.pageWidth.value)
129129
}
130130

131-
/** Implements a test whether a list of strings representing phases contains
132-
* a given phase. The test returns true if the given phase starts with
133-
* one of the names in the list of strings, or if the list of strings
134-
* contains "all".
131+
/** Test whether a list of strings representing phases contains
132+
* a given phase. See [[config.CompilerCommand#explainAdvanced]] for the
133+
* exact meaning of "contains" here.
135134
*/
136135
implicit class PhaseListDecorator(val names: List[String]) extends AnyVal {
137-
def containsPhase(phase: Phase): Boolean = phase match {
136+
def containsPhase(phase: Phase): Boolean = phase match {
138137
case phase: TreeTransformer => phase.transformations.exists(trans => containsPhase(trans.phase))
139-
case _ => names exists (n => n == "all" || phase.phaseName.startsWith(n))
138+
case _ =>
139+
names exists { name =>
140+
name == "all" || {
141+
val strippedName = name.stripSuffix("+")
142+
val logNextPhase = name ne strippedName
143+
phase.phaseName.startsWith(strippedName) ||
144+
(logNextPhase && phase.prev.phaseName.startsWith(strippedName))
145+
}
146+
}
140147
}
141148
}
142149

src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,12 @@ trait Reporting { this: Context =>
101101
def incompleteInputError(msg: String, pos: SourcePosition = NoSourcePosition)(implicit ctx: Context): Unit =
102102
reporter.incomplete(new Error(msg, pos))(ctx)
103103

104-
/** Log msg if current phase or its precedessor is mentioned in
105-
* settings.log.
106-
* The reason we also pick the predecessor is that during the
107-
* tree transform of phase X, we often are already in phase X+1.
108-
* It's convenient to have logging work independently of whether
109-
* we have advanced the phase or not.
104+
/** Log msg if settings.log contains the current phase.
105+
* See [[config.CompilerCommand#explainAdvanced]] for the exact meaning of
106+
* "contains" here.
110107
*/
111108
def log(msg: => String): Unit =
112-
if (this.settings.log.value.containsPhase(phase) ||
113-
this.settings.log.value.containsPhase(phase.prev))
109+
if (this.settings.log.value.containsPhase(phase))
114110
echo(s"[log ${ctx.phasesStack.reverse.mkString(" -> ")}] $msg")
115111

116112
def debuglog(msg: => String): Unit =

0 commit comments

Comments
 (0)