@@ -40,78 +40,93 @@ class Compiler {
4040 * plain SymDenotation, as opposed to a UniqueRefDenotation.
4141 */
4242 def phases : List [List [Phase ]] =
43- List (
44- List (new FrontEnd ), // Compiler frontend: scanner, parser, namer, typer
45- List (new sbt.ExtractDependencies ), // Sends information on classes' dependencies to sbt via callbacks
46- List (new PostTyper ), // Additional checks and cleanups after type checking
47- List (new sbt.ExtractAPI ), // Sends a representation of the API of classes to sbt via callbacks
48- List (new Pickler ), // Generate TASTY info
49- List (new LinkAll ), // Reload compilation units from TASTY for library code (if needed)
50- List (new ReifyQuotes ), // Turn quoted trees into explicit run-time data structures
51- List (new FirstTransform , // Some transformations to put trees into a canonical form
52- new CheckReentrant , // Internal use only: Check that compiled program has no data races involving global vars
53- new ElimPackagePrefixes ), // Eliminate references to package prefixes in Select nodes
54- List (new CheckStatic , // Check restrictions that apply to @static members
55- new ElimRepeated , // Rewrite vararg parameters and arguments
56- new NormalizeFlags , // Rewrite some definition flags
57- new ExtensionMethods , // Expand methods of value classes with extension methods
58- new ExpandSAMs , // Expand single abstract method closures to anonymous classes
59- new TailRec , // Rewrite tail recursion to loops
60- new ByNameClosures , // Expand arguments to by-name parameters to closures
61- new LiftTry , // Put try expressions that might execute on non-empty stacks into their own methods
62- new HoistSuperArgs , // Hoist complex arguments of supercalls to enclosing scope
63- new ClassOf , // Expand `Predef.classOf` calls.
64- new RefChecks ), // Various checks mostly related to abstract members and overriding
65- List (new TryCatchPatterns , // Compile cases in try/catch
66- new PatternMatcher , // Compile pattern matches
67- new ExplicitOuter , // Add accessors to outer classes from nested ones.
68- new ExplicitSelf , // Make references to non-trivial self types explicit as casts
69- new ShortcutImplicits , // Allow implicit functions without creating closures
70- new CrossCastAnd , // Normalize selections involving intersection types.
71- new Splitter ), // Expand selections involving union types into conditionals
72- List (new PhantomArgLift , // Extracts the evaluation of phantom arguments placing them before the call.
73- new VCInlineMethods , // Inlines calls to value class methods
74- new SeqLiterals , // Express vararg arguments as arrays
75- new InterceptedMethods , // Special handling of `==`, `|=`, `getClass` methods
76- new Getters , // Replace non-private vals and vars with getter defs (fields are added later)
77- new ElimByName , // Expand by-name parameter references
78- new ElimOuterSelect , // Expand outer selections
79- new AugmentScala2Traits , // Expand traits defined in Scala 2.x to simulate old-style rewritings
80- new ResolveSuper , // Implement super accessors and add forwarders to trait methods
81- new Simplify , // Perform local optimizations, simplified versions of what linker does.
82- new PrimitiveForwarders , // Add forwarders to trait methods that have a mismatch between generic and primitives
83- new FunctionXXLForwarders , // Add forwarders for FunctionXXL apply method
84- new ArrayConstructors ), // Intercept creation of (non-generic) arrays and intrinsify.
85- List (new Erasure ), // Rewrite types to JVM model, erasing all type parameters, abstract types and refinements.
86- List (new ElimErasedValueType , // Expand erased value types to their underlying implmementation types
87- new VCElideAllocations , // Peep-hole optimization to eliminate unnecessary value class allocations
88- new Mixin , // Expand trait fields and trait initializers
89- new LazyVals , // Expand lazy vals
90- new Memoize , // Add private fields to getters and setters
91- new NonLocalReturns , // Expand non-local returns
92- new CapturedVars ), // Represent vars captured by closures as heap objects
93- List (new Constructors , // Collect initialization code in primary constructors
94- // Note: constructors changes decls in transformTemplate, no InfoTransformers should be added after it
95- new FunctionalInterfaces , // Rewrites closures to implement @specialized types of Functions.
96- new GetClass , // Rewrites getClass calls on primitive types.
97- new Simplify ), // Perform local optimizations, simplified versions of what linker does.
98- List (new LinkScala2Impls , // Redirect calls to trait methods defined by Scala 2.x, so that they now go to their implementations
99- new LambdaLift , // Lifts out nested functions to class scope, storing free variables in environments
100- // Note: in this mini-phase block scopes are incorrect. No phases that rely on scopes should be here
101- new ElimStaticThis ), // Replace `this` references to static objects by global identifiers
102- List (new Flatten , // Lift all inner classes to package scope
103- new RestoreScopes , // Repair scopes rendered invalid by moving definitions in prior phases of the group
104- new RenameLifted , // Renames lifted classes to local numbering scheme
105- new TransformWildcards , // Replace wildcards with default values
106- new MoveStatics , // Move static methods to companion classes
107- new ExpandPrivate , // Widen private definitions accessed from nested classes
108- new SelectStatic , // get rid of selects that would be compiled into GetStatic
109- new CollectEntryPoints , // Find classes with main methods
110- new CollectSuperCalls , // Find classes that are called with super
111- new DropInlined , // Drop Inlined nodes, since backend has no use for them
112- new LabelDefs ), // Converts calls to labels to jumps
113- List (new GenBCode ) // Generate JVM bytecode
114- )
43+ frontendPhases ::: picklerPhases ::: transformPhases ::: backendPhases
44+
45+ /** Phases dealing with the frontend up to trees ready for TASTY pickling */
46+ protected def frontendPhases : List [List [Phase ]] =
47+ List (new FrontEnd ) :: // Compiler frontend: scanner, parser, namer, typer
48+ List (new sbt.ExtractDependencies ) :: // Sends information on classes' dependencies to sbt via callbacks
49+ List (new PostTyper ) :: // Additional checks and cleanups after type checking
50+ List (new sbt.ExtractAPI ) :: // Sends a representation of the API of classes to sbt via callbacks
51+ Nil
52+
53+ /** Phases dealing with TASTY tree pickling and unpickling */
54+ protected def picklerPhases : List [List [Phase ]] =
55+ List (new Pickler ) :: // Generate TASTY info
56+ List (new LinkAll ) :: // Reload compilation units from TASTY for library code (if needed)
57+ List (new ReifyQuotes ) :: // Turn quoted trees into explicit run-time data structures
58+ Nil
59+
60+ /** Phases dealing with the transformation from pickled trees to backend trees */
61+ protected def transformPhases : List [List [Phase ]] =
62+ List (new FirstTransform , // Some transformations to put trees into a canonical form
63+ new CheckReentrant , // Internal use only: Check that compiled program has no data races involving global vars
64+ new ElimPackagePrefixes ) :: // Eliminate references to package prefixes in Select nodes
65+ List (new CheckStatic , // Check restrictions that apply to @static members
66+ new ElimRepeated , // Rewrite vararg parameters and arguments
67+ new NormalizeFlags , // Rewrite some definition flags
68+ new ExtensionMethods , // Expand methods of value classes with extension methods
69+ new ExpandSAMs , // Expand single abstract method closures to anonymous classes
70+ new TailRec , // Rewrite tail recursion to loops
71+ new ByNameClosures , // Expand arguments to by-name parameters to closures
72+ new LiftTry , // Put try expressions that might execute on non-empty stacks into their own methods
73+ new HoistSuperArgs , // Hoist complex arguments of supercalls to enclosing scope
74+ new ClassOf , // Expand `Predef.classOf` calls.
75+ new RefChecks ) :: // Various checks mostly related to abstract members and overriding
76+ List (new TryCatchPatterns , // Compile cases in try/catch
77+ new PatternMatcher , // Compile pattern matches
78+ new ExplicitOuter , // Add accessors to outer classes from nested ones.
79+ new ExplicitSelf , // Make references to non-trivial self types explicit as casts
80+ new ShortcutImplicits , // Allow implicit functions without creating closures
81+ new CrossCastAnd , // Normalize selections involving intersection types.
82+ new Splitter ) :: // Expand selections involving union types into conditionals
83+ List (new PhantomArgLift , // Extracts the evaluation of phantom arguments placing them before the call.
84+ new VCInlineMethods , // Inlines calls to value class methods
85+ new SeqLiterals , // Express vararg arguments as arrays
86+ new InterceptedMethods , // Special handling of `==`, `|=`, `getClass` methods
87+ new Getters , // Replace non-private vals and vars with getter defs (fields are added later)
88+ new ElimByName , // Expand by-name parameter references
89+ new ElimOuterSelect , // Expand outer selections
90+ new AugmentScala2Traits , // Expand traits defined in Scala 2.x to simulate old-style rewritings
91+ new ResolveSuper , // Implement super accessors and add forwarders to trait methods
92+ new Simplify , // Perform local optimizations, simplified versions of what linker does.
93+ new PrimitiveForwarders , // Add forwarders to trait methods that have a mismatch between generic and primitives
94+ new FunctionXXLForwarders , // Add forwarders for FunctionXXL apply method
95+ new ArrayConstructors ) :: // Intercept creation of (non-generic) arrays and intrinsify.
96+ List (new Erasure ) :: // Rewrite types to JVM model, erasing all type parameters, abstract types and refinements.
97+ List (new ElimErasedValueType , // Expand erased value types to their underlying implmementation types
98+ new VCElideAllocations , // Peep-hole optimization to eliminate unnecessary value class allocations
99+ new Mixin , // Expand trait fields and trait initializers
100+ new LazyVals , // Expand lazy vals
101+ new Memoize , // Add private fields to getters and setters
102+ new NonLocalReturns , // Expand non-local returns
103+ new CapturedVars ) :: // Represent vars captured by closures as heap objects
104+ List (new Constructors , // Collect initialization code in primary constructors
105+ // Note: constructors changes decls in transformTemplate, no InfoTransformers should be added after it
106+ new FunctionalInterfaces , // Rewrites closures to implement @specialized types of Functions.
107+ new GetClass , // Rewrites getClass calls on primitive types.
108+ new Simplify ) :: // Perform local optimizations, simplified versions of what linker does.
109+ List (new LinkScala2Impls , // Redirect calls to trait methods defined by Scala 2.x, so that they now go to their implementations
110+ new LambdaLift , // Lifts out nested functions to class scope, storing free variables in environments
111+ // Note: in this mini-phase block scopes are incorrect. No phases that rely on scopes should be here
112+ new ElimStaticThis ) :: // Replace `this` references to static objects by global identifiers
113+ List (new Flatten , // Lift all inner classes to package scope
114+ new RestoreScopes , // Repair scopes rendered invalid by moving definitions in prior phases of the group
115+ new RenameLifted , // Renames lifted classes to local numbering scheme
116+ new TransformWildcards , // Replace wildcards with default values
117+ new MoveStatics , // Move static methods to companion classes
118+ new ExpandPrivate , // Widen private definitions accessed from nested classes
119+ new SelectStatic , // get rid of selects that would be compiled into GetStatic
120+ new CollectEntryPoints , // Find classes with main methods
121+ new CollectSuperCalls , // Find classes that are called with super
122+ new DropInlined , // Drop Inlined nodes, since backend has no use for them
123+ new LabelDefs ) :: // Converts calls to labels to jumps
124+ Nil
125+
126+ /** Generate the output of the compilation */
127+ protected def backendPhases : List [List [Phase ]] =
128+ List (new GenBCode ) :: // Generate JVM bytecode
129+ Nil
115130
116131 var runId = 1
117132 def nextRunId = {
0 commit comments