Skip to content

Commit

Permalink
Restore AugmentScala2Traits, but limit it to super accessors.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjrd committed Jun 24, 2020
1 parent e650c86 commit 975a4be
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Compiler {
new LiftTry, // Put try expressions that might execute on non-empty stacks into their own methods
new CollectNullableFields, // Collect fields that can be nulled out after use in lazy initialization
new ElimOuterSelect, // Expand outer selections
//new AugmentScala2Traits, // Augments Scala2 traits with additional members needed for mixin composition.
new AugmentScala2Traits, // Augments Scala2 traits so that super accessors are made non-private
new ResolveSuper, // Implement super accessors
new FunctionXXLForwarders, // Add forwarders for FunctionXXL apply method
new ParamForwarding, // Add forwarders for aliases of superclass parameters
Expand Down
25 changes: 5 additions & 20 deletions compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ object AugmentScala2Traits {
val name: String = "augmentScala2Traits"
}

/** This phase augments Scala2 traits with additional members needed for mixin composition.
/** This phase augments Scala2 traits to fix up super accessors.
*
* These symbols would have been added between Unpickling and Mixin in the Scala2 pipeline.
* Strangely, Scala 2 super accessors are pickled as private, but are compiled as public expanded.
* In this phase we expand them and make them non-private, so that `ResolveSuper` does something meaningful.
*
* Specifically, we:
* - Add trait setters for vals defined in traits.
* - Expand the names of all private getters and setters as well as super accessors in the trait and make
* not-private.
* TODO Should we merge this into `ResolveSuper` at this point?

This comment has been minimized.

Copy link
@smarter

smarter Jun 24, 2020

Member

What about doing the private expansion when reading them in Scala2Unpickler?

This comment has been minimized.

Copy link
@sjrd

sjrd Jun 24, 2020

Author Member

That could also work, but I'm not going to touch that before everything else is validated ;)

*/
class AugmentScala2Traits extends MiniPhase with IdentityDenotTransformer { thisPhase =>
import ast.tpd._
Expand All @@ -47,21 +45,8 @@ class AugmentScala2Traits extends MiniPhase with IdentityDenotTransformer { this
}

private def augmentScala2Trait(mixin: ClassSymbol)(implicit ctx: Context): Unit = {
def traitSetter(getter: TermSymbol) =
getter.copy(
name = getter.ensureNotPrivate.name
.expandedName(getter.owner, TraitSetterName)
.asTermName.setterName,
flags = Method | Accessor,
info = MethodType(getter.info.resultType :: Nil, defn.UnitType))

for (sym <- mixin.info.decls) {
if (sym.isGetter && !sym.isOneOf(DeferredOrLazy) && !sym.setter.exists &&
!sym.info.resultType.isInstanceOf[ConstantType])
traitSetter(sym.asTerm).enteredAfter(thisPhase)
if ((sym.isAllOf(PrivateAccessor) && !sym.name.is(ExpandedName) &&
(sym.isGetter || sym.isSetter)) // strangely, Scala 2 fields are also methods that have Accessor set.
|| sym.isSuperAccessor) // scala2 superaccessors are pickled as private, but are compiled as public expanded
if (sym.isSuperAccessor)
sym.ensureNotPrivate.installAfter(thisPhase)
}
mixin.setFlagFrom(thisPhase, Scala2xPartiallyAugmented)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/ResolveSuper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ResolveSuper extends MiniPhase with IdentityDenotTransformer { thisPhase =
override def phaseName: String = ResolveSuper.name

override def runsAfter: Set[String] = Set(ElimByName.name, // verified empirically, need to figure out what the reason is.
//AugmentScala2Traits.name,
AugmentScala2Traits.name,
PruneErasedDefs.name) // Erased decls make `isCurrent` work incorrectly

override def changesMembers: Boolean = true // the phase adds super accessors
Expand Down

0 comments on commit 975a4be

Please sign in to comment.