Skip to content

Commit 2fa4b0f

Browse files
authored
Merge branch 'lampepfl:main' into fix-global
2 parents 168565f + 492f777 commit 2fa4b0f

File tree

189 files changed

+3056
-1185
lines changed

Some content is hidden

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

189 files changed

+3056
-1185
lines changed

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

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -667,18 +667,20 @@ object desugar {
667667
DefDef(name, Nil, tpt, rhs).withMods(synthetic)
668668

669669
def productElemMeths =
670-
val caseParams = derivedVparamss.head.toArray
671-
val selectorNamesInBody = normalizedBody.collect {
672-
case vdef: ValDef if vdef.name.isSelectorName =>
673-
vdef.name
674-
case ddef: DefDef if ddef.name.isSelectorName && ddef.paramss.isEmpty =>
675-
ddef.name
676-
}
677-
for i <- List.range(0, arity)
678-
selName = nme.selectorName(i)
679-
if (selName ne caseParams(i).name) && !selectorNamesInBody.contains(selName)
680-
yield syntheticProperty(selName, caseParams(i).tpt,
681-
Select(This(EmptyTypeIdent), caseParams(i).name))
670+
if caseClassInScala2StdLib then Nil
671+
else
672+
val caseParams = derivedVparamss.head.toArray
673+
val selectorNamesInBody = normalizedBody.collect {
674+
case vdef: ValDef if vdef.name.isSelectorName =>
675+
vdef.name
676+
case ddef: DefDef if ddef.name.isSelectorName && ddef.paramss.isEmpty =>
677+
ddef.name
678+
}
679+
for i <- List.range(0, arity)
680+
selName = nme.selectorName(i)
681+
if (selName ne caseParams(i).name) && !selectorNamesInBody.contains(selName)
682+
yield syntheticProperty(selName, caseParams(i).tpt,
683+
Select(This(EmptyTypeIdent), caseParams(i).name))
682684

683685
def enumCaseMeths =
684686
if isEnumCase then
@@ -768,11 +770,13 @@ object desugar {
768770
val unapplyMeth = {
769771
def scala2LibCompatUnapplyRhs(unapplyParamName: Name) =
770772
assert(arity <= Definitions.MaxTupleArity, "Unexpected case class with tuple larger than 22: "+ cdef.show)
771-
if arity == 1 then Apply(scalaDot(nme.Option), Select(Ident(unapplyParamName), nme._1))
772-
else
773-
val tupleApply = Select(Ident(nme.scala), s"Tuple$arity".toTermName)
774-
val members = List.tabulate(arity) { n => Select(Ident(unapplyParamName), s"_${n+1}".toTermName) }
775-
Apply(scalaDot(nme.Option), Apply(tupleApply, members))
773+
derivedVparamss.head match
774+
case vparam :: Nil =>
775+
Apply(scalaDot(nme.Option), Select(Ident(unapplyParamName), vparam.name))
776+
case vparams =>
777+
val tupleApply = Select(Ident(nme.scala), s"Tuple$arity".toTermName)
778+
val members = vparams.map(vparam => Select(Ident(unapplyParamName), vparam.name))
779+
Apply(scalaDot(nme.Option), Apply(tupleApply, members))
776780

777781
val hasRepeatedParam = constrVparamss.head.exists {
778782
case ValDef(_, tpt, _) => isRepeated(tpt)
@@ -1010,7 +1014,7 @@ object desugar {
10101014
* if the type has a pattern variable name
10111015
*/
10121016
def quotedPatternTypeDef(tree: TypeDef)(using Context): TypeDef = {
1013-
assert(ctx.mode.is(Mode.QuotedPattern))
1017+
assert(ctx.mode.isQuotedPattern)
10141018
if tree.name.isVarPattern && !tree.isBackquoted then
10151019
val patternTypeAnnot = New(ref(defn.QuotedRuntimePatterns_patternTypeAnnot.typeRef)).withSpan(tree.span)
10161020
val mods = tree.mods.withAddedAnnotation(patternTypeAnnot)
@@ -1359,7 +1363,7 @@ object desugar {
13591363
case tree: ValDef => valDef(tree)
13601364
case tree: TypeDef =>
13611365
if (tree.isClassDef) classDef(tree)
1362-
else if (ctx.mode.is(Mode.QuotedPattern)) quotedPatternTypeDef(tree)
1366+
else if (ctx.mode.isQuotedPattern) quotedPatternTypeDef(tree)
13631367
else tree
13641368
case tree: DefDef =>
13651369
if (tree.name.isConstructorName) tree // was already handled by enclosing classDef

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,8 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
954954
def isStructuralTermSelectOrApply(tree: Tree)(using Context): Boolean = {
955955
def isStructuralTermSelect(tree: Select) =
956956
def hasRefinement(qualtpe: Type): Boolean = qualtpe.dealias match
957+
case defn.PolyOrErasedFunctionOf(_) =>
958+
false
957959
case RefinedType(parent, rname, rinfo) =>
958960
rname == tree.name || hasRefinement(parent)
959961
case tp: TypeProxy =>
@@ -966,10 +968,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
966968
false
967969
!tree.symbol.exists
968970
&& tree.isTerm
969-
&& {
970-
val qualType = tree.qualifier.tpe
971-
hasRefinement(qualType) && !defn.isRefinedFunctionType(qualType)
972-
}
971+
&& hasRefinement(tree.qualifier.tpe)
973972
def loop(tree: Tree): Boolean = tree match
974973
case TypeApply(fun, _) =>
975974
loop(fun)

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,9 @@ object Trees {
673673
*/
674674
case class Inlined[+T <: Untyped] private[ast] (call: tpd.Tree, bindings: List[MemberDef[T]], expansion: Tree[T])(implicit @constructorOnly src: SourceFile)
675675
extends Tree[T] {
676+
677+
def inlinedFromOuterScope: Boolean = call.isEmpty
678+
676679
type ThisTree[+T <: Untyped] = Inlined[T]
677680
override def isTerm = expansion.isTerm
678681
override def isType = expansion.isType
@@ -774,7 +777,7 @@ object Trees {
774777
}
775778

776779
/** Tree that replaces a level 1 splices in pickled (level 0) quotes.
777-
* It is only used when picking quotes (will never be in a TASTy file).
780+
* It is only used when pickling quotes (will never be in a TASTy file).
778781
*
779782
* @param isTerm If this hole is a term, otherwise it is a type hole.
780783
* @param idx The index of the hole in it's enclosing level 0 quote.
@@ -1479,7 +1482,7 @@ object Trees {
14791482
* innermost enclosing call for which the inlined version is currently
14801483
* processed.
14811484
*/
1482-
protected def inlineContext(call: tpd.Tree)(using Context): Context = ctx
1485+
protected def inlineContext(tree: Inlined)(using Context): Context = ctx
14831486

14841487
/** The context to use when mapping or accumulating over a tree */
14851488
def localCtx(tree: Tree)(using Context): Context
@@ -1549,8 +1552,8 @@ object Trees {
15491552
cpy.Try(tree)(transform(block), transformSub(cases), transform(finalizer))
15501553
case SeqLiteral(elems, elemtpt) =>
15511554
cpy.SeqLiteral(tree)(transform(elems), transform(elemtpt))
1552-
case Inlined(call, bindings, expansion) =>
1553-
cpy.Inlined(tree)(call, transformSub(bindings), transform(expansion)(using inlineContext(call)))
1555+
case tree @ Inlined(call, bindings, expansion) =>
1556+
cpy.Inlined(tree)(call, transformSub(bindings), transform(expansion)(using inlineContext(tree)))
15541557
case TypeTree() =>
15551558
tree
15561559
case SingletonTypeTree(ref) =>
@@ -1693,8 +1696,8 @@ object Trees {
16931696
this(this(this(x, block), handler), finalizer)
16941697
case SeqLiteral(elems, elemtpt) =>
16951698
this(this(x, elems), elemtpt)
1696-
case Inlined(call, bindings, expansion) =>
1697-
this(this(x, bindings), expansion)(using inlineContext(call))
1699+
case tree @ Inlined(call, bindings, expansion) =>
1700+
this(this(x, bindings), expansion)(using inlineContext(tree))
16981701
case TypeTree() =>
16991702
x
17001703
case SingletonTypeTree(ref) =>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,17 +1392,17 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
13921392
* EmptyTree calls (for parameters) cancel the next-enclosing call in the list instead of being added to it.
13931393
* We assume parameters are never nested inside parameters.
13941394
*/
1395-
override def inlineContext(call: Tree)(using Context): Context = {
1395+
override def inlineContext(tree: Inlined)(using Context): Context = {
13961396
// We assume enclosingInlineds is already normalized, and only process the new call with the head.
13971397
val oldIC = enclosingInlineds
13981398

13991399
val newIC =
1400-
if call.isEmpty then
1400+
if tree.inlinedFromOuterScope then
14011401
oldIC match
14021402
case t1 :: ts2 => ts2
14031403
case _ => oldIC
14041404
else
1405-
call :: oldIC
1405+
tree.call :: oldIC
14061406

14071407
val ctx1 = ctx.fresh.setProperty(InlinedCalls, newIC)
14081408
if oldIC.isEmpty then ctx1.setProperty(InlinedTrees, new Counter) else ctx1

compiler/src/dotty/tools/dotc/cc/CaptureSet.scala

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,11 @@ sealed abstract class CaptureSet extends Showable:
210210
* any of the elements in the constant capture set `that`
211211
*/
212212
def -- (that: CaptureSet.Const)(using Context): CaptureSet =
213-
val elems1 = elems.filter(!that.accountsFor(_))
214-
if elems1.size == elems.size then this
215-
else if this.isConst then Const(elems1)
216-
else Diff(asVar, that)
213+
if this.isConst then
214+
val elems1 = elems.filter(!that.accountsFor(_))
215+
if elems1.size == elems.size then this else Const(elems1)
216+
else
217+
if that.isAlwaysEmpty then this else Diff(asVar, that)
217218

218219
/** The largest subset (via <:<) of this capture set that does not account for `ref` */
219220
def - (ref: CaptureRef)(using Context): CaptureSet =
@@ -845,34 +846,45 @@ object CaptureSet:
845846
/** The capture set of the type underlying a CaptureRef */
846847
def ofInfo(ref: CaptureRef)(using Context): CaptureSet = ref match
847848
case ref: TermRef if ref.isRootCapability => ref.singletonCaptureSet
848-
case _ => ofType(ref.underlying)
849+
case _ => ofType(ref.underlying, followResult = true)
849850

850851
/** Capture set of a type */
851-
def ofType(tp: Type)(using Context): CaptureSet =
852-
def recur(tp: Type): CaptureSet = tp.dealias match
853-
case tp: TermRef =>
854-
tp.captureSet
855-
case tp: TermParamRef =>
856-
tp.captureSet
857-
case _: TypeRef =>
858-
if tp.classSymbol.hasAnnotation(defn.CapabilityAnnot) then universal else empty
859-
case _: TypeParamRef =>
860-
empty
861-
case CapturingType(parent, refs) =>
862-
recur(parent) ++ refs
863-
case AppliedType(tycon, args) =>
864-
val cs = recur(tycon)
865-
tycon.typeParams match
866-
case tparams @ (LambdaParam(tl, _) :: _) => cs.substParams(tl, args)
867-
case _ => cs
868-
case tp: TypeProxy =>
869-
recur(tp.underlying)
870-
case AndType(tp1, tp2) =>
871-
recur(tp1) ** recur(tp2)
872-
case OrType(tp1, tp2) =>
873-
recur(tp1) ++ recur(tp2)
874-
case _ =>
875-
empty
852+
def ofType(tp: Type, followResult: Boolean)(using Context): CaptureSet =
853+
def recur(tp: Type): CaptureSet = trace(i"ofType $tp, ${tp.getClass} $followResult", show = true):
854+
tp.dealias match
855+
case tp: TermRef =>
856+
tp.captureSet
857+
case tp: TermParamRef =>
858+
tp.captureSet
859+
case _: TypeRef =>
860+
if tp.classSymbol.hasAnnotation(defn.CapabilityAnnot) then universal else empty
861+
case _: TypeParamRef =>
862+
empty
863+
case CapturingType(parent, refs) =>
864+
recur(parent) ++ refs
865+
case tpd @ RefinedType(parent, _, rinfo: MethodType)
866+
if followResult && defn.isFunctionType(tpd) =>
867+
ofType(parent, followResult = false) // pick up capture set from parent type
868+
++ (recur(rinfo.resType) // add capture set of result
869+
-- CaptureSet(rinfo.paramRefs.filter(_.isTracked)*)) // but disregard bound parameters
870+
case tpd @ AppliedType(tycon, args) =>
871+
if followResult && defn.isNonRefinedFunction(tpd) then
872+
recur(args.last)
873+
// must be (pure) FunctionN type since ImpureFunctions have already
874+
// been eliminated in selector's dealias. Use capture set of result.
875+
else
876+
val cs = recur(tycon)
877+
tycon.typeParams match
878+
case tparams @ (LambdaParam(tl, _) :: _) => cs.substParams(tl, args)
879+
case _ => cs
880+
case tp: TypeProxy =>
881+
recur(tp.underlying)
882+
case AndType(tp1, tp2) =>
883+
recur(tp1) ** recur(tp2)
884+
case OrType(tp1, tp2) =>
885+
recur(tp1) ++ recur(tp2)
886+
case _ =>
887+
empty
876888
recur(tp)
877889
.showing(i"capture set of $tp = $result", capt)
878890

0 commit comments

Comments
 (0)