From ea96ecda77ab99969a65b66173260e66b199be74 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 27 Mar 2017 18:55:50 +0200 Subject: Get rid of SuperAccessor flag --- compiler/src/dotty/tools/dotc/core/Flags.scala | 4 ++-- compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala | 4 +--- .../dotty/tools/dotc/core/unpickleScala2/PickleBuffer.scala | 2 +- .../dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala | 10 +++++++--- compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala | 3 ++- .../src/dotty/tools/dotc/transform/AugmentScala2Traits.scala | 2 +- compiler/src/dotty/tools/dotc/transform/ExpandSAMs.scala | 2 +- compiler/src/dotty/tools/dotc/transform/ResolveSuper.scala | 4 ++-- compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala | 2 +- compiler/src/dotty/tools/dotc/transform/SymUtils.scala | 2 ++ compiler/src/dotty/tools/dotc/transform/ValueClasses.scala | 3 ++- compiler/src/dotty/tools/dotc/typer/RefChecks.scala | 2 +- 12 files changed, 23 insertions(+), 17 deletions(-) (limited to 'compiler/src') diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index 8a1e14c63..ef3261719 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -311,12 +311,12 @@ object Flags { final val CaseAccessorOrBaseTypeArg = CaseAccessor.toCommonFlags /** A super accessor */ - final val SuperAccessor = termFlag(26, "") + final val Scala2SuperAccessor = termFlag(26, "") /** An unpickled Scala 2.x class */ final val Scala2x = typeFlag(26, "") - final val SuperAccessorOrScala2x = SuperAccessor.toCommonFlags + final val SuperAccessorOrScala2x = Scala2x.toCommonFlags /** A method that has default params */ final val DefaultParameterized = termFlag(27, "") diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index d8497f39d..8a9b68093 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -427,10 +427,8 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi val rhsIsEmpty = noRhs(end) if (!rhsIsEmpty) skipTree() val (givenFlags, annots, privateWithin) = readModifiers(end) - val nameFlags = - (if (name.is(NameExtractors.SuperAccessorName)) SuperAccessor else EmptyFlags) pickling.println(i"creating symbol $name at $start with flags $givenFlags") - val flags = normalizeFlags(tag, givenFlags | nameFlags, name, isAbsType, rhsIsEmpty) + val flags = normalizeFlags(tag, givenFlags, name, isAbsType, rhsIsEmpty) def adjustIfModule(completer: LazyType) = if (flags is Module) ctx.adjustModuleCompleter(completer, name) else completer val sym = diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/PickleBuffer.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/PickleBuffer.scala index 773c6760e..2a789dca9 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/PickleBuffer.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/PickleBuffer.scala @@ -224,7 +224,7 @@ object PickleBuffer { DEFAULTPARAM -> (DefaultParameterized, Trait), BRIDGE -> Bridge, ACCESSOR -> Accessor, - SUPERACCESSOR -> SuperAccessor, + SUPERACCESSOR -> Scala2SuperAccessor, PARAMACCESSOR -> ParamAccessor, MODULEVAR -> Scala2ModuleVar, LAZY -> Lazy, diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index aed0e97f1..976eb5df4 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -18,6 +18,7 @@ import printing.Printer import io.AbstractFile import util.common._ import typer.Checking.checkNonCyclic +import transform.SymUtils._ import PickleBuffer._ import PickleFormat._ import Decorators._ @@ -441,7 +442,10 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas name = name.unmangleExpandedName flags = flags &~ Scala2ExpandedName } - if (flags is SuperAccessor) name = name.asTermName.unmangleSuperName + if (flags is Scala2SuperAccessor) { + name = name.asTermName.unmangleSuperName + flags = flags &~ Scala2SuperAccessor + } def isClassRoot = (name == classRoot.name) && (owner == classRoot.owner) && !(flags is ModuleClass) def isModuleClassRoot = (name == moduleClassRoot.name) && (owner == moduleClassRoot.owner) && (flags is Module) @@ -555,9 +559,9 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas else tp1 if (denot.isConstructor) addConstructorTypeParams(denot) if (atEnd) { - assert(!(denot is SuperAccessor), denot) + assert(!denot.isSuperAccessor, denot) } else { - assert(denot is (SuperAccessor | ParamAccessor), denot) + assert(denot.is(ParamAccessor) || denot.isSuperAccessor, denot) def disambiguate(alt: Symbol) = { // !!! DEBUG ctx.debugTraceIndented(s"disambiguating ${denot.info} =:= ${denot.owner.thisType.memberInfo(alt)} ${denot.owner}") { denot.info matches denot.owner.thisType.memberInfo(alt) diff --git a/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala b/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala index 8d704f9a2..324aecdf0 100644 --- a/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala +++ b/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala @@ -7,6 +7,7 @@ import Annotations._, Contexts._, Flags._, Phases._, Trees._, Types._, Symbols._ import Names._, NameOps._, StdNames._ import typer.Inliner import typer.ErrorReporting.cyclicErrorMsg +import transform.SymUtils._ import dotty.tools.io.Path import java.io.PrintWriter @@ -539,7 +540,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder val abs = sym.is(Abstract) || sym.is(Deferred) || absOver val over = sym.is(Override) || absOver new api.Modifiers(abs, over, sym.is(Final), sym.is(Sealed), - sym.is(Implicit), sym.is(Lazy), sym.is(Macro), sym.is(SuperAccessor)) + sym.is(Implicit), sym.is(Lazy), sym.is(Macro), sym.isSuperAccessor) } def apiAnnotations(s: Symbol): List[api.Annotation] = { diff --git a/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala b/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala index 594d85bfa..fa79d995c 100644 --- a/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala +++ b/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala @@ -92,7 +92,7 @@ class AugmentScala2Traits extends MiniPhaseTransform with IdentityDenotTransform traitSetter(sym.asTerm).enteredAfter(thisTransform) if ((sym.is(PrivateAccessor) && !sym.name.is(ExpandedName) && (sym.isGetter || sym.isSetter)) // strangely, Scala 2 fields are also methods that have Accessor set. - || sym.is(SuperAccessor)) // scala2 superaccessors are pickled as private, but are compiled as public expanded + || sym.isSuperAccessor) // scala2 superaccessors are pickled as private, but are compiled as public expanded sym.ensureNotPrivate.installAfter(thisTransform) } ctx.log(i"Scala2x trait decls of $mixin = ${mixin.info.decls.toList.map(_.showDcl)}%\n %") diff --git a/compiler/src/dotty/tools/dotc/transform/ExpandSAMs.scala b/compiler/src/dotty/tools/dotc/transform/ExpandSAMs.scala index 7b15b7e54..f63cba3f1 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExpandSAMs.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExpandSAMs.scala @@ -38,7 +38,7 @@ class ExpandSAMs extends MiniPhaseTransform { thisTransformer => case tpe @ SAMType(_) if isPlatformSam(tpe.classSymbol.asClass) => tree case tpe => - val Seq(samDenot) = tpe.abstractTermMembers.filter(!_.symbol.is(SuperAccessor)) + val Seq(samDenot) = tpe.abstractTermMembers.filter(!_.symbol.isSuperAccessor) cpy.Block(tree)(stats, AnonClass(tpe :: Nil, fn.symbol.asTerm :: Nil, samDenot.symbol.asTerm.name :: Nil)) } diff --git a/compiler/src/dotty/tools/dotc/transform/ResolveSuper.scala b/compiler/src/dotty/tools/dotc/transform/ResolveSuper.scala index 9e22a6b46..1df10cac2 100644 --- a/compiler/src/dotty/tools/dotc/transform/ResolveSuper.scala +++ b/compiler/src/dotty/tools/dotc/transform/ResolveSuper.scala @@ -60,7 +60,7 @@ class ResolveSuper extends MiniPhaseTransform with IdentityDenotTransformer { th import ops._ def superAccessors(mixin: ClassSymbol): List[Tree] = - for (superAcc <- mixin.info.decls.filter(_ is SuperAccessor).toList) + for (superAcc <- mixin.info.decls.filter(_.isSuperAccessor).toList) yield polyDefDef(implementation(superAcc.asTerm), forwarder(rebindSuper(cls, superAcc))) def methodOverrides(mixin: ClassSymbol): List[Tree] = @@ -74,7 +74,7 @@ class ResolveSuper extends MiniPhaseTransform with IdentityDenotTransformer { th override def transformDefDef(ddef: DefDef)(implicit ctx: Context, info: TransformerInfo) = { val meth = ddef.symbol.asTerm - if (meth.is(SuperAccessor, butNot = Deferred)) { + if (meth.isSuperAccessor && !meth.is(Deferred)) { assert(ddef.rhs.isEmpty) val cls = meth.owner.asClass val ops = new MixinOps(cls, thisTransform) diff --git a/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala b/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala index 32923f0f5..bae1b897e 100644 --- a/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala +++ b/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala @@ -81,7 +81,7 @@ class SuperAccessors(thisTransformer: DenotTransformer) { ctx.debuglog(s"add super acc ${sym.showLocated} to $clazz") val deferredOrPrivate = if (clazz is Trait) Deferred else Private val acc = ctx.newSymbol( - clazz, superName, SuperAccessor | Artifact | Method | deferredOrPrivate, + clazz, superName, Artifact | Method | deferredOrPrivate, superInfo, coord = sym.coord).enteredAfter(thisTransformer) // Diagnostic for SI-7091 if (!accDefs.contains(clazz)) diff --git a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala index f6ff539fe..1b3018d9b 100644 --- a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala +++ b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala @@ -55,6 +55,8 @@ class SymUtils(val self: Symbol) extends AnyVal { def isAliasPreferred(implicit ctx: Context) = self.is(AliasPreferred) || self.name.is(ExpandedName) + def isSuperAccessor(implicit ctx: Context) = self.name.is(SuperAccessorName) + /** If this is a constructor, its owner: otherwise this. */ final def skipConstructor(implicit ctx: Context): Symbol = if (self.isConstructor) self.owner else self diff --git a/compiler/src/dotty/tools/dotc/transform/ValueClasses.scala b/compiler/src/dotty/tools/dotc/transform/ValueClasses.scala index b16d05644..b398c2767 100644 --- a/compiler/src/dotty/tools/dotc/transform/ValueClasses.scala +++ b/compiler/src/dotty/tools/dotc/transform/ValueClasses.scala @@ -8,6 +8,7 @@ import SymDenotations._ import Contexts._ import Flags._ import StdNames._ +import SymUtils._ /** Methods that apply to user-defined value classes */ object ValueClasses { @@ -24,7 +25,7 @@ object ValueClasses { d.isRealMethod && isDerivedValueClass(d.owner) && !d.isConstructor && - !d.is(SuperAccessor) && + !d.isSuperAccessor && !d.is(Macro) /** The member that of a derived value class that unboxes it. */ diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index d61f5fa68..49bc24c80 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -405,7 +405,7 @@ object RefChecks { def ignoreDeferred(member: SingleDenotation) = member.isType || - member.symbol.is(SuperAccessor) || // not yet synthesized + member.symbol.isSuperAccessor || // not yet synthesized member.symbol.is(JavaDefined) && hasJavaErasedOverriding(member.symbol) // 2. Check that only abstract classes have deferred members -- cgit v1.2.3