Skip to content

Commit d0e49f5

Browse files
author
Hermes Espínola González
authored
Merge branch 'master' into error-msg/stable-identifiers
2 parents 1aefc73 + c04eb15 commit d0e49f5

File tree

442 files changed

+6796
-1955
lines changed

Some content is hidden

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

442 files changed

+6796
-1955
lines changed

.drone.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pipeline:
5252
image: lampepfl/dotty:2018-10-01
5353
commands:
5454
- ./project/scripts/genDocs
55-
secrets: [ bot_pass ]
55+
secrets: [ bot_token ]
5656
when:
5757
event: push
5858
# We only generate the documentation for the master branch
@@ -114,7 +114,3 @@ pipeline:
114114
when:
115115
status: [ failure ]
116116
event: [ push, tag, deployment ]
117-
118-
branches:
119-
# The gh-pages branch holds the documentation and don't need to be built
120-
exclude: gh-pages

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package dotc
33

44
import util.SourceFile
55
import ast.{tpd, untpd}
6-
import tpd.{ Tree, TreeTraverser }
6+
import dotty.tools.dotc.ast.Trees
7+
import tpd.{Tree, TreeTraverser}
78
import typer.PrepareInlineable.InlineAccessors
89
import dotty.tools.dotc.core.Contexts.Context
910
import dotty.tools.dotc.core.SymDenotations.ClassDenotation
1011
import dotty.tools.dotc.core.Symbols._
1112
import dotty.tools.dotc.transform.SymUtils._
13+
import dotty.tools.dotc.typer.Inliner
1214

