Skip to content

Commit c5a3b5c

Browse files
authored
Merge pull request #8428 from dotty-staging/fix-#7926
Fix #7926: Redo parameter aliasing optimization
2 parents 5c6098f + a924104 commit c5a3b5c

29 files changed

+215
-123
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class Compiler {
9090
new AugmentScala2Traits, // Augments Scala2 traits with additional members needed for mixin composition.
9191
new ResolveSuper, // Implement super accessors
9292
new FunctionXXLForwarders, // Add forwarders for FunctionXXL apply method
93+
new ParamForwarding, // Add forwarders for aliases of superclass parameters
9394
new TupleOptimizations, // Optimize generic operations on tuples
9495
new ArrayConstructors) :: // Intercept creation of (non-generic) arrays and intrinsify.
9596
List(new Erasure) :: // Rewrite types to JVM model, erasing all type parameters, abstract types and refinements.

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,6 @@ object Annotations {
145145
def deferredResolve(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation =
146146
deferred(atp.classSymbol)(resolveConstructor(atp, args))
147147

148-
def makeAlias(sym: TermSymbol)(implicit ctx: Context): Annotation =
149-
apply(defn.AliasAnnot, List(
150-
ref(TermRef(sym.owner.thisType, sym.name, sym))))
151-
152148
/** Extractor for child annotations */
153149
object Child {
154150

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,6 @@ class Definitions {
780780
@tu lazy val RefiningAnnotationClass: ClassSymbol = ctx.requiredClass("scala.annotation.RefiningAnnotation")
781781

782782
// Annotation classes
783-
@tu lazy val AliasAnnot: ClassSymbol = ctx.requiredClass("scala.annotation.internal.Alias")
784783
@tu lazy val AnnotationDefaultAnnot: ClassSymbol = ctx.requiredClass("scala.annotation.internal.AnnotationDefault")
785784
@tu lazy val BodyAnnot: ClassSymbol = ctx.requiredClass("scala.annotation.internal.Body")
786785
@tu lazy val ChildAnnot: ClassSymbol = ctx.requiredClass("scala.annotation.internal.Child")

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ object Flags {
296296
val (_, CaseAccessor @ _, _) = newFlags(25, "<caseaccessor>")
297297

298298
/** A Scala 2x super accessor / an unpickled Scala 2.x class */
299-
val (SuperAccessorOrScala2x @ _, Scala2SuperAccessor @ _, Scala2x @ _) = newFlags(26, "<superaccessor>", "<scala-2.x>")
299+
val (SuperParamAliasOrScala2x @ _, SuperParamAlias @ _, Scala2x @ _) = newFlags(26, "<super-param-alias>", "<scala-2.x>")
300300

301301
/** A method that has default params */
302302
val (_, DefaultParameterized @ _, _) = newFlags(27, "<defaultparam>")
@@ -371,8 +371,9 @@ object Flags {
371371
/** Symbol is a self name */
372372
val (_, SelfName @ _, _) = newFlags(54, "<selfname>")
373373

374-
/** An existentially bound symbol (Scala 2.x only) */
375-
val (Scala2ExistentialCommon @ _, _, Scala2Existential @ _) = newFlags(55, "<existential>")
374+
/** A Scala 2 superaccessor (only needed during Scala2Unpickling) /
375+
* an existentially bound symbol (Scala 2.x only) */
376+
val (Scala2SpecialFlags @ _, Scala2SuperAccessor @ _, Scala2Existential @ _) = newFlags(55, "<existential>")
376377

377378
/** Children were queried on this class */
378379
val (_, _, ChildrenQueried @ _) = newFlags(56, "<children-queried>")
@@ -439,10 +440,10 @@ object Flags {
439440
val FromStartFlags: FlagSet = commonFlags(
440441
Module, Package, Deferred, Method, Case,
441442
HigherKinded, Param, ParamAccessor,
442-
Scala2ExistentialCommon, MutableOrOpen, Opaque, Touched, JavaStatic,
443+
Scala2SpecialFlags, MutableOrOpen, Opaque, Touched, JavaStatic,
443444
OuterOrCovariant, LabelOrContravariant, CaseAccessor,
444445
Extension, NonMember, Implicit, Given, Permanent, Synthetic,
445-
SuperAccessorOrScala2x, Inline, Macro)
446+
SuperParamAliasOrScala2x, Inline, Macro)
446447

447448
/** Flags that are not (re)set when completing the denotation, or, if symbol is
448449
* a top-level class or object, when completing the denotation once the class
@@ -551,6 +552,7 @@ object Flags {
551552
val JavaProtected: FlagSet = JavaDefined | Protected
552553
val MethodOrLazy: FlagSet = Lazy | Method
553554
val MutableOrLazy: FlagSet = Lazy | Mutable
555+
val MethodOrLazyOrMutable: FlagSet = Lazy | Method | Mutable
554556
val LiftedMethod: FlagSet = Lifted | Method
555557
val LocalParam: FlagSet = Local | Param
556558
val LocalParamAccessor: FlagSet = Local | ParamAccessor | Private
@@ -561,7 +563,7 @@ object Flags {
561563
val PrivateMethod: FlagSet = Method | Private
562564
val NoInitsInterface: FlagSet = NoInits | PureInterface
563565
val NoInitsTrait: FlagSet = NoInits | Trait // A trait that does not need to be initialized
564-
val ValidForeverFlags: FlagSet = Package | Permanent | Scala2ExistentialCommon
566+
val ValidForeverFlags: FlagSet = Package | Permanent | Scala2SpecialFlags
565567
val TermParamOrAccessor: FlagSet = Param | ParamAccessor
566568
val PrivateParamAccessor: FlagSet = ParamAccessor | Private
567569
val PrivateOrSynthetic: FlagSet = Private | Synthetic

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

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

356356
val AvoidClashName: SuffixNameKind = new SuffixNameKind(AVOIDCLASH, "$_avoid_name_clash_$")
357-
val CacheName = new SuffixNameKind(CACHE, "$_cache")
358357
val DirectMethodName: SuffixNameKind = new SuffixNameKind(DIRECT, "$direct") { override def definesNewName = true }
359358
val FieldName: SuffixNameKind = new SuffixNameKind(FIELD, "$$local") {
360359
override def mkString(underlying: TermName, info: ThisInfo) = underlying.toString
361360
}
362361
val ExtMethName: SuffixNameKind = new SuffixNameKind(EXTMETH, "$extension")
362+
val ParamAccessorName: SuffixNameKind = new SuffixNameKind(PARAMACC, "$accessor")
363363
val ModuleClassName: SuffixNameKind = new SuffixNameKind(OBJECTCLASS, "$", optInfoString = "ModuleClass")
364364
val ImplMethName: SuffixNameKind = new SuffixNameKind(IMPLMETH, "$")
365365
val AdaptedClosureName: SuffixNameKind = new SuffixNameKind(ADAPTEDCLOSURE, "$adapted") { override def definesNewName = true }

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ object NameTags extends TastyFormat.NameTags {
3434
final val IMPLMETH = 32 // Used to define methods in implementation classes
3535
// (can probably be removed).
3636

37-
final val CACHE = 33 // Used as a cache for the rhs of an alias implicit.
37+
final val PARAMACC = 33 // Used for a private parameter alias
3838

3939
def nameTagToString(tag: Int): String = tag match {
4040
case UTF8 => "UTF8"
@@ -55,6 +55,8 @@ object NameTags extends TastyFormat.NameTags {
5555
case DIRECT => "DIRECT"
5656
case FIELD => "FIELD"
5757
case EXTMETH => "EXTMETH"
58+
case IMPLMETH => "IMPLMETH"
59+
case PARAMACC => "PARAMACC"
5860
case ADAPTEDCLOSURE => "ADAPTEDCLOSURE"
5961
case OBJECTCLASS => "OBJECTCLASS"
6062

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,11 @@ object SymDenotations {
14851485
override def transformAfter(phase: DenotTransformer, f: SymDenotation => SymDenotation)(implicit ctx: Context): Unit =
14861486
super.transformAfter(phase, f)
14871487

1488+
/** Set flag `flags` in current phase and in all phases that follow */
1489+
def setFlagFrom(phase: DenotTransformer, flags: FlagSet)(using Context): Unit =
1490+
setFlag(flags)
1491+
transformAfter(phase, sd => { sd.setFlag(flags); sd })
1492+
14881493
/** If denotation is private, remove the Private flag and expand the name if necessary */
14891494
def ensureNotPrivate(implicit ctx: Context): SymDenotation =
14901495
if (is(Private))

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ class TreePickler(pickler: TastyPickler) {
682682
if (flags.is(StableRealizable)) writeModTag(STABLE)
683683
if (flags.is(Extension)) writeModTag(EXTENSION)
684684
if (flags.is(ParamAccessor)) writeModTag(PARAMsetter)
685+
if (flags.is(SuperParamAlias)) writeModTag(PARAMalias)
685686
if (flags.is(Exported)) writeModTag(EXPORTED)
686687
assert(!(flags.is(Label)))
687688
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ class TreeUnpickler(reader: TastyReader,
644644
case EXTENSION => addFlag(Extension)
645645
case GIVEN => addFlag(Given)
646646
case PARAMsetter => addFlag(ParamAccessor)
647+
case PARAMalias => addFlag(SuperParamAlias)
647648
case EXPORTED => addFlag(Exported)
648649
case OPEN => addFlag(Open)
649650
case PRIVATEqualified =>

0 commit comments

Comments
 (0)