Skip to content

Commit a73a1d9

Browse files
committed
Document phases
Give a one-line explanation what each phase does in Compiler.
1 parent b2d1e87 commit a73a1d9

File tree

3 files changed

+52
-50
lines changed

3 files changed

+52
-50
lines changed

src/dotty/tools/dotc/Compiler.scala

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -38,54 +38,55 @@ class Compiler {
3838
*/
3939
def phases: List[List[Phase]] =
4040
List(
41-
List(new FrontEnd),
42-
List(new PostTyper),
43-
List(new Pickler),
44-
List(new FirstTransform,
45-
new CheckReentrant),
46-
List(new RefChecks,
47-
new CheckStatic,
48-
new ElimRepeated,
49-
new NormalizeFlags,
50-
new ExtensionMethods,
51-
new ExpandSAMs,
52-
new TailRec,
53-
new LiftTry,
54-
new ClassOf),
55-
List(new PatternMatcher,
56-
new ExplicitOuter,
57-
new ExplicitSelf,
58-
new CrossCastAnd,
59-
new Splitter),
60-
List(new VCInlineMethods,
61-
new SeqLiterals,
62-
new InterceptedMethods,
63-
new Getters,
64-
new ElimByName,
65-
new AugmentScala2Traits,
66-
new ResolveSuper),
67-
List(new Erasure),
68-
List(new ElimErasedValueType,
69-
new VCElideAllocations,
70-
new Mixin,
71-
new LazyVals,
72-
new Memoize,
73-
new LinkScala2ImplClasses,
74-
new NonLocalReturns,
75-
new CapturedVars, // capturedVars has a transformUnit: no phases should introduce local mutable vars here
76-
new Constructors, // constructors changes decls in transformTemplate, no InfoTransformers should be added after it
77-
new FunctionalInterfaces,
78-
new GetClass), // getClass transformation should be applied to specialized methods
79-
List(new LambdaLift, // in this mini-phase block scopes are incorrect. No phases that rely on scopes should be here
80-
new ElimStaticThis,
81-
new Flatten,
82-
// new DropEmptyCompanions,
83-
new RestoreScopes),
84-
List(new ExpandPrivate,
85-
new CollectEntryPoints,
86-
new LabelDefs),
87-
List(new GenSJSIR),
88-
List(new GenBCode)
41+
List(new FrontEnd), // Compiler frontend: scanner, parser, namer, typer
42+
List(new PostTyper), // Additional checks and cleanups after type checking
43+
List(new Pickler), // Generate TASTY info
44+
List(new FirstTransform, // Some transformations to put trees into a canonical form
45+
new CheckReentrant), // Internal use only: Check that compiled program has no data races involving global vars
46+
List(new RefChecks, // Various checks mostly related to abstract members and overriding
47+
new CheckStatic, // Check restrictions that apply to @static members
48+
new ElimRepeated, // Rewrite vararg parameters and arguments
49+
new NormalizeFlags, // Rewrite some definition flags
50+
new ExtensionMethods, // Expand methods of value classes with extension methods
51+
new ExpandSAMs, // Expand single abstract method closures to anonymous classes
52+
new TailRec, // Rewrite tail recursion to loops
53+
new LiftTry, // Put try expressions that might execute on non-empty stacks into their own methods
54+
new ClassOf), // Expand `Predef.classOf` calls.
55+
List(new PatternMatcher, // Compile pattern matches
56+
new ExplicitOuter, // Add accessors to outer classes from nested ones.
57+
new ExplicitSelf, // Make references to non-trivial self types explicit as casts
58+
new CrossCastAnd, // Normalize selections involving intersection types.
59+
new Splitter), // Expand selections involving union types into conditionals
60+
List(new VCInlineMethods, // Inlines calls to value class methods
61+
new SeqLiterals, // Express vararg arguments as arrays
62+
new InterceptedMethods, // Special handling of `==`, `|=`, `getClass` methods
63+
new Getters, // Replace non-private vals and vars with getter defs (fields are added later)
64+
new ElimByName, // Expand by-name parameters and arguments
65+
new AugmentScala2Traits, // Expand traits defined in Scala 2.11 to simulate old-style rewritings
66+
new ResolveSuper), // Implement super accessors and add forwarders to trait methods
67+
List(new Erasure), // Rewrite types to JVM model, erasing all type parameters, abstract types and refinements.
68+
List(new ElimErasedValueType, // Expand erased value types to their underlying implmementation types
69+
new VCElideAllocations, // Peep-hole optimization to eliminate unnecessary value class allocations
70+
new Mixin, // Expand trait fields and trait initializers
71+
new LazyVals, // Expand lazy vals
72+
new Memoize, // Add private fields to getters and setters
73+
new LinkScala2ImplClasses, // Forward calls to the implementation classes of traits defined by Scala 2.11
74+
new NonLocalReturns, // Expand non-local returns
75+
new CapturedVars, // Represent vars captured by closures as heap objects
76+
new Constructors, // Collect initialization code in primary constructors
77+
// Note: constructors changes decls in transformTemplate, no InfoTransformers should be added after it
78+
new FunctionalInterfaces,// Rewrites closures to implement @specialized types of Functions.
79+
new GetClass), // Rewrites getClass calls on primitive types.
80+
List(new LambdaLift, // Lifts out nested functions to class scope, storing free variables in environments
81+
// Note: in this mini-phase block scopes are incorrect. No phases that rely on scopes should be here
82+
new ElimStaticThis, // Replace `this` references to static objects by global identifiers
83+
new Flatten, // Lift all inner classes to package scope
84+
new RestoreScopes), // Repair scopes rendered invalid by moving definitions in prior phases of the group
85+
List(new ExpandPrivate, // Widen private definitions accessed from nested classes
86+
new CollectEntryPoints, // Find classes with main methods
87+
new LabelDefs), // Converts calls to labels to jumps
88+
List(new GenSJSIR), // Generate .js code
89+
List(new GenBCode) // Generate JVM bytecode
8990
)
9091

9192
var runId = 1

src/dotty/tools/dotc/transform/ElimStaticThis.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import dotty.tools.dotc.core.SymDenotations.SymDenotation
1010
import TreeTransforms.{MiniPhaseTransform, TransformerInfo}
1111
import dotty.tools.dotc.core.Types.{ThisType, TermRef}
1212

13-
/** Replace This references to module classes in static methods by global identifiers to the
13+
/** Replace This references to module classes in static methods by global identifiers to the
1414
* corresponding modules.
1515
*/
1616
class ElimStaticThis extends MiniPhaseTransform {

src/dotty/tools/dotc/transform/GetClass.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class GetClass extends MiniPhaseTransform {
2020

2121
override def phaseName: String = "getClass"
2222

23-
override def runsAfter: Set[Class[_ <: Phase]] = Set(classOf[Erasure])
23+
// getClass transformation should be applied to specialized methods
24+
override def runsAfter: Set[Class[_ <: Phase]] = Set(classOf[Erasure], classOf[FunctionalInterfaces])
2425

2526
override def transformApply(tree: Apply)(implicit ctx: Context, info: TransformerInfo): Tree = {
2627
import ast.Trees._

0 commit comments

Comments
 (0)