1315
class CompilationUnit(val source: SourceFile) {
1416

@@ -23,10 +25,10 @@ class CompilationUnit(val source: SourceFile) {
2325
/** Pickled TASTY binaries, indexed by class. */
2426
var pickled: Map[ClassSymbol, Array[Byte]] = Map()
2527

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+
/** Will be set to `true` if contains `Quote`, `Splice` or calls to inline methods.
29+
* The information is used in phase `Staging` in order to avoid traversing a quote-less tree.
2830
*/
29-
var containsQuotesOrSplices: Boolean = false
31+
var needsStaging: Boolean = false
3032

3133
/** A structure containing a temporary map for generating inline accessors */
3234
val inlineAccessors: InlineAccessors = new InlineAccessors
@@ -46,17 +48,18 @@ object CompilationUnit {
4648
if (forceTrees) {
4749
val force = new Force
4850
force.traverse(unit1.tpdTree)
49-
unit1.containsQuotesOrSplices = force.containsQuotes
51+
unit1.needsStaging = force.needsStaging
5052
}
5153
unit1
5254
}
5355

5456
/** Force the tree to be loaded */
5557
private class Force extends TreeTraverser {
56-
var containsQuotes = false
58+
var needsStaging = false
5759
def traverse(tree: Tree)(implicit ctx: Context): Unit = {
58-
if (tree.symbol.isQuote)
59-
containsQuotes = true
60+
// Note that top-level splices are still inside the inline methods
61+
if (tree.symbol.isQuote || tpd.isInlineCall(tree))
62+
needsStaging = true
6063
traverseChildren(tree)
6164
}
6265
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Compiler {
4444
/** Phases dealing with TASTY tree pickling and unpickling */
4545
protected def picklerPhases: List[List[Phase]] =
4646
List(new Pickler) :: // Generate TASTY info
47-
List(new ReifyQuotes) :: // Turn quoted trees into explicit run-time data structures
47+
List(new Staging) :: // Inline calls, expand macros and turn quoted trees into explicit run-time data structures
4848
Nil
4949

5050
/** Phases dealing with the transformation from pickled trees to backend trees */
@@ -69,8 +69,7 @@ class Compiler {
6969
new ExplicitOuter, // Add accessors to outer classes from nested ones.
7070
new ExplicitSelf, // Make references to non-trivial self types explicit as casts
7171
new StringInterpolatorOpt, // Optimizes raw and s string interpolators by rewriting them to string concatentations
72-
new CrossCastAnd, // Normalize selections involving intersection types.
73-
new Splitter) :: // Expand selections involving union types into conditionals
72+
new CrossCastAnd) :: // Normalize selections involving intersection types.
7473
List(new PruneErasedDefs, // Drop erased definitions from scopes and simplify erased expressions
7574
new VCInlineMethods, // Inlines calls to value class methods
7675
new SeqLiterals, // Express vararg arguments as arrays

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class Driver {
3434
case ex: FatalError =>
3535
ctx.error(ex.getMessage) // signals that we should fail compilation.
3636
ctx.reporter
37+
case ex: Throwable =>
38+
println(s"$ex while compiling ${fileNames.mkString(", ")}")
39+
throw ex
3740
}
3841
else ctx.reporter
3942

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,10 +870,21 @@ object desugar {
870870
* def pn = x$1._n
871871
* body
872872
* }
873+
*
874+
* or if `isGenericTuple`
875+
*
876+
* x$1 => {
877+
* def p1 = x$1.apply(0)
878+
* ...
879+
* def pn = x$1.apply(n-1)
880+
* body
881+
* }
873882
*/
874-
def makeTupledFunction(params: List[ValDef], body: Tree)(implicit ctx: Context): Tree = {
883+
def makeTupledFunction(params: List[ValDef], body: Tree, isGenericTuple: Boolean)(implicit ctx: Context): Tree = {
875884
val param = makeSyntheticParameter()
876-
def selector(n: Int) = Select(refOfDef(param), nme.selectorName(n))
885+
def selector(n: Int) =
886+
if (isGenericTuple) Apply(Select(refOfDef(param), nme.apply), Literal(Constant(n)))
887+
else Select(refOfDef(param), nme.selectorName(n))
877888
val vdefs =
878889
params.zipWithIndex.map{
879890
case (param, idx) =>

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package ast
55
import core._
66
import Flags._, Trees._, Types._, Contexts._
77
import Names._, StdNames._, NameOps._, Symbols._
8-
import typer.ConstFold
8+
import typer.{ConstFold, Inliner}
99
import reporting.trace
1010

1111
import scala.annotation.tailrec
@@ -737,6 +737,17 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
737737
case _ => This(ctx.owner.enclosingClass.asClass)
738738
}
739739

740+
/** Is this an application on a structural selection?
741+
*
742+
* @see isStructuralTermSelect
743+
*/
744+
def isStructuralTermApply(tree: Tree)(implicit ctx: Context): Boolean = tree match {
745+
case Apply(fun, _) =>
746+
isStructuralTermSelect(fun)
747+
case _ =>
748+
false
749+
}
750+
740751
/** Is this a selection of a member of a structural type that is not a member
741752
* of an underlying class or trait?
742753
*/
@@ -759,6 +770,14 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
759770
false
760771
}
761772

773+
/** Is this call a call to a method that is marked as Inline */
774+
def isInlineCall(arg: Tree)(implicit ctx: Context): Boolean = arg match {
775+
case _: RefTree | _: GenericApply[_] =>
776+
!arg.tpe.widenDealias.isInstanceOf[MethodicType] && Inliner.isInlineable(arg)
777+
case _ =>
778+
false
779+
}
780+
762781
/** Structural tree comparison (since == on trees is reference equality).
763782
* For the moment, only Ident, Select, Literal, Apply and TypeApply are supported
764783
*/

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,10 @@ object Trees {
484484

485485
/** { stats; expr } */
486486
case class Block[-T >: Untyped] private[ast] (stats: List[Tree[T]], expr: Tree[T])
487-
extends TermTree[T] {
487+
extends Tree[T] {
488488
type ThisTree[-T >: Untyped] = Block[T]
489+
override def isType: Boolean = expr.isType
490+
override def isTerm: Boolean = !isType // this will classify empty trees as terms, which is necessary
489491
}
490492

491493
/** if cond then thenp else elsep */
@@ -583,9 +585,8 @@ object Trees {
583585

584586
/** A tree representing inlined code.
585587
*
586-
* @param call Info about the original call that was inlined
587-
* Until PostTyper, this is the full call, afterwards only
588-
* a reference to the toplevel class from which the call was inlined.
588+
* @param call Info about the original call that was inlined.
589+
* Only a reference to the toplevel class from which the call was inlined.
589590
* @param bindings Bindings for proxies to be used in the inlined code
590591
* @param expansion The inlined tree, minus bindings.
591592
*

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

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
4040
def Super(qual: Tree, mixName: TypeName, inConstrCall: Boolean, mixinClass: Symbol = NoSymbol)(implicit ctx: Context): Super =
4141
Super(qual, if (mixName.isEmpty) untpd.EmptyTypeIdent else untpd.Ident(mixName), inConstrCall, mixinClass)
4242

43-
def Apply(fn: Tree, args: List[Tree])(implicit ctx: Context): Apply =
43+
def Apply(fn: Tree, args: List[Tree])(implicit ctx: Context): Apply = {
44+
assert(fn.isInstanceOf[RefTree] || fn.isInstanceOf[GenericApply[_]])
4445
ta.assignType(untpd.Apply(fn, args), fn, args)
46+
}
4547

46-
def TypeApply(fn: Tree, args: List[Tree])(implicit ctx: Context): TypeApply =
48+
def TypeApply(fn: Tree, args: List[Tree])(implicit ctx: Context): TypeApply = {
49+
assert(fn.isInstanceOf[RefTree] || fn.isInstanceOf[GenericApply[_]])
4750
ta.assignType(untpd.TypeApply(fn, args), fn, args)
51+
}
4852

4953
def Literal(const: Constant)(implicit ctx: Context): Literal =
5054
ta.assignType(untpd.Literal(const))
@@ -181,8 +185,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
181185
def Alternative(trees: List[Tree])(implicit ctx: Context): Alternative =
182186
ta.assignType(untpd.Alternative(trees), trees)
183187

184-
def UnApply(fun: Tree, implicits: List[Tree], patterns: List[Tree], proto: Type)(implicit ctx: Context): UnApply =
188+
def UnApply(fun: Tree, implicits: List[Tree], patterns: List[Tree], proto: Type)(implicit ctx: Context): UnApply = {
189+
assert(fun.isInstanceOf[RefTree] || fun.isInstanceOf[GenericApply[_]])
185190
ta.assignType(untpd.UnApply(fun, implicits, patterns), proto)
191+
}
186192

187193
def ValDef(sym: TermSymbol, rhs: LazyTree = EmptyTree)(implicit ctx: Context): ValDef =
188194
ta.assignType(untpd.ValDef(sym.name, TypeTree(sym.info), rhs), sym)
@@ -913,7 +919,17 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
913919
def outerSelect(levels: Int, tp: Type)(implicit ctx: Context): Tree =
914920
untpd.Select(tree, OuterSelectName(EmptyTermName, levels)).withType(SkolemType(tp))
915921

916-
def underlyingArgument(implicit ctx: Context): Tree = mapToUnderlying.transform(tree)
922+
/** Replace Inlined nodes and InlineProxy references to underlying arguments */
923+
def underlyingArgument(implicit ctx: Context): Tree = {
924+
val mapToUnderlying = new MapToUnderlying {
925+
override def skipLocal(sym: Symbol): Boolean =
926+
sym.is(InlineProxy) || sym.is(Synthetic)
927+
}
928+
mapToUnderlying.transform(tree)
929+
}
930+
931+
/** Replace Ident nodes references to the underlying tree that defined them */
932+
def underlying(implicit ctx: Context): Tree = new MapToUnderlying().transform(tree)
917933

918934
// --- Higher order traversal methods -------------------------------
919935

@@ -941,18 +957,22 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
941957
}
942958
}
943959

944-
/** Map Inlined nodes, InlineProxy references and Synthetic val references to underlying arguments */
945-
object mapToUnderlying extends TreeMap {
960+
/** Map Inlined nodes, NamedArgs, Blocks with no statements and local references to underlying arguments.
961+
* Also drops Inline and Block with no statements.
962+
*/
963+
class MapToUnderlying extends TreeMap {
946964
override def transform(tree: Tree)(implicit ctx: Context): Tree = tree match {
947-
case tree: Ident if tree.symbol.is(InlineProxy) || (tree.symbol.is(Synthetic) && !tree.symbol.owner.isClass) =>
965+
case tree: Ident if !tree.symbol.owner.isClass && skipLocal(tree.symbol) =>
948966
tree.symbol.defTree match {
949967
case defTree: ValOrDefDef => transform(defTree.rhs)
950968
case _ => tree
951969
}
952970
case Inlined(_, _, arg) => transform(arg)
971+
case Block(Nil, arg) => transform(arg)
953972
case NamedArg(_, arg) => transform(arg)
954973
case tree => super.transform(tree)
955974
}
975+
def skipLocal(sym: Symbol): Boolean = true
956976
}
957977

958978
implicit class ListOfTreeDecorator(val xs: List[tpd.Tree]) extends AnyVal {

compiler/src/dotty/tools/dotc/config/Printers.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ object Printers {
2828
val overload: Printer = noPrinter
2929
val patmatch: Printer = noPrinter
3030
val pickling: Printer = noPrinter
31+
val quotePickling: Printer = noPrinter
3132
val plugins: Printer = noPrinter
3233
val simplify: Printer = noPrinter
3334
val subtyping: Printer = noPrinter

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class ScalaSettings extends Settings.SettingGroup {
116116
val YprintDebug: Setting[Boolean] = BooleanSetting("-Yprint-debug", "when printing trees, print some extra information useful for debugging.")
117117
val YprintDebugOwners: Setting[Boolean] = BooleanSetting("-Yprint-debug-owners", "when printing trees, print owners of definitions.")
118118
val YshowPrintErrors: Setting[Boolean] = BooleanSetting("-Yshow-print-errors", "don't suppress exceptions thrown during tree printing.")
119+
val YshowRawQuoteTrees: Setting[Boolean] = BooleanSetting("-Yshow-raw-tree", "don't remove quote artifacts")
119120
val YtestPickler: Setting[Boolean] = BooleanSetting("-Ytest-pickler", "self-test for pickling functionality; should be used with -Ystop-after:pickler")
120121
val YcheckReentrant: Setting[Boolean] = BooleanSetting("-Ycheck-reentrant", "check that compiled program does not contain vars that can be accessed from a global root.")
121122
val YdropComments: Setting[Boolean] = BooleanSetting("-Ydrop-comments", "Drop comments when scanning source files.")

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ object Definitions {
2424
* else without affecting the set of programs that can be compiled.
2525
*/
2626
val MaxImplementedFunctionArity: Int = 22
27-
28-
/** The maximal arity of a function that can be accessed as member of a structural type */
29-
val MaxStructuralMethodArity: Int = 7
3027
}
3128

3229
/** A class defining symbols and types of standard definitions

compiler/src/dotty/tools/dotc/core/StdNames.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,6 @@ object StdNames {
501501
val scala_ : N = "scala"
502502
val scalaShadowing : N = "scalaShadowing"
503503
val selectDynamic: N = "selectDynamic"
504-
val selectDynamicMethod: N = "selectDynamicMethod"
505504
val selectOverloadedMethod: N = "selectOverloadedMethod"
506505
val selectTerm: N = "selectTerm"
507506
val selectType: N = "selectType"

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,10 @@ object SymDenotations {
16311631
Stats.record("basetype cache entries")
16321632
if (!baseTp.exists) Stats.record("basetype cache NoTypes")
16331633
}
1634-
btrCache.put(tp, baseTp)
1634+
if (!tp.isProvisional)
1635+
btrCache.put(tp, baseTp)
1636+
else
1637+
btrCache.remove(tp) // Remove any potential sentinel value
16351638
}
16361639

16371640
def ensureAcyclic(baseTp: Type) = {
@@ -1682,8 +1685,8 @@ object SymDenotations {
16821685
case _ =>
16831686
val superTp = tp.superType
16841687
val baseTp = recur(superTp)
1685-
if (inCache(superTp) && tp.symbol.maybeOwner.isType)
1686-
record(tp, baseTp) // typeref cannot be a GADT, so cache is stable
1688+
if (inCache(superTp))
1689+
record(tp, baseTp)
16871690
else
16881691
btrCache.remove(tp)
16891692
baseTp
@@ -1717,8 +1720,6 @@ object SymDenotations {
17171720
val baseTp = recur(superTp)
17181721
tp match {
17191722
case tp: CachedType if baseTp.exists && inCache(superTp) =>
1720-
// Note: This also works for TypeVars: If they are not instantiated, their supertype
1721-
// is a TypeParamRef, which is never cached. So uninstantiated TypeVars are not cached either.
17221723
record(tp, baseTp)
17231724
case _ =>
17241725
}

0 commit comments

Comments
 (0)