Skip to content

Commit 096d0d3

Browse files
committed
Merge branch 'master' into 'topic/sbt1'
2 parents a15d0cd + 84bf2fa commit 096d0d3

File tree

120 files changed

+1476
-337
lines changed

Some content is hidden

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

120 files changed

+1476
-337
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class Compiler {
8181
new CrossCastAnd, // Normalize selections involving intersection types.
8282
new Splitter) :: // Expand selections involving union types into conditionals
8383
List(new ErasedDecls, // Removes all erased defs and vals decls (except for parameters)
84+
new IsInstanceOfChecker, // check runtime realisability for `isInstanceOf`
8485
new VCInlineMethods, // Inlines calls to value class methods
8586
new SeqLiterals, // Express vararg arguments as arrays
8687
new InterceptedMethods, // Special handling of `==`, `|=`, `getClass` methods

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,6 @@ object desugar {
429429
}
430430
val hasRepeatedParam = constrVparamss.exists(_.exists {
431431
case ValDef(_, tpt, _) => isRepeated(tpt)
432-
case _ => false
433432
})
434433
if (mods.is(Abstract) || hasRepeatedParam) Nil // cannot have default arguments for repeated parameters, hence copy method is not issued
435434
else {
@@ -805,7 +804,7 @@ object desugar {
805804
* If `inlineable` is true, tag $anonfun with an @inline annotation.
806805
*/
807806
def makeClosure(params: List[ValDef], body: Tree, tpt: Tree = TypeTree(), inlineable: Boolean)(implicit ctx: Context) = {
808-
var mods = synthetic
807+
var mods = synthetic | Artifact
809808
if (inlineable) mods |= Inline
810809
Block(
811810
DefDef(nme.ANON_FUN, Nil, params :: Nil, tpt, body).withMods(mods),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ object Trees {
771771
def flatten[T >: Untyped](trees: List[Tree[T]]): List[Tree[T]] = {
772772
var buf: ListBuffer[Tree[T]] = null
773773
var xs = trees
774-
while (xs.nonEmpty) {
774+
while (!xs.isEmpty) {
775775
xs.head match {
776776
case Thicket(elems) =>
777777
if (buf == null) {
@@ -805,7 +805,7 @@ object Trees {
805805
def unforced: AnyRef
806806
protected def force(x: AnyRef): Unit
807807
def forceIfLazy(implicit ctx: Context): T = unforced match {
808-
case lzy: Lazy[T] =>
808+
case lzy: Lazy[T @unchecked] =>
809809
val x = lzy.complete
810810
force(x)
811811
x

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ trait PropertiesTrait {
5656
def scalaPropOrElse(name: String, alt: String): String = scalaProps.getProperty(name, alt)
5757
def scalaPropOrEmpty(name: String): String = scalaPropOrElse(name, "")
5858
def scalaPropOrNone(name: String): Option[String] = Option(scalaProps.getProperty(name))
59-
59+
6060
/** Either the development or release version if known, otherwise
6161
* the empty string.
6262
*/
@@ -73,7 +73,15 @@ trait PropertiesTrait {
7373
} else ""
7474
}
7575
}
76-
76+
77+
/** Whether the current version of compiler is experimental
78+
*
79+
* 1. Snapshot and nightly releases are experimental.
80+
* 2. Features supported by experimental versions of the compiler:
81+
* - research plugins
82+
*/
83+
val experimental = versionString.contains("SNAPSHOT") || versionString.contains("NIGHTLY")
84+
7785
val copyrightString = scalaPropOrElse("copyright.string", "(c) 2002-2017 LAMP/EPFL")
7886

7987
/** This is the encoding to use reading in source files, overridden with -encoding

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ trait Hashable {
6464
var h = seed
6565
var xs = tps
6666
var len = arity
67-
while (xs.nonEmpty) {
67+
while (!xs.isEmpty) {
6868
val elemHash = typeHash(bs, xs.head)
6969
if (elemHash == NotCached) return NotCached
7070
h = hashing.mix(h, elemHash)

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -547,13 +547,15 @@ object Names {
547547
private[this] var size = 1
548548

549549
/** The hash of a name made of from characters cs[offset..offset+len-1]. */
550-
private def hashValue(cs: Array[Char], offset: Int, len: Int): Int =
551-
if (len > 0)
552-
(len * (41 * 41 * 41) +
553-
cs(offset) * (41 * 41) +
554-
cs(offset + len - 1) * 41 +
555-
cs(offset + (len >> 1)))
556-
else 0
550+
private def hashValue(cs: Array[Char], offset: Int, len: Int): Int = {
551+
var i = offset
552+
var hash = 0
553+
while (i < len + offset) {
554+
hash = 31 * hash + cs(i)
555+
i += 1
556+
}
557+
hash
558+
}
557559

558560
/** Is (the ASCII representation of) name at given index equal to
559561
* cs[offset..offset+len-1]?

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -519,23 +519,17 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
519519
def mergeParams(ps1: List[TypeParamRef], ps2: List[TypeParamRef]) =
520520
(ps1 /: ps2)((ps1, p2) => if (ps1.contains(p2)) ps1 else p2 :: ps1)
521521

522-
def mergeEntries(e1: Type, e2: Type): Type = e1 match {
523-
case e1: TypeBounds =>
524-
e2 match {
525-
case e2: TypeBounds => e1 & e2
526-
case _ if e1 contains e2 => e2
527-
case _ => mergeError
528-
}
529-
case tv1: TypeVar =>
530-
e2 match {
531-
case tv2: TypeVar if tv1.instanceOpt eq tv2.instanceOpt => e1
532-
case _ => mergeError
533-
}
522+
// Must be symmetric
523+
def mergeEntries(e1: Type, e2: Type): Type =
524+
(e1, e2) match {
534525
case _ if e1 eq e2 => e1
535-
case _ => mergeError
536-
}
537-
538-
def mergeError = throw new AssertionError(i"cannot merge $this with $other")
526+
case (e1: TypeBounds, e2: TypeBounds) => e1 & e2
527+
case (e1: TypeBounds, _) if e1 contains e2 => e2
528+
case (_, e2: TypeBounds) if e2 contains e1 => e1
529+
case (tv1: TypeVar, tv2: TypeVar) if tv1.instanceOpt eq tv2.instanceOpt => e1
530+
case _ =>
531+
throw new AssertionError(i"cannot merge $this with $other, mergeEntries($e1, $e2) failed")
532+
}
539533

540534
val that = other.asInstanceOf[OrderingConstraint]
541535
new OrderingConstraint(

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,6 @@ object Phases {
385385
override def toString = phaseName
386386
}
387387

388-
trait NeedsCompanions {
389-
def isCompanionNeeded(cls: ClassSymbol)(implicit ctx: Context): Boolean
390-
}
391-
392388
/** Replace all instances of `oldPhaseClass` in `current` phases
393389
* by the result of `newPhases` applied to the old phase.
394390
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ case class Signature(paramsSig: List[TypeName], resSig: TypeName) {
4545
final def consistentParams(that: Signature): Boolean = {
4646
@tailrec def loop(names1: List[TypeName], names2: List[TypeName]): Boolean =
4747
if (names1.isEmpty) names2.isEmpty
48-
else names2.nonEmpty && consistent(names1.head, names2.head) && loop(names1.tail, names2.tail)
48+
else !names2.isEmpty && consistent(names1.head, names2.head) && loop(names1.tail, names2.tail)
4949
loop(this.paramsSig, that.paramsSig)
5050
}
5151

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,15 +2862,16 @@ object Types {
28622862

28632863
type This = MethodType
28642864

2865+
val paramInfos = paramInfosExp(this)
2866+
val resType = resultTypeExp(this)
2867+
assert(resType.exists)
2868+
28652869
def companion: MethodTypeCompanion
28662870

28672871
final override def isJavaMethod: Boolean = companion eq JavaMethodType
28682872
final override def isImplicitMethod: Boolean = companion.eq(ImplicitMethodType) || companion.eq(ErasedImplicitMethodType)
28692873
final override def isErasedMethod: Boolean = companion.eq(ErasedMethodType) || companion.eq(ErasedImplicitMethodType)
28702874

2871-
val paramInfos = paramInfosExp(this)
2872-
val resType = resultTypeExp(this)
2873-
assert(resType.exists)
28742875

28752876
def computeSignature(implicit ctx: Context): Signature = {
28762877
val params = if (isErasedMethod) Nil else paramInfos

compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,14 @@ object PickledQuotes {
128128
private def classTagToTypeTree(ct: ClassTag[_])(implicit ctx: Context): TypeTree = {
129129
val tpe = ct match {
130130
case ClassTag.Unit => defn.UnitType
131+
case ClassTag.Boolean => defn.BooleanType
131132
case ClassTag.Byte => defn.ByteType
132133
case ClassTag.Char => defn.CharType
133134
case ClassTag.Short => defn.ShortType
134135
case ClassTag.Int => defn.IntType
135136
case ClassTag.Long => defn.LongType
136137
case ClassTag.Float => defn.FloatType
137-
case ClassTag.Double => defn.FloatType
138+
case ClassTag.Double => defn.DoubleType
138139
}
139140
TypeTree(tpe)
140141
}

compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ Standard-Section: "ASTs" TopLevelStat*
5656
Stat
5757
5858
Stat = Term
59-
VALDEF Length NameRef Type rhs_Term? Modifier*
60-
DEFDEF Length NameRef TypeParam* Params* return_Type rhs_Term?
59+
VALDEF Length NameRef type_Term rhs_Term? Modifier*
60+
DEFDEF Length NameRef TypeParam* Params* returnType_Term rhs_Term?
6161
Modifier*
62-
TYPEDEF Length NameRef (Type | Template) Modifier*
62+
TYPEDEF Length NameRef (type_Term | Template) Modifier*
6363
IMPORT Length qual_Term Selector*
6464
Selector = IMPORTED name_NameRef
6565
RENAMED to_NameRef
@@ -69,24 +69,23 @@ Standard-Section: "ASTs" TopLevelStat*
6969
TypeParam = TYPEPARAM Length NameRef Type Modifier*
7070
Params = PARAMS Length Param*
7171
Param = PARAM Length NameRef Type rhs_Term? Modifier* // rhs_Term is present in the case of an aliased class parameter
72-
Template = TEMPLATE Length TypeParam* Param* Parent* Self? Stat* // Stat* always starts with the primary constructor.
73-
Parent = Application
74-
Type
72+
Template = TEMPLATE Length TypeParam* Param* parent_Term* Self? Stat* // Stat* always starts with the primary constructor.
7573
Self = SELFDEF selfName_NameRef selfType_Type
7674
7775
Term = Path
78-
Application
7976
IDENT NameRef Type // used when term ident’s type is not a TermRef
8077
SELECT possiblySigned_NameRef qual_Term
8178
QUALTHIS typeIdent_Tree
82-
NEW cls_Type
79+
NEW clsType_Term
8380
NAMEDARG paramName_NameRef arg_Term
81+
APPLY Length fn_Term arg_Term*
82+
TYPEAPPLY Length fn_Term arg_Type*
8483
SUPER Length this_Term mixinTypeIdent_Tree?
85-
TYPED Length expr_Term ascription_Type
84+
TYPED Length expr_Term ascriptionType_Tern
8685
ASSIGN Length lhs_Term rhs_Term
8786
BLOCK Length expr_Term Stat*
8887
INLINED Length call_Term expr_Term Stat*
89-
LAMBDA Length meth_Term target_Type
88+
LAMBDA Length meth_Term target_Type?
9089
IF Length cond_Term then_Term else_Term
9190
MATCH Length sel_Term CaseDef*
9291
TRY Length expr_Term CaseDef* finalizer_Term?
@@ -98,7 +97,7 @@ Standard-Section: "ASTs" TopLevelStat*
9897
UNAPPLY Length fun_Term ImplicitArg* pat_Type pat_Term*
9998
IDENTtpt NameRef Type // used for all type idents
10099
SELECTtpt NameRef qual_Term
101-
SINGLETONtpt Path
100+
SINGLETONtpt ref_Term
102101
REFINEDtpt Length underlying_Term refinement_Stat*
103102
APPLIEDtpt Length tycon_Term arg_Term*
104103
POLYtpt Length TypeParam* body_Term
@@ -110,9 +109,7 @@ Standard-Section: "ASTs" TopLevelStat*
110109
EMPTYTREE
111110
SHAREDterm term_ASTRef
112111
HOLE Length idx_Nat arg_Tree*
113-
Application = APPLY Length fn_Term arg_Term*
114112
115-
TYPEAPPLY Length fn_Term arg_Type*
116113
CaseDef = CASEDEF Length pat_Term rhs_Tree guard_Tree?
117114
ImplicitArg = IMPLICITARG arg_Term
118115
ASTRef = Nat // byte position in AST payload
@@ -179,6 +176,7 @@ Standard-Section: "ASTs" TopLevelStat*
179176
SEALED
180177
CASE
181178
IMPLICIT
179+
ERASED
182180
LAZY
183181
OVERRIDE
184182
INLINE // inline method

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,13 @@ object Scanners {
249249
/** Are we directly in a string interpolation expression?
250250
*/
251251
private def inStringInterpolation =
252-
sepRegions.nonEmpty && sepRegions.head == STRINGLIT
252+
!sepRegions.isEmpty && sepRegions.head == STRINGLIT
253253

254254
/** Are we directly in a multiline string interpolation expression?
255255
* @pre inStringInterpolation
256256
*/
257257
private def inMultiLineInterpolation =
258-
inStringInterpolation && sepRegions.tail.nonEmpty && sepRegions.tail.head == STRINGPART
258+
inStringInterpolation && !sepRegions.tail.isEmpty && sepRegions.tail.head == STRINGPART
259259

260260
/** read next token and return last offset
261261
*/

compiler/src/dotty/tools/dotc/plugins/Plugin.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ sealed trait Plugin {
2929
* Research plugin receives a phase plan and return a new phase plan, while
3030
* non-research plugin returns a list of phases to be inserted.
3131
*/
32-
def research: Boolean = isInstanceOf[ResearchPlugin]
32+
def isResearch: Boolean = isInstanceOf[ResearchPlugin]
3333

3434
/** A description of this plugin's options, suitable as a response
3535
* to the -help command-line option. Conventionally, the options

compiler/src/dotty/tools/dotc/plugins/Plugins.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package plugins
33

44
import core._
55
import Contexts._
6-
import config.PathResolver
6+
import config.{ PathResolver, Properties }
77
import dotty.tools.io._
88
import Phases._
99
import config.Printers.plugins.{ println => debug }
@@ -128,7 +128,12 @@ trait Plugins {
128128
val updatedPlan = Plugins.schedule(plan, pluginPhases)
129129

130130
// add research plugins
131-
plugins.collect { case p: ResearchPlugin => p }.foldRight(updatedPlan) { (plug, plan) => plug.init(options(plug), plan) }
131+
if (Properties.experimental)
132+
plugins.collect { case p: ResearchPlugin => p }.foldRight(updatedPlan) {
133+
(plug, plan) => plug.init(options(plug), plan)
134+
}
135+
else
136+
updatedPlan
132137
}
133138
}
134139

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package dotty.tools.dotc.printing
22

3-
import dotty.tools.dotc.ast.Trees.{Closure, DefDef, Untyped, ValDef}
3+
import dotty.tools.dotc.ast.Trees._
44
import dotty.tools.dotc.ast.untpd.{PackageDef, Template, TypeDef}
55
import dotty.tools.dotc.ast.{Trees, untpd}
66
import dotty.tools.dotc.printing.Texts._
77
import dotty.tools.dotc.core.Contexts._
8+
import dotty.tools.dotc.core.StdNames.nme
89
import dotty.tools.dotc.core.Flags._
910
import dotty.tools.dotc.core.Symbols._
11+
import dotty.tools.dotc.core.StdNames._
1012

1113
import scala.language.implicitConversions
1214

@@ -15,9 +17,19 @@ class DecompilerPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
1517
override protected def filterModTextAnnots(annots: List[untpd.Tree]): List[untpd.Tree] =
1618
annots.filter(_.tpe != defn.SourceFileAnnotType)
1719

18-
override protected def blockText[T >: Untyped](trees: List[Trees.Tree[T]]): Text = {
19-
super.blockText(trees.filterNot(_.isInstanceOf[Closure[_]]))
20-
}
20+
override protected def blockToText[T >: Untyped](block: Block[T]): Text =
21+
block match {
22+
case Block(DefDef(_, _, _, _, Trees.If(cond, Trees.Block(body :: Nil, _), _)) :: Nil, y) if y.symbol.name == nme.WHILE_PREFIX =>
23+
keywordText("while") ~ " (" ~ toText(cond) ~ ")" ~ toText(body)
24+
case Block(DefDef(_, _, _, _, Trees.Block(body :: Nil, Trees.If(cond, _, _))) :: Nil, y) if y.symbol.name == nme.DO_WHILE_PREFIX =>
25+
keywordText("do") ~ toText(body) ~ keywordText("while") ~ " (" ~ toText(cond) ~ ")"
26+
case Block((meth @ DefDef(nme.ANON_FUN, _, _, _, _)) :: Nil, _: Closure[T]) =>
27+
withEnclosingDef(meth) {
28+
addVparamssText("", meth.vparamss) ~ " => " ~ toText(meth.rhs)
29+
}
30+
case _ =>
31+
super.blockToText(block)
32+
}
2133

2234
override protected def packageDefText(tree: PackageDef): Text = {
2335
val stats = tree.stats.filter {
@@ -29,8 +41,10 @@ class DecompilerPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
2941
case _ => toTextGlobal(stats, "\n")
3042
}
3143
val bodyText =
32-
if (currentPrecedence == TopLevelPrec) "\n" ~ statsText else " {" ~ statsText ~ "}"
33-
keywordStr("package ") ~ toTextPackageId(tree.pid) ~ bodyText
44+
if (tree.pid.symbol.isEmptyPackage) statsText
45+
else if (currentPrecedence == TopLevelPrec) "\n" ~ statsText
46+
else " {" ~ statsText ~ "}"
47+
(keywordStr("package ") ~ toTextPackageId(tree.pid)).provided(!tree.symbol.isEmptyPackage) ~ bodyText
3448
}
3549

3650
override protected def templateText(tree: TypeDef, impl: Template): Text = {
@@ -40,15 +54,14 @@ class DecompilerPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
4054
decl ~~ typeText(nameIdText(tree)) ~ withEnclosingDef(tree) { toTextTemplate(impl) } ~ ""
4155
}
4256

43-
override protected def defDefToText[T >: Untyped](tree: DefDef[T]): Text = {
44-
import untpd.{modsDeco => _, _}
45-
dclTextOr(tree) {
46-
val printLambda = tree.symbol.isAnonymousFunction
47-
val prefix = modText(tree.mods, keywordStr("def")) ~~ valDefText(nameIdText(tree)) provided (!printLambda)
48-
withEnclosingDef(tree) {
49-
addVparamssText(prefix ~ tparamsText(tree.tparams), tree.vparamss) ~ optAscription(tree.tpt).provided(!printLambda) ~
50-
optText(tree.rhs)((if (printLambda) " => " else " = ") ~ _)
51-
}
52-
}
57+
override protected def toTextTemplate(impl: Template, ofNew: Boolean = false): Text = {
58+
val impl1 = impl.copy(parents = impl.parents.filterNot(_.symbol.maybeOwner == defn.ObjectClass))
59+
super.toTextTemplate(impl1, ofNew)
60+
}
61+
62+
override protected def typeApplyText[T >: Untyped](tree: TypeApply[T]): Text = {
63+
if (tree.symbol eq defn.quoteMethod) "'"
64+
else if (tree.symbol eq defn.typeQuoteMethod) "'[" ~ toTextGlobal(tree.args, ", ") ~ "]"
65+
else super.typeApplyText(tree)
5366
}
5467
}

0 commit comments

Comments
 (0)