Skip to content

Commit 6c561c2

Browse files
authored
Merge branch 'master' into wip/scala#3509
2 parents f13589a + 576f6c6 commit 6c561c2

File tree

280 files changed

+5916
-1323
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

280 files changed

+5916
-1323
lines changed

.drone.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@ pipeline:
2525
image: lampepfl/dotty:2017-11-17
2626
commands:
2727
- cp -R . /tmp/1/ && cd /tmp/1/
28-
- ./project/scripts/sbt ";compile ;testAll"
28+
- ./project/scripts/sbt ";compile ;test"
2929
- ./project/scripts/sbtTests
3030

3131
test_bootstrapped:
3232
group: test
3333
image: lampepfl/dotty:2017-11-17
3434
commands:
3535
- cp -R . /tmp/2/ && cd /tmp/2/
36-
- ./project/scripts/sbt ";dotty-bootstrapped/compile ;dotty-bootstrapped/testAll"
36+
- ./project/scripts/sbt ";dotty-bootstrapped/compile ;dotty-bootstrapped/test"
3737
- ./project/scripts/sbtBootstrappedTests
3838

3939
test_optimised:
4040
group: test
4141
image: lampepfl/dotty:2017-11-17
4242
commands:
4343
- cp -R . /tmp/3/ && cd /tmp/3/
44-
- ./project/scripts/sbt dotty-optimised/testAll
44+
- ./project/scripts/sbt dotty-optimised/test
4545

4646
test_sbt:
4747
group: test

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,9 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
11711171
object Template extends TemplateDeconstructor {
11721172
def _1: List[Tree] = field.parents
11731173
def _2: ValDef = field.self
1174-
def _3: List[Tree] = field.constr :: field.body
1174+
def _3: List[Tree] =
1175+
if (field.constr.rhs.isEmpty) field.body
1176+
else field.constr :: field.body
11751177
}
11761178

11771179
object Bind extends BindDeconstructor {

compiler/src/dotty/tools/dotc/CompilationUnit.scala

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import dotty.tools.dotc.ast.tpd.{ Tree, TreeTraverser }
88
import dotty.tools.dotc.core.Contexts.Context
99
import dotty.tools.dotc.core.SymDenotations.ClassDenotation
1010
import dotty.tools.dotc.core.Symbols._
11+
import dotty.tools.dotc.transform.SymUtils._
1112

1213
class CompilationUnit(val source: SourceFile) {
1314

@@ -21,22 +22,39 @@ class CompilationUnit(val source: SourceFile) {
2122

2223
/** Pickled TASTY binaries, indexed by class. */
2324
var pickled: Map[ClassSymbol, Array[Byte]] = Map()
25+
26+
/** Will be reset to `true` if `untpdTree` contains `Quote` trees. The information
27+
* is used in phase ReifyQuotes in order to avoid traversing a quote-less tree.
28+
*/
29+
var containsQuotesOrSplices: Boolean = false
2430
}
2531

2632
object CompilationUnit {
2733

2834
/** Make a compilation unit for top class `clsd` with the contends of the `unpickled` */
29-
def mkCompilationUnit(clsd: ClassDenotation, unpickled: Tree, forceTrees: Boolean)(implicit ctx: Context): CompilationUnit = {
35+
def mkCompilationUnit(clsd: ClassDenotation, unpickled: Tree, forceTrees: Boolean)(implicit ctx: Context): CompilationUnit =
36+
mkCompilationUnit(new SourceFile(clsd.symbol.associatedFile, Seq()), unpickled, forceTrees)
37+
38+
/** Make a compilation unit the given unpickled tree */
39+
def mkCompilationUnit(source: SourceFile, unpickled: Tree, forceTrees: Boolean)(implicit ctx: Context): CompilationUnit = {
3040
assert(!unpickled.isEmpty, unpickled)
31-
val unit1 = new CompilationUnit(new SourceFile(clsd.symbol.associatedFile, Seq()))
41+
val unit1 = new CompilationUnit(source)
3242
unit1.tpdTree = unpickled
33-
if (forceTrees)
43+
if (forceTrees) {
44+
val force = new Force
3445
force.traverse(unit1.tpdTree)
46+
unit1.containsQuotesOrSplices = force.containsQuotes
47+
}
3548
unit1
3649
}
3750

3851
/** Force the tree to be loaded */
39-
private object force extends TreeTraverser {
40-
def traverse(tree: Tree)(implicit ctx: Context): Unit = traverseChildren(tree)
52+
private class Force extends TreeTraverser {
53+
var containsQuotes = false
54+
def traverse(tree: Tree)(implicit ctx: Context): Unit = {
55+
if (tree.symbol.isQuote)
56+
containsQuotes = true
57+
traverseChildren(tree)
58+
}
4159
}
4260
}

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 87 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -40,77 +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 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
99-
// 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-
)
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
114130

115131
var runId = 1
116132
def nextRunId = {

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,11 +1065,12 @@ object desugar {
10651065
AppliedTypeTree(ref(seqType), t),
10661066
New(ref(defn.RepeatedAnnotType), Nil :: Nil))
10671067
} else {
1068-
assert(ctx.mode.isExpr || ctx.reporter.hasErrors, ctx.mode)
1068+
assert(ctx.mode.isExpr || ctx.reporter.hasErrors || ctx.mode.is(Mode.Interactive), ctx.mode)
10691069
Select(t, op.name)
10701070
}
10711071
case PrefixOp(op, t) =>
1072-
Select(t, nme.UNARY_PREFIX ++ op.name)
1072+
val nspace = if (ctx.mode.is(Mode.Type)) tpnme else nme
1073+
Select(t, nspace.UNARY_PREFIX ++ op.name)
10731074
case Tuple(ts) =>
10741075
val arity = ts.length
10751076
def tupleTypeRef = defn.TupleType(arity)

0 commit comments

Comments
 (0)