Skip to content

Commit 35f461e

Browse files
Merge branch 'master' into quote-timeout
2 parents c48c61a + a76d932 commit 35f461e

File tree

169 files changed

+1145
-905
lines changed

Some content is hidden

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

169 files changed

+1145
-905
lines changed

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

+21-25
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,22 @@ object desugar {
2626
/** If a Select node carries this attachment, suppress the check
2727
* that its type refers to an acessible symbol.
2828
*/
29-
val SuppressAccessCheck: Property.Key[Unit] = new Property.Key
29+
val SuppressAccessCheck: Property.Key[Unit] = Property.Key()
3030

3131
/** An attachment for companion modules of classes that have a `derives` clause.
3232
* The position value indicates the start position of the template of the
3333
* deriving class.
3434
*/
35-
val DerivingCompanion: Property.Key[SourcePosition] = new Property.Key
35+
val DerivingCompanion: Property.Key[SourcePosition] = Property.Key()
3636

3737
/** An attachment for match expressions generated from a PatDef or GenFrom.
3838
* Value of key == one of IrrefutablePatDef, IrrefutableGenFrom
3939
*/
40-
val CheckIrrefutable: Property.Key[MatchCheck] = new Property.StickyKey
41-
42-
/** What static check should be applied to a Match (none, irrefutable, exhaustive) */
43-
class MatchCheck(val n: Int) extends AnyVal
44-
object MatchCheck {
45-
val None = new MatchCheck(0)
46-
val Exhaustive = new MatchCheck(1)
47-
val IrrefutablePatDef = new MatchCheck(2)
48-
val IrrefutableGenFrom = new MatchCheck(3)
40+
val CheckIrrefutable: Property.Key[MatchCheck] = Property.StickyKey()
41+
42+
/** What static check should be applied to a Match? */
43+
enum MatchCheck {
44+
case None, Exhaustive, IrrefutablePatDef, IrrefutableGenFrom
4945
}
5046

5147
/** Info of a variable in a pattern: The named tree and its type */
@@ -136,17 +132,17 @@ object desugar {
136132
def derivedTypeParam(tdef: TypeDef, suffix: String = "")(implicit ctx: Context): TypeDef =
137133
cpy.TypeDef(tdef)(
138134
name = tdef.name ++ suffix,
139-
rhs = new DerivedFromParamTree(suffix).withSpan(tdef.rhs.span).watching(tdef)
135+
rhs = DerivedFromParamTree(suffix).withSpan(tdef.rhs.span).watching(tdef)
140136
)
141137

142138
/** A derived type definition watching `sym` */
143139
def derivedTypeParam(sym: TypeSymbol)(implicit ctx: Context): TypeDef =
144-
TypeDef(sym.name, new DerivedFromParamTree("").watching(sym)).withFlags(TypeParam)
140+
TypeDef(sym.name, DerivedFromParamTree("").watching(sym)).withFlags(TypeParam)
145141

146142
/** A value definition copied from `vdef` with a tpt typetree derived from it */
147143
def derivedTermParam(vdef: ValDef)(implicit ctx: Context): ValDef =
148144
cpy.ValDef(vdef)(
149-
tpt = new DerivedFromParamTree("").withSpan(vdef.tpt.span).watching(vdef))
145+
tpt = DerivedFromParamTree("").withSpan(vdef.tpt.span).watching(vdef))
150146

151147
// ----- Desugar methods -------------------------------------------------
152148

@@ -165,7 +161,7 @@ object desugar {
165161
// val getter = ValDef(mods, name, tpt, rhs) withPos vdef.pos?
166162
// right now vdef maps via expandedTree to a thicket which concerns itself.
167163
// I don't see a problem with that but if there is one we can avoid it by making a copy here.
168-
val setterParam = makeSyntheticParameter(tpt = (new SetterParamTree).watching(vdef))
164+
val setterParam = makeSyntheticParameter(tpt = SetterParamTree().watching(vdef))
169165
// The rhs gets filled in later, when field is generated and getter has parameters (see Memoize miniphase)
170166
val setterRhs = if (vdef.rhs.isEmpty) EmptyTree else unitLiteral
171167
val setter = cpy.DefDef(vdef)(
@@ -217,7 +213,7 @@ object desugar {
217213
val meth @ DefDef(_, tparams, vparamss, tpt, rhs) = transformQuotedPatternName(meth0)
218214
val methName = normalizeName(meth, tpt).asTermName
219215
val mods = meth.mods
220-
val epbuf = new ListBuffer[ValDef]
216+
val epbuf = ListBuffer[ValDef]()
221217
def desugarContextBounds(rhs: Tree): Tree = rhs match {
222218
case ContextBounds(tbounds, cxbounds) =>
223219
epbuf ++= makeImplicitParameters(cxbounds, Implicit, forPrimaryConstructor = isPrimaryConstructor)
@@ -443,7 +439,7 @@ object desugar {
443439
val (enumCases, enumStats) = stats.partition(DesugarEnums.isEnumCase)
444440
if (enumCases.isEmpty)
445441
ctx.error("Enumerations must constain at least one case", namePos)
446-
val enumCompanionRef = new TermRefTree()
442+
val enumCompanionRef = TermRefTree()
447443
val enumImport = Import(importDelegate = false, enumCompanionRef, enumCases.flatMap(caseIds))
448444
(enumImport :: enumStats, enumCases, enumCompanionRef)
449445
}
@@ -456,7 +452,7 @@ object desugar {
456452
val derivedVparamss = constrVparamss.nestedMap(derivedTermParam(_))
457453
val arity = constrVparamss.head.length
458454

459-
val classTycon: Tree = new TypeRefTree // watching is set at end of method
455+
val classTycon: Tree = TypeRefTree() // watching is set at end of method
460456

461457
def appliedTypeTree(tycon: Tree, args: List[Tree]) =
462458
(if (args.isEmpty) tycon else AppliedTypeTree(tycon, args))
@@ -766,7 +762,7 @@ object desugar {
766762
}
767763

768764
flatTree(cdef1 :: companions ::: implicitWrappers)
769-
}.reporting(res => i"desugared: $res", Printers.desugar)
765+
}.reporting(i"desugared: $result", Printers.desugar)
770766

771767
/** Expand
772768
*
@@ -844,7 +840,7 @@ object desugar {
844840
*/
845841
def normalizeName(mdef: MemberDef, impl: Tree)(implicit ctx: Context): Name = {
846842
var name = mdef.name
847-
if (name.isEmpty) name = name.likeSpaced(s"${inventName(impl)}_instance".toTermName)
843+
if (name.isEmpty) name = name.likeSpaced(s"${inventName(impl)}_given".toTermName)
848844
if (ctx.owner == defn.ScalaPackageClass && defn.reservedScalaClassNames.contains(name.toTypeName)) {
849845
def kind = if (name.isTypeName) "class" else "object"
850846
ctx.error(em"illegal redefinition of standard $kind $name", mdef.sourcePos)
@@ -895,8 +891,8 @@ object desugar {
895891
}
896892
else x
897893
}
898-
private val typeNameExtractor = new NameExtractor(followArgs = true)
899-
private val argNameExtractor = new NameExtractor(followArgs = false)
894+
private val typeNameExtractor = NameExtractor(followArgs = true)
895+
private val argNameExtractor = NameExtractor(followArgs = false)
900896

901897
private def inventTypeName(tree: Tree)(implicit ctx: Context): String = typeNameExtractor("", tree)
902898

@@ -1207,7 +1203,7 @@ object desugar {
12071203
def makeContextualFunction(formals: List[Type], body: Tree, isErased: Boolean)(implicit ctx: Context): Tree = {
12081204
val mods = if (isErased) Given | Erased else Given
12091205
val params = makeImplicitParameters(formals.map(TypeTree), mods)
1210-
new FunctionWithMods(params, body, Modifiers(mods))
1206+
FunctionWithMods(params, body, Modifiers(mods))
12111207
}
12121208

12131209
/** Add annotation to tree:
@@ -1419,7 +1415,7 @@ object desugar {
14191415
val pdefs = (valeqs, defpats, rhss).zipped.map(makePatDef(_, Modifiers(), _, _))
14201416
val rhs1 = makeFor(nme.map, nme.flatMap, GenFrom(defpat0, gen.expr, gen.checkMode) :: Nil, Block(pdefs, makeTuple(id0 :: ids)))
14211417
val allpats = gen.pat :: pats
1422-
val vfrom1 = new GenFrom(makeTuple(allpats), rhs1, GenCheckMode.Ignore)
1418+
val vfrom1 = GenFrom(makeTuple(allpats), rhs1, GenCheckMode.Ignore)
14231419
makeFor(mapName, flatMapName, vfrom1 :: rest1, body)
14241420
case (gen: GenFrom) :: test :: rest =>
14251421
val filtered = Apply(rhsSelect(gen, nme.withFilter), makeLambda(gen, test))
@@ -1594,7 +1590,7 @@ object desugar {
15941590
* without duplicates
15951591
*/
15961592
private def getVariables(tree: Tree)(implicit ctx: Context): List[VarInfo] = {
1597-
val buf = new ListBuffer[VarInfo]
1593+
val buf = ListBuffer[VarInfo]()
15981594
def seenName(name: Name) = buf exists (_._1.name == name)
15991595
def add(named: NameTree, t: Tree): Unit =
16001596
if (!seenName(named.name) && named.name.isTermName) buf += ((named, t))

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object DesugarEnums {
2121
}
2222

2323
/** Attachment containing the number of enum cases and the smallest kind that was seen so far. */
24-
val EnumCaseCount: Property.Key[(Int, DesugarEnums.CaseKind.Value)] = new Property.Key
24+
val EnumCaseCount: Property.Key[(Int, DesugarEnums.CaseKind.Value)] = Property.Key()
2525

2626
/** The enumeration class that belongs to an enum case. This works no matter
2727
* whether the case is still in the enum class or it has been transferred to the

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ object Trees {
8383
*/
8484
final def tpe: T @uncheckedVariance = {
8585
if (myTpe == null)
86-
throw new UnAssignedTypeException(this)
86+
throw UnAssignedTypeException(this)
8787
myTpe
8888
}
8989

@@ -857,19 +857,19 @@ object Trees {
857857

858858
class EmptyTree[T >: Untyped] extends Thicket(Nil)(NoSource) {
859859
// assert(uniqueId != 1492)
860-
override def withSpan(span: Span) = throw new AssertionError("Cannot change span of EmptyTree")
860+
override def withSpan(span: Span) = throw AssertionError("Cannot change span of EmptyTree")
861861
}
862862

863863
class EmptyValDef[T >: Untyped] extends ValDef[T](
864864
nme.WILDCARD, genericEmptyTree[T], genericEmptyTree[T])(NoSource) with WithoutTypeOrPos[T] {
865865
myTpe = NoType.asInstanceOf[T]
866866
setMods(untpd.Modifiers(PrivateLocal))
867867
override def isEmpty: Boolean = true
868-
override def withSpan(span: Span) = throw new AssertionError("Cannot change span of EmptyValDef")
868+
override def withSpan(span: Span) = throw AssertionError("Cannot change span of EmptyValDef")
869869
}
870870

871-
@sharable val theEmptyTree: EmptyTree[Type] = new EmptyTree[Type]
872-
@sharable val theEmptyValDef: EmptyValDef[Type] = new EmptyValDef[Type]
871+
@sharable val theEmptyTree = new EmptyTree[Type]()
872+
@sharable val theEmptyValDef = new EmptyValDef[Type]()
873873

874874
def genericEmptyValDef[T >: Untyped]: ValDef[T] = theEmptyValDef.asInstanceOf[ValDef[T]]
875875
def genericEmptyTree[T >: Untyped]: Thicket[T] = theEmptyTree.asInstanceOf[Thicket[T]]
@@ -992,11 +992,10 @@ object Trees {
992992

993993
@sharable val EmptyTree: Thicket = genericEmptyTree
994994
@sharable val EmptyValDef: ValDef = genericEmptyValDef
995-
@sharable val ContextualEmptyTree: Thicket = new EmptyTree // an empty tree marking a contextual closure
995+
@sharable val ContextualEmptyTree: Thicket = EmptyTree() // an empty tree marking a contextual closure
996996

997997
// ----- Auxiliary creation methods ------------------
998998

999-
def Thicket(trees: List[Tree])(implicit src: SourceFile): Thicket = new Thicket(trees)
1000999
def Thicket(): Thicket = EmptyTree
10011000
def Thicket(x1: Tree, x2: Tree)(implicit src: SourceFile): Thicket = Thicket(x1 :: x2 :: Nil)
10021001
def Thicket(x1: Tree, x2: Tree, x3: Tree)(implicit src: SourceFile): Thicket = Thicket(x1 :: x2 :: x3 :: Nil)
@@ -1036,7 +1035,7 @@ object Trees {
10361035
def Select(tree: Tree)(qualifier: Tree, name: Name)(implicit ctx: Context): Select = tree match {
10371036
case tree: SelectWithSig =>
10381037
if ((qualifier eq tree.qualifier) && (name == tree.name)) tree
1039-
else finalize(tree, new SelectWithSig(qualifier, name, tree.sig)(sourceFile(tree)))
1038+
else finalize(tree, SelectWithSig(qualifier, name, tree.sig)(sourceFile(tree)))
10401039
case tree: Select if (qualifier eq tree.qualifier) && (name == tree.name) => tree
10411040
case _ => finalize(tree, untpd.Select(qualifier, name)(sourceFile(tree)))
10421041
}

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

+16-16
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
153153
ta.assignType(untpd.SeqLiteral(elems, elemtpt), elems, elemtpt)
154154

155155
def JavaSeqLiteral(elems: List[Tree], elemtpt: Tree)(implicit ctx: Context): JavaSeqLiteral =
156-
ta.assignType(new untpd.JavaSeqLiteral(elems, elemtpt), elems, elemtpt).asInstanceOf[JavaSeqLiteral]
156+
ta.assignType(untpd.JavaSeqLiteral(elems, elemtpt), elems, elemtpt).asInstanceOf[JavaSeqLiteral]
157157

158158
def Inlined(call: Tree, bindings: List[MemberDef], expansion: Tree)(implicit ctx: Context): Inlined =
159159
ta.assignType(untpd.Inlined(call, bindings, expansion), bindings, expansion)
@@ -231,7 +231,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
231231
def valueParamss(tp: Type): (List[List[TermSymbol]], Type) = tp match {
232232
case tp: MethodType =>
233233
val isParamDependent = tp.isParamDependent
234-
val previousParamRefs = if (isParamDependent) new mutable.ListBuffer[TermRef]() else null
234+
val previousParamRefs = if (isParamDependent) mutable.ListBuffer[TermRef]() else null
235235

236236
def valueParam(name: TermName, origInfo: Type): TermSymbol = {
237237
val maybeImplicit =
@@ -294,7 +294,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
294294
val newTypeParams =
295295
for (tparam <- cls.typeParams if !(bodyTypeParams contains tparam))
296296
yield TypeDef(tparam)
297-
val findLocalDummy = new FindLocalDummyAccumulator(cls)
297+
val findLocalDummy = FindLocalDummyAccumulator(cls)
298298
val localDummy = ((NoSymbol: Symbol) /: body)(findLocalDummy.apply)
299299
.orElse(ctx.newLocalDummy(cls))
300300
val impl = untpd.Template(constr, parents, Nil, selfType, newTypeParams ++ body)
@@ -391,7 +391,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
391391
private def followOuterLinks(t: Tree)(implicit ctx: Context) = t match {
392392
case t: This if ctx.erasedTypes && !(t.symbol == ctx.owner.enclosingClass || t.symbol.isStaticOwner) =>
393393
// after erasure outer paths should be respected
394-
new ExplicitOuter.OuterOps(ctx).path(toCls = t.tpe.widen.classSymbol)
394+
ExplicitOuter.OuterOps(ctx).path(toCls = t.tpe.widen.classSymbol)
395395
case t =>
396396
t
397397
}
@@ -538,9 +538,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
538538
}
539539

540540
override val cpy: TypedTreeCopier = // Type ascription needed to pick up any new members in TreeCopier (currently there are none)
541-
new TypedTreeCopier
541+
TypedTreeCopier()
542542

543-
val cpyBetweenPhases: TimeTravellingTreeCopier = new TimeTravellingTreeCopier
543+
val cpyBetweenPhases: TimeTravellingTreeCopier = TimeTravellingTreeCopier()
544544

545545
class TypedTreeCopier extends TreeCopier {
546546
def postProcess(tree: Tree, copied: untpd.Tree): copied.ThisTree[Type] =
@@ -746,16 +746,16 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
746746
}
747747

748748
def shallowFold[T](z: T)(op: (T, tpd.Tree) => T)(implicit ctx: Context): T =
749-
new ShallowFolder(op).apply(z, tree)
749+
ShallowFolder(op).apply(z, tree)
750750

751751
def deepFold[T](z: T)(op: (T, tpd.Tree) => T)(implicit ctx: Context): T =
752-
new DeepFolder(op).apply(z, tree)
752+
DeepFolder(op).apply(z, tree)
753753

754754
def find[T](pred: (tpd.Tree) => Boolean)(implicit ctx: Context): Option[tpd.Tree] =
755755
shallowFold[Option[tpd.Tree]](None)((accum, tree) => if (pred(tree)) Some(tree) else accum)
756756

757757
def subst(from: List[Symbol], to: List[Symbol])(implicit ctx: Context): ThisTree =
758-
new TreeTypeMap(substFrom = from, substTo = to).apply(tree)
758+
TreeTypeMap(substFrom = from, substTo = to).apply(tree)
759759

760760
/** Change owner from `from` to `to`. If `from` is a weak owner, also change its
761761
* owner to `to`, and continue until a non-weak owner is reached.
@@ -766,7 +766,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
766766
loop(from.owner, from :: froms, to :: tos)
767767
else {
768768
//println(i"change owner ${from :: froms}%, % ==> $tos of $tree")
769-
new TreeTypeMap(oldOwners = from :: froms, newOwners = tos).apply(tree)
769+
TreeTypeMap(oldOwners = from :: froms, newOwners = tos).apply(tree)
770770
}
771771
}
772772
if (from == to) tree else loop(from, Nil, to :: Nil)
@@ -788,7 +788,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
788788
}
789789
val owners = ownerAcc(immutable.Set.empty[Symbol], tree).toList
790790
val newOwners = List.fill(owners.size)(newOwner)
791-
new TreeTypeMap(oldOwners = owners, newOwners = newOwners).apply(tree)
791+
TreeTypeMap(oldOwners = owners, newOwners = newOwners).apply(tree)
792792
}
793793

794794
/** After phase `trans`, set the owner of every definition in this tree that was formerly
@@ -1008,7 +1008,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
10081008
}
10091009

10101010
/** Replace Ident nodes references to the underlying tree that defined them */
1011-
def underlying(implicit ctx: Context): Tree = new MapToUnderlying().transform(tree)
1011+
def underlying(implicit ctx: Context): Tree = MapToUnderlying().transform(tree)
10121012

10131013
// --- Higher order traversal methods -------------------------------
10141014

@@ -1030,7 +1030,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
10301030

10311031
/** All subtrees of this tree that satisfy predicate `p`. */
10321032
def filterSubTrees(f: Tree => Boolean)(implicit ctx: Context): List[Tree] = {
1033-
val buf = new mutable.ListBuffer[Tree]
1033+
val buf = mutable.ListBuffer[Tree]()
10341034
foreachSubTree { tree => if (f(tree)) buf += tree }
10351035
buf.toList
10361036
}
@@ -1137,7 +1137,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
11371137
def applyOverloaded(receiver: Tree, method: TermName, args: List[Tree], targs: List[Type],
11381138
expectedType: Type, isContextual: Boolean = false)(implicit ctx: Context): Tree = {
11391139
val typer = ctx.typer
1140-
val proto = new FunProtoTyped(args, expectedType)(typer, isContextual)
1140+
val proto = FunProtoTyped(args, expectedType)(typer, isContextual)
11411141
val denot = receiver.tpe.member(method)
11421142
assert(denot.exists, i"no member $receiver . $method, members = ${receiver.tpe.decls}")
11431143
val selected =
@@ -1162,7 +1162,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
11621162
val fun = receiver.select(selected).appliedToTypes(targs)
11631163

11641164
val apply = untpd.Apply(fun, args)
1165-
new typer.ApplyToTyped(apply, fun, selected, args, expectedType).result.asInstanceOf[Tree] // needed to handle varargs
1165+
typer.ApplyToTyped(apply, fun, selected, args, expectedType).result.asInstanceOf[Tree] // needed to handle varargs
11661166
}
11671167

11681168
@tailrec
@@ -1221,7 +1221,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
12211221
}
12221222

12231223
/** A key to be used in a context property that tracks enclosing inlined calls */
1224-
private val InlinedCalls = new Property.Key[List[Tree]]
1224+
private val InlinedCalls = Property.Key[List[Tree]]()
12251225

12261226
/** Record an enclosing inlined call.
12271227
* EmptyTree calls (for parameters) cancel the next-enclosing call in the list instead of being added to it.

0 commit comments

Comments
 (0)