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