Skip to content

Commit 446fdb1

Browse files
committed
Merge branch 'master' into topic/scodec-community-build
2 parents 33d1bce + 37eec14 commit 446fdb1

File tree

69 files changed

+530
-299
lines changed

Some content is hidden

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

69 files changed

+530
-299
lines changed

community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ final case class SbtCommunityProject(
106106
case Some(ivyHome) => List(s"-Dsbt.ivy.home=$ivyHome")
107107
case _ => Nil
108108
extraSbtArgs ++ sbtProps ++ List(
109-
"-sbt-version", "1.3.6",
109+
"-sbt-version", "1.3.8",
110110
s"--addPluginSbtFile=$sbtPluginFilePath")
111111

112112
object projects:

compiler/src/dotty/tools/backend/sjs/JUnitBootstrappers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class JUnitBootstrappers extends MiniPhase {
181181
val sym = ctx.newDefaultConstructor(owner).entered
182182
DefDef(sym, {
183183
Block(
184-
Super(This(owner), nme.EMPTY.toTypeName, inConstrCall = true).select(defn.ObjectClass.primaryConstructor).appliedToNone :: Nil,
184+
Super(This(owner), tpnme.EMPTY).select(defn.ObjectClass.primaryConstructor).appliedToNone :: Nil,
185185
unitLiteral
186186
)
187187
})

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,9 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
191191
case arg => arg.typeOpt.widen.isRepeatedParam
192192
}
193193

194-
/** If this tree has type parameters, those. Otherwise Nil.
195-
def typeParameters(tree: Tree): List[TypeDef] = tree match {
196-
case DefDef(_, _, tparams, _, _, _) => tparams
197-
case ClassDef(_, _, tparams, _) => tparams
198-
case TypeDef(_, _, tparams, _) => tparams
199-
case _ => Nil
200-
}*/
194+
/** All type and value parameter symbols of this DefDef */
195+
def allParamSyms(ddef: DefDef)(using Context): List[Symbol] =
196+
(ddef.tparams ::: ddef.vparamss.flatten).map(_.symbol)
201197

202198
/** Does this argument list end with an argument of the form <expr> : _* ? */
203199
def isWildcardStarArgList(trees: List[Tree])(implicit ctx: Context): Boolean =

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package ast
44

55
import core._
66
import Types._, Names._, NameOps._, Flags._, util.Spans._, Contexts._, Constants._
7+
import typer.ProtoTypes
78
import SymDenotations._, Symbols._, Denotations._, StdNames._, Comments._
89
import language.higherKinds
910
import collection.mutable.ListBuffer
@@ -1505,5 +1506,58 @@ object Trees {
15051506
case tree: TypeDef => cpy.TypeDef(tree)(name = newName.asTypeName)
15061507
}
15071508
}.asInstanceOf[tree.ThisTree[T]]
1509+
1510+
/** Delegate to FunProto or FunProtoTyped depending on whether the prefix is `untpd` or `tpd`. */
1511+
protected def FunProto(args: List[Tree], resType: Type)(using Context): ProtoTypes.FunProto
1512+
1513+
/** Construct the application `$receiver.$method[$targs]($args)` using overloading resolution
1514+
* to find a matching overload of `$method` if necessary.
1515+
* This is useful when overloading resolution needs to be performed in a phase after typer.
1516+
* Note that this will not perform any kind of implicit search.
1517+
*
1518+
* @param expectedType An expected type of the application used to guide overloading resolution
1519+
*/
1520+
def applyOverloaded(
1521+
receiver: tpd.Tree, method: TermName, args: List[Tree], targs: List[Type],
1522+
expectedType: Type)(using parentCtx: Context): tpd.Tree = {
1523+
given ctx as Context = parentCtx.retractMode(Mode.ImplicitsEnabled)
1524+
1525+
val typer = ctx.typer
1526+
val proto = FunProto(args, expectedType)
1527+
val denot = receiver.tpe.member(method)
1528+
assert(denot.exists, i"no member $receiver . $method, members = ${receiver.tpe.decls}")
1529+
val selected =
1530+
if (denot.isOverloaded) {
1531+
def typeParamCount(tp: Type) = tp.widen match {
1532+
case tp: PolyType => tp.paramInfos.length
1533+
case _ => 0
1534+
}
1535+
val allAlts = denot.alternatives
1536+
.map(denot => TermRef(receiver.tpe, denot.symbol))
1537+
.filter(tr => typeParamCount(tr) == targs.length)
1538+
.filter { _.widen match {
1539+
case MethodTpe(_, _, x: MethodType) => !x.isImplicitMethod
1540+
case _ => true
1541+
}}
1542+
val alternatives = ctx.typer.resolveOverloaded(allAlts, proto)
1543+
assert(alternatives.size == 1,
1544+
i"${if (alternatives.isEmpty) "no" else "multiple"} overloads available for " +
1545+
i"$method on ${receiver.tpe.widenDealiasKeepAnnots} with targs: $targs%, %; args: $args%, %; expectedType: $expectedType." +
1546+
i"all alternatives: ${allAlts.map(_.symbol.showDcl).mkString(", ")}\n" +
1547+
i"matching alternatives: ${alternatives.map(_.symbol.showDcl).mkString(", ")}.") // this is parsed from bytecode tree. there's nothing user can do about it
1548+
alternatives.head
1549+
}
1550+
else TermRef(receiver.tpe, denot.symbol)
1551+
val fun = receiver.select(selected).appliedToTypes(targs)
1552+
1553+
val apply = untpd.Apply(fun, args)
1554+
typer.ApplyTo(apply, fun, selected, proto, expectedType)
1555+
}
1556+
1557+
1558+
def resolveConstructor(atp: Type, args: List[Tree])(implicit ctx: Context): tpd.Tree = {
1559+
val targs = atp.argTypes
1560+
applyOverloaded(tpd.New(atp.typeConstructor), nme.CONSTRUCTOR, args, targs, atp)
1561+
}
15081562
}
15091563
}

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

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dotc
33
package ast
44

55
import dotty.tools.dotc.transform.{ExplicitOuter, Erasure}
6-
import dotty.tools.dotc.typer.ProtoTypes.FunProtoTyped
6+
import typer.ProtoTypes
77
import transform.SymUtils._
88
import transform.TypeUtils._
99
import core._
@@ -35,11 +35,11 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
3535
def This(cls: ClassSymbol)(implicit ctx: Context): This =
3636
untpd.This(untpd.Ident(cls.name)).withType(cls.thisType)
3737

38-
def Super(qual: Tree, mix: untpd.Ident, inConstrCall: Boolean, mixinClass: Symbol)(implicit ctx: Context): Super =
39-
ta.assignType(untpd.Super(qual, mix), qual, inConstrCall, mixinClass)
38+
def Super(qual: Tree, mix: untpd.Ident, mixinClass: Symbol)(implicit ctx: Context): Super =
39+
ta.assignType(untpd.Super(qual, mix), qual, mixinClass)
4040

41-
def Super(qual: Tree, mixName: TypeName, inConstrCall: Boolean, mixinClass: Symbol = NoSymbol)(implicit ctx: Context): Super =
42-
Super(qual, if (mixName.isEmpty) untpd.EmptyTypeIdent else untpd.Ident(mixName), inConstrCall, mixinClass)
41+
def Super(qual: Tree, mixName: TypeName, mixinClass: Symbol = NoSymbol)(implicit ctx: Context): Super =
42+
Super(qual, if (mixName.isEmpty) untpd.EmptyTypeIdent else untpd.Ident(mixName), mixinClass)
4343

4444
def Apply(fn: Tree, args: List[Tree])(implicit ctx: Context): Apply = {
4545
assert(fn.isInstanceOf[RefTree] || fn.isInstanceOf[GenericApply[_]] || fn.isInstanceOf[Inlined])
@@ -1152,41 +1152,6 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
11521152
}
11531153
}
11541154

1155-
def applyOverloaded(receiver: Tree, method: TermName, args: List[Tree], targs: List[Type],
1156-
expectedType: Type, isContextual: Boolean = false)(implicit ctx: Context): Tree = {
1157-
val typer = ctx.typer
1158-
val proto = FunProtoTyped(args, expectedType)(typer, isContextual)
1159-
val denot = receiver.tpe.member(method)
1160-
assert(denot.exists, i"no member $receiver . $method, members = ${receiver.tpe.decls}")
1161-
val selected =
1162-
if (denot.isOverloaded) {
1163-
def typeParamCount(tp: Type) = tp.widen match {
1164-
case tp: PolyType => tp.paramInfos.length
1165-
case _ => 0
1166-
}
1167-
var allAlts = denot.alternatives
1168-
.map(denot => TermRef(receiver.tpe, denot.symbol))
1169-
.filter(tr => typeParamCount(tr) == targs.length)
1170-
.filter { _.widen match {
1171-
case MethodTpe(_, _, x: MethodType) => !x.isImplicitMethod
1172-
case _ => true
1173-
}}
1174-
if (targs.isEmpty) allAlts = allAlts.filterNot(_.widen.isInstanceOf[PolyType])
1175-
val alternatives = ctx.typer.resolveOverloaded(allAlts, proto)
1176-
assert(alternatives.size == 1,
1177-
i"${if (alternatives.isEmpty) "no" else "multiple"} overloads available for " +
1178-
i"$method on ${receiver.tpe.widenDealiasKeepAnnots} with targs: $targs%, %; args: $args%, % of types ${args.tpes.map(_.widenDealiasKeepAnnots)}%, %; expectedType: $expectedType." +
1179-
i"all alternatives: ${allAlts.map(_.symbol.showDcl).mkString(", ")}\n" +
1180-
i"matching alternatives: ${alternatives.map(_.symbol.showDcl).mkString(", ")}.") // this is parsed from bytecode tree. there's nothing user can do about it
1181-
alternatives.head
1182-
}
1183-
else TermRef(receiver.tpe, denot.symbol)
1184-
val fun = receiver.select(selected).appliedToTypes(targs)
1185-
1186-
val apply = untpd.Apply(fun, args)
1187-
typer.ApplyToTyped(apply, fun, selected, args, expectedType).result.asInstanceOf[Tree] // needed to handle varargs
1188-
}
1189-
11901155
@tailrec
11911156
def sameTypes(trees: List[tpd.Tree], trees1: List[tpd.Tree]): Boolean =
11921157
if (trees.isEmpty) trees.isEmpty
@@ -1361,11 +1326,6 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
13611326
transformer.transform(tree)
13621327
}
13631328

1364-
def resolveConstructor(atp: Type, args:List[Tree])(implicit ctx: Context): Tree = {
1365-
val targs = atp.argTypes
1366-
tpd.applyOverloaded(New(atp.typeConstructor), nme.CONSTRUCTOR, args, targs, atp)
1367-
}
1368-
13691329
/** Convert a list of trees to a vararg-compatible tree.
13701330
* Used to make arguments for methods that accept varargs.
13711331
*/
@@ -1385,4 +1345,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
13851345
ref(defn.ListModule).select(nme.apply)
13861346
.appliedToTypeTree(tpe)
13871347
.appliedToVarargs(trees, tpe)
1348+
1349+
1350+
protected def FunProto(args: List[Tree], resType: Type)(using ctx: Context) =
1351+
ProtoTypes.FunProtoTyped(args, resType)(ctx.typer, isUsingApply = false)
13881352
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package ast
44

55
import core._
66
import Types._, Contexts._, Constants._, Names._, Flags._
7+
import dotty.tools.dotc.typer.ProtoTypes
78
import Symbols._, StdNames._, Trees._
89
import util.{Property, SourceFile, NoSource}
910
import util.Spans.Span
@@ -756,4 +757,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
756757
}
757758
acc(false, tree)
758759
}
760+
761+
protected def FunProto(args: List[Tree], resType: Type)(using ctx: Context) =
762+
ProtoTypes.FunProto(args, resType)(ctx.typer, isUsingApply = false)
759763
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ object Annotations {
142142
def deferred(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation =
143143
deferred(atp.classSymbol)(New(atp, args))
144144

145-
def deferredResolve(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation =
146-
deferred(atp.classSymbol)(resolveConstructor(atp, args))
145+
def deferredResolve(atp: Type, args: List[ast.untpd.Tree])(implicit ctx: Context): Annotation =
146+
deferred(atp.classSymbol)(ast.untpd.resolveConstructor(atp, args))
147147

148148
/** Extractor for child annotations */
149149
object Child {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ object Contexts {
353353
* - as owner: The primary constructor of the class
354354
* - as outer context: The context enclosing the class context
355355
* - as scope: The parameter accessors in the class context
356-
* - with additional mode: InSuperCall
357356
*
358357
* The reasons for this peculiar choice of attributes are as follows:
359358
*
@@ -394,7 +393,7 @@ object Contexts {
394393
var classCtx = outersIterator.dropWhile(!_.isClassDefContext).next()
395394
classCtx.outer.fresh.setOwner(owner)
396395
.setScope(locals)
397-
.setMode(classCtx.mode | Mode.InSuperCall)
396+
.setMode(classCtx.mode)
398397
}
399398

400399
/** The context of expression `expr` seen as a member of a statement sequence */

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ object Flags {
519519
val AbstractSealed: FlagSet = Abstract | Sealed
520520
val AbstractOrTrait: FlagSet = Abstract | Trait
521521
val EffectivelyOpenFlags = Abstract | JavaDefined | Open | Scala2x | Trait
522+
val AccessorOrDeferred: FlagSet = Accessor | Deferred
522523
val PrivateAccessor: FlagSet = Accessor | Private
523524
val AccessorOrSynthetic: FlagSet = Accessor | Synthetic
524525
val EnumCase: FlagSet = Case | Enum

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ object Mode {
4343

4444
val CheckCyclic: Mode = newMode(5, "CheckCyclic")
4545

46-
/** We are looking at the arguments of a supercall */
47-
val InSuperCall: Mode = newMode(6, "InSuperCall")
48-
4946
/** We are in a pattern alternative */
5047
val InPatternAlternative: Mode = newMode(7, "InPatternAlternative")
5148

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ object NameKinds {
353353
val ProtectedAccessorName: PrefixNameKind = new PrefixNameKind(PROTECTEDACCESSOR, "protected$")
354354
val InlineAccessorName: PrefixNameKind = new PrefixNameKind(INLINEACCESSOR, "inline$")
355355

356-
val AvoidClashName: SuffixNameKind = new SuffixNameKind(AVOIDCLASH, "$_avoid_name_clash_$")
356+
val BodyRetainerName: SuffixNameKind = new SuffixNameKind(BODYRETAINER, "$retainedBody")
357357
val FieldName: SuffixNameKind = new SuffixNameKind(FIELD, "$$local") {
358358
override def mkString(underlying: TermName, info: ThisInfo) = underlying.toString
359359
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ object NameOps {
128128
/** If flags is a ModuleClass but not a Package, add module class suffix */
129129
def adjustIfModuleClass(flags: FlagSet): N = likeSpacedN {
130130
if (flags.is(ModuleClass, butNot = Package)) name.asTypeName.moduleClassName
131-
else name.toTermName.exclude(AvoidClashName)
131+
else name.toTermName
132132
}
133133

134134
/** The expanded name.

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ object NameTags extends TastyFormat.NameTags {
1717

1818
final val INITIALIZER = 26 // A mixin initializer method
1919

20-
final val AVOIDCLASH = 27 // Adds a suffix to avoid a name clash;
21-
// Used in FirstTransform for synthesized companion objects of classes
22-
// if they would clash with another value.
23-
24-
final val DIRECT = 28 // Used by ShortCutImplicits for the name of methods that
25-
// implement implicit function result types directly.
26-
2720
final val FIELD = 29 // Used by Memoize to tag the name of a class member field.
2821

2922
final val EXTMETH = 30 // Used by ExtensionMethods for the name of an extension method
@@ -51,8 +44,6 @@ object NameTags extends TastyFormat.NameTags {
5144
case INLINEACCESSOR => "INLINEACCESSOR"
5245
case PROTECTEDACCESSOR => "PROTECTEDACCESSOR"
5346
case INITIALIZER => "INITIALIZER"
54-
case AVOIDCLASH => "AVOIDCLASH"
55-
case DIRECT => "DIRECT"
5647
case FIELD => "FIELD"
5748
case EXTMETH => "EXTMETH"
5849
case IMPLMETH => "IMPLMETH"

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ object SymDenotations {
282282
*/
283283
def effectiveName(implicit ctx: Context): Name =
284284
if (this.is(ModuleClass)) name.stripModuleClassSuffix
285-
else name.exclude(AvoidClashName)
285+
else name
286286

287287
/** The privateWithin boundary, NoSymbol if no boundary is given.
288288
*/
@@ -940,13 +940,17 @@ object SymDenotations {
940940
def isInlineMethod(implicit ctx: Context): Boolean =
941941
isAllOf(InlineMethod, butNot = Accessor)
942942

943+
def isRetainedInlineMethod(using Context): Boolean =
944+
isAllOf(InlineMethod, butNot = AccessorOrDeferred)
945+
&& allOverriddenSymbols.exists(!_.is(Inline))
946+
943947
/** Is this a Scala 2 macro */
944948
final def isScala2Macro(implicit ctx: Context): Boolean = is(Macro) && symbol.owner.is(Scala2x)
945949

946950
/** An erased value or an inline method.
947951
*/
948952
def isEffectivelyErased(implicit ctx: Context): Boolean =
949-
is(Erased) || isInlineMethod
953+
is(Erased) || isInlineMethod && !isRetainedInlineMethod
950954

951955
/** ()T and => T types should be treated as equivalent for this symbol.
952956
* Note: For the moment, we treat Scala-2 compiled symbols as loose matching,

0 commit comments

Comments
 (0)