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"

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ import ast.TreeTypeMap
3333
class BetaReduce extends MiniPhase:
3434
import ast.tpd._
3535

36-
def phaseName: String = "betaReduce"
36+
override def phaseName: String = BetaReduce.name
37+
38+
override def description: String = BetaReduce.description
3739

3840
override def transformApply(app: Apply)(using Context): Tree = app.fun match
3941
case Select(fn, nme.apply) if defn.isFunctionType(fn.tpe) =>
@@ -47,6 +49,9 @@ class BetaReduce extends MiniPhase:
4749
object BetaReduce:
4850
import ast.tpd._
4951

52+
val name: String = "betaReduce"
53+
val description: String = "reduce closure applications"
54+
5055
/** Beta-reduces a call to `fn` with arguments `argSyms` or returns `tree` */
5156
def apply(original: Tree, fn: Tree, args: List[Tree])(using Context): Tree =
5257
fn match

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer:
2222
thisPhase =>
2323
import ast.tpd._
2424

25-
/** the following two members override abstract members in Transform */
26-
val phaseName: String = "capturedVars"
25+
override def phaseName: String = CapturedVars.name
26+
27+
override def description: String = CapturedVars.description
2728

2829
override def runsAfterGroupsOf: Set[String] = Set(LiftTry.name)
2930
// lifting tries changes what variables are considered to be captured
@@ -167,3 +168,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer:
167168
case _ =>
168169
tree
169170
recur(tree.lhs)
171+
172+
object CapturedVars:
173+
val name: String = "capturedVars"
174+
val description: String = "represent vars captured by closures as heap objects"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import annotation.threadUnsafe
1212

1313
object CheckLoopingImplicits:
1414
val name: String = "checkLoopingImplicits"
15+
val description: String = "check that implicit defs do not call themselves in an infinite loop"
1516

1617
/** Checks that implicit defs do not call themselves in an infinite loop */
1718
class CheckLoopingImplicits extends MiniPhase:
@@ -20,6 +21,8 @@ class CheckLoopingImplicits extends MiniPhase:
2021

2122
override def phaseName: String = CheckLoopingImplicits.name
2223

24+
override def description: String = CheckLoopingImplicits.description
25+
2326
override def transformValDef(mdef: ValDef)(using Context): Tree =
2427
transform(mdef)
2528

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import annotation.threadUnsafe
1212

1313
object CheckNoSuperThis:
1414
val name: String = "checkNoSuperThis"
15+
val description: String = "check that supercalls don't contain references to This"
1516

1617
/** Checks that super and this calls do not pass `this` as (part of) an argument. */
1718
class CheckNoSuperThis extends MiniPhase:
@@ -20,6 +21,8 @@ class CheckNoSuperThis extends MiniPhase:
2021

2122
override def phaseName: String = CheckNoSuperThis.name
2223

24+
override def description: String = CheckNoSuperThis.description
25+
2326
override def runsAfterGroupsOf: Set[String] = Set(Constructors.name)
2427

2528
override def transformDefDef(mdef: DefDef)(using Context): DefDef =
@@ -47,4 +50,4 @@ class CheckNoSuperThis extends MiniPhase:
4750
case _ =>
4851
mdef
4952

50-
end CheckNoSuperThis
53+
end CheckNoSuperThis

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ import Decorators._
2929
class CheckReentrant extends MiniPhase {
3030
import ast.tpd._
3131

32-
override def phaseName: String = "checkReentrant"
32+
override def phaseName: String = CheckReentrant.name
33+
34+
override def description: String = CheckReentrant.description
3335

3436
private var shared: Set[Symbol] = Set()
3537
private var seen: Set[ClassSymbol] = Set()
@@ -84,3 +86,7 @@ class CheckReentrant extends MiniPhase {
8486
tree
8587
}
8688
}
89+
90+
object CheckReentrant:
91+
val name: String = "checkReentrant"
92+
val description: String = "check no data races involving global vars"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class CheckStatic extends MiniPhase {
2929

3030
override def phaseName: String = CheckStatic.name
3131

32+
override def description: String = CheckStatic.description
33+
3234
override def transformTemplate(tree: tpd.Template)(using Context): tpd.Tree = {
3335
val defns = tree.body.collect{case t: ValOrDefDef => t}
3436
var hadNonStaticField = false
@@ -63,4 +65,5 @@ class CheckStatic extends MiniPhase {
6365

6466
object CheckStatic {
6567
val name: String = "checkStatic"
68+
val description: String = "check restrictions that apply to @static members"
6669
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ import dotty.tools.backend.jvm.GenBCode
2929
* -Xmain-class
3030
*/
3131
class CollectEntryPoints extends MiniPhase:
32-
def phaseName: String = "Collect entry points"
32+
33+
override def phaseName: String = CollectEntryPoints.name
34+
35+
override def description: String = CollectEntryPoints.description
3336

3437
override def isRunnable(using Context): Boolean =
3538
def forceRun = ctx.settings.XmainClass.isDefault && ctx.settings.outputDir.value.isInstanceOf[JarArchive]
@@ -52,3 +55,7 @@ class CollectEntryPoints extends MiniPhase:
5255
case _ =>
5356
}
5457
}
58+
59+
object CollectEntryPoints:
60+
val name: String = "Collect entry points"
61+
val description: String = "collect all entry points and save them in the context"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import java.util.IdentityHashMap
1313

1414
object CollectNullableFields {
1515
val name: String = "collectNullableFields"
16+
val description: String = "collect fields that can be nulled out after use in lazy initialization"
1617
}
1718

1819
/** Collect fields that can be nulled out after use in lazy initialization.
@@ -43,6 +44,8 @@ class CollectNullableFields extends MiniPhase {
4344

4445
override def phaseName: String = CollectNullableFields.name
4546

47+
override def description: String = CollectNullableFields.description
48+
4649
/** Running after `ElimByName` to see by names as nullable types. */
4750
override def runsAfter: Set[String] = Set(ElimByName.name)
4851

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import annotation.threadUnsafe
2020

2121
object CompleteJavaEnums {
2222
val name: String = "completeJavaEnums"
23+
val description: String = "fill in constructors for Java enums"
2324

2425
private val nameParamName: TermName = "_$name".toTermName
2526
private val ordinalParamName: TermName = "_$ordinal".toTermName
@@ -35,6 +36,8 @@ class CompleteJavaEnums extends MiniPhase with InfoTransformer { thisPhase =>
3536

3637
override def phaseName: String = CompleteJavaEnums.name
3738

39+
override def description: String = CompleteJavaEnums.description
40+
3841
override def relaxedTypingInGroup: Boolean = true
3942
// Because it adds additional parameters to some constructors
4043

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import collection.mutable
2121

2222
object Constructors {
2323
val name: String = "constructors"
24+
val description: String = "collect initialization code in primary constructors"
2425
}
2526

2627
/** This transform
@@ -33,6 +34,9 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
3334
import tpd._
3435

3536
override def phaseName: String = Constructors.name
37+
38+
override def description: String = Constructors.description
39+
3640
override def runsAfter: Set[String] = Set(HoistSuperArgs.name)
3741
override def runsAfterGroupsOf: Set[String] = Set(Memoize.name)
3842
// Memoized needs to be finished because we depend on the ownerchain after Memoize

0 commit comments

Comments
 (0)