Skip to content

Commit 1776d81

Browse files
authored
Merge pull request #14388 from ckipp01/showPhases
refactor: improve output of -Xshow-phases
2 parents 457c69f + 575e169 commit 1776d81

File tree

93 files changed

+488
-64
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+488
-64
lines changed

compiler/src/dotty/tools/backend/jvm/CollectSuperCalls.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import dotty.tools.dotc.transform.MegaPhase.MiniPhase
2020
class CollectSuperCalls extends MiniPhase {
2121
import tpd._
2222

23-
def phaseName: String = "collectSuperCalls"
23+
override def phaseName: String = CollectSuperCalls.name
24+
25+
override def description: String = CollectSuperCalls.description
2426

2527
override def transformSelect(tree: Select)(using Context): Tree = {
2628
tree.qualifier match {
@@ -40,3 +42,7 @@ class CollectSuperCalls extends MiniPhase {
4042
}
4143
}
4244
}
45+
46+
object CollectSuperCalls:
47+
val name: String = "collectSuperCalls"
48+
val description: String = "find classes that are called with super"

compiler/src/dotty/tools/backend/jvm/GenBCode.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ import StdNames._
3434
import dotty.tools.io._
3535

3636
class GenBCode extends Phase {
37-
def phaseName: String = GenBCode.name
37+
38+
override def phaseName: String = GenBCode.name
39+
40+
override def description: String = GenBCode.description
3841

3942
private val superCallsMap = new MutableSymbolMap[Set[ClassSymbol]]
4043
def registerSuperCall(sym: Symbol, calls: ClassSymbol): Unit = {
@@ -106,6 +109,7 @@ class GenBCode extends Phase {
106109

107110
object GenBCode {
108111
val name: String = "genBCode"
112+
val description: String = "generate JVM bytecode"
109113
}
110114

111115
class GenBCodePipeline(val int: DottyBackendInterface, val primitives: DottyPrimitives)(using Context) extends BCodeSyncAndTry {

compiler/src/dotty/tools/backend/sjs/GenSJSIR.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@ import Phases._
66

77
/** Generates Scala.js IR files for the compilation unit. */
88
class GenSJSIR extends Phase {
9-
def phaseName: String = "genSJSIR"
9+
10+
override def phaseName: String = GenSJSIR.name
11+
12+
override def description: String = GenSJSIR.description
1013

1114
override def isRunnable(using Context): Boolean =
1215
super.isRunnable && ctx.settings.scalajs.value
1316

1417
def run(using Context): Unit =
1518
new JSCodeGen().run()
1619
}
20+
21+
object GenSJSIR:
22+
val name: String = "genSJSIR"
23+
val description: String = "generate .sjsir files for Scala.js"

compiler/src/dotty/tools/dotc/config/CliCommand.scala

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,32 @@ trait CliCommand:
138138
protected def yusageMessage(using settings: ConcreteSettings)(using SettingsState) =
139139
createUsageMsg("Possible private", shouldExplain = true, isPrivate)
140140

141-
protected def phasesMessage: String =
142-
(new Compiler()).phases.map {
143-
case List(single) => single.phaseName
144-
case more => more.map(_.phaseName).mkString("{", ", ", "}")
145-
}.mkString("\n")
141+
/** Used for the formatted output of -Xshow-phases */
142+
protected def phasesMessage(using ctx: Context): String =
143+
144+
val phases = new Compiler().phases
145+
val nameLimit = 25
146+
val maxCol = ctx.settings.pageWidth.value
147+
val maxName = phases.flatten.map(_.phaseName.length).max
148+
val width = maxName.min(nameLimit)
149+
val maxDesc = maxCol - (width + 6)
150+
val fmt = s"%${width}.${width}s %.${maxDesc}s%n"
151+
152+
val sb = new StringBuilder
153+
sb ++= fmt.format("phase name", "description")
154+
sb ++= fmt.format("----------", "-----------")
155+
156+
phases.foreach {
157+
case List(single) =>
158+
sb ++= fmt.format(single.phaseName, single.description)
159+
case Nil => ()
160+
case more =>
161+
sb ++= fmt.format(s"{", "")
162+
more.foreach { mini => sb ++= fmt.format(mini.phaseName, mini.description) }
163+
sb ++= fmt.format(s"}", "")
164+
}
165+
sb.mkString
166+
146167

147168
/** Provide usage feedback on argument summary, assuming that all settings
148169
* are already applied in context.

compiler/src/dotty/tools/dotc/parsing/ParserPhase.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import dotty.tools.unsupported
1515
class Parser extends Phase {
1616

1717
override def phaseName: String = Parser.name
18+
override def description: String = Parser.description
1819

1920
// We run TreeChecker only after type checking
2021
override def isCheckable: Boolean = false
@@ -58,4 +59,5 @@ class Parser extends Phase {
5859

5960
object Parser{
6061
val name: String = "parser"
62+
val description: String = "scan and parse sources"
6163
}

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ import scala.util.chaining.*
4343
* @see ExtractDependencies
4444
*/
4545
class ExtractAPI extends Phase {
46-
override def phaseName: String = "sbt-api"
46+
47+
override def phaseName: String = ExtractAPI.name
48+
49+
override def description: String = ExtractAPI.description
4750

4851
override def isRunnable(using Context): Boolean = {
4952
def forceRun = ctx.settings.YdumpSbtInc.value || ctx.settings.YforceSbtPhases.value
@@ -87,6 +90,10 @@ class ExtractAPI extends Phase {
8790
}
8891
}
8992

93+
object ExtractAPI:
94+
val name: String = "sbt-api"
95+
val description: String = "sends a representation of the API of classes to sbt"
96+
9097
/** Extracts full (including private members) API representation out of Symbols and Types.
9198
*
9299
* The exact representation used for each type is not important: the only thing

compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ import scala.collection.{Set, mutable}
4949
class ExtractDependencies extends Phase {
5050
import ExtractDependencies._
5151

52-
override def phaseName: String = "sbt-deps"
52+
override def phaseName: String = ExtractDependencies.name
53+
54+
override def description: String = ExtractDependencies.description
5355

5456
override def isRunnable(using Context): Boolean = {
5557
def forceRun = ctx.settings.YdumpSbtInc.value || ctx.settings.YforceSbtPhases.value
@@ -180,6 +182,9 @@ class ExtractDependencies extends Phase {
180182
}
181183

182184
object ExtractDependencies {
185+
val name: String = "sbt-deps"
186+
val description: String = "sends information on classes' dependencies to sbt"
187+
183188
def classNameAsString(sym: Symbol)(using Context): String =
184189
sym.fullName.stripModuleClassSuffix.toString
185190

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class ExtractSemanticDB extends Phase:
3636

3737
override val phaseName: String = ExtractSemanticDB.name
3838

39+
override val description: String = ExtractSemanticDB.description
40+
3941
override def isRunnable(using Context) =
4042
super.isRunnable && ctx.settings.Xsemanticdb.value
4143

@@ -461,6 +463,7 @@ object ExtractSemanticDB:
461463
import java.nio.file.Paths
462464

463465
val name: String = "extractSemanticDB"
466+
val description: String = "extract info into .semanticdb files"
464467

465468
def write(
466469
source: SourceFile,

compiler/src/dotty/tools/dotc/transform/ArrayApply.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import scala.reflect.ClassTag
2121
class ArrayApply extends MiniPhase {
2222
import tpd._
2323

24-
override def phaseName: String = "arrayApply"
24+
override def phaseName: String = ArrayApply.name
25+
26+
override def description: String = ArrayApply.description
2527

2628
override def transformApply(tree: tpd.Apply)(using Context): tpd.Tree =
2729
if isArrayModuleApply(tree.symbol) then
@@ -71,3 +73,7 @@ class ArrayApply extends MiniPhase {
7173
}
7274
}
7375
}
76+
77+
object ArrayApply:
78+
val name: String = "arrayApply"
79+
val description: String = "optimize `scala.Array.apply`"

compiler/src/dotty/tools/dotc/transform/ArrayConstructors.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import scala.collection.immutable.::
2222
class ArrayConstructors extends MiniPhase {
2323
import ast.tpd._
2424

25-
override def phaseName: String = "arrayConstructors"
25+
override def phaseName: String = ArrayConstructors.name
26+
27+
override def description: String = ArrayConstructors.description
2628

2729
override def transformApply(tree: tpd.Apply)(using Context): tpd.Tree = {
2830
def expand(elemType: Type, dims: List[Tree]) =
@@ -49,3 +51,7 @@ class ArrayConstructors extends MiniPhase {
4951
else tree
5052
}
5153
}
54+
55+
object ArrayConstructors:
56+
val name: String = "arrayConstructors"
57+
val description: String = "intercept creation of (non-generic) arrays and intrinsify"

0 commit comments

Comments
 (0)