docs/_docs/contributing/architecture/phases.md
As described in the compiler overview, dotc is divided into a list of phases,
specified in the Compiler class.
a flattened list of all the phases can be displayed by invoking
the compiler with the -Xshow-phases flag:
$ scalac -Xshow-phases
In class Compiler you can access the list of phases with the method phases:
def phases: List[List[Phase]] =
frontendPhases ::: picklerPhases ::: transformPhases ::: backendPhases
You can see that phases are actually grouped into sublists, given by the signature
List[List[Phase]]; that is, each sublist forms a phase group that is then fused into a
single tree traversal when a Run is executed.
Phase fusion allows each phase of a group to be small and modular, (each performing a single function), while reducing the number of tree traversals and increasing performance.
Phases are able to be grouped together if they inherit from MiniPhase.
Phases fall into four categories, allowing customisation by sub-classes of Compiler:
frontendPhasesIn the main compiler these include parser, typer, posttyper, prepjsinterop and phases for producing SemanticDB and communicating with the incremental compiler Zinc. The parser reads source programs and generates untyped abstract syntax trees, which in typer are then typechecked and transformed into typed abstract syntax trees. Following is posttyper, performing checks and cleanups that require a fully typed program. In particular, it
super calls in traitsequals and hashCode for case classes.picklerPhasesThese phases start with pickler, which serializes typed trees
produced by the frontendPhases into TASTy format. Following is inlining,
which expand calls to inline methods, and postInlining providing implementations
of the Mirror framework for inlined calls.
Finally are staging, which ensures that quotes conform to the
Phase Consistency Principle (PCP), and pickleQuotes which converts quoted
trees to embedded TASTy strings.
transformPhasesThese phases are concerned with transformation into lower-level forms suitable for the runtime system, with two sub-groupings:
ElimErasedValueType to
CollectSuperCalls. These further transform trees until they are essentially a
structured version of Java bytecode.backendPhasesThese map the transformed trees to Java classfiles or SJSIR files.