diff options
Diffstat (limited to 'compiler/src/dotty/tools/dotc/core')
13 files changed, 42 insertions, 39 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index b70fcb093..670b919ac 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -67,7 +67,7 @@ class Definitions { enterTypeField(cls, name, flags | ClassTypeParamCreationFlags, scope) private def enterSyntheticTypeParam(cls: ClassSymbol, paramFlags: FlagSet, scope: MutableScope, suffix: String = "T0") = - enterTypeParam(cls, suffix.toTypeName.expandedName(cls), ExpandedName | paramFlags, scope) + enterTypeParam(cls, suffix.toTypeName.expandedName(cls), paramFlags, scope) // NOTE: Ideally we would write `parentConstrs: => Type*` but SIP-24 is only // implemented in Dotty and not in Scala 2. diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index 29f1078a2..8a1e14c63 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -272,9 +272,6 @@ object Flags { */ final val Synthetic = commonFlag(18, "<synthetic>") - /** Symbol's name is expanded */ - final val ExpandedName = commonFlag(19, "<expandedname>") - /** A covariant type variable / an outer accessor */ final val CovariantOrOuter = commonFlag(20, "") final val Covariant = typeFlag(20, "<covariant>") @@ -308,7 +305,6 @@ object Flags { final val CaseAccessor = termFlag(25, "<caseaccessor>") /** A binding for a type parameter of a base class or trait. - * TODO: Replace with combination of isType, ExpandedName, and Override? */ final val BaseTypeArg = typeFlag(25, "<basetypearg>") @@ -409,9 +405,6 @@ object Flags { final val Scala2ExistentialCommon = commonFlag(55, "<existential>") final val Scala2Existential = Scala2ExistentialCommon.toTypeFlags - /** An overloaded symbol (Scala 2.x only) */ - final val Scala2Overloaded = termFlag(56, "<overloaded>") - /** A module variable (Scala 2.x only) */ final val Scala2ModuleVar = termFlag(57, "<modulevar>") @@ -424,6 +417,13 @@ object Flags { /** A method that is known to have inherited default parameters */ final val InheritedDefaultParams = termFlag(60, "<inherited-default-param>") + /** Translation of Scala2's EXPANDEDNAME flag. This flag is never stored in + * symbols, is only used locally when reading the flags of a Scala2 symbol. + * It's therefore safe to share the code with `InheritedDefaultParams` because + * the latter is never present in Scala2 unpickle info. + */ + final val Scala2ExpandedName = InheritedDefaultParams.toCommonFlags + /** A method that is known to have no default parameters */ final val NoDefaultParams = termFlag(61, "<no-default-param>") @@ -475,7 +475,7 @@ object Flags { /** Flags that are passed from a type parameter of a class to a refinement symbol * that sets the type parameter */ - final val RetainedTypeArgFlags = VarianceFlags | ExpandedName | Protected | Local + final val RetainedTypeArgFlags = VarianceFlags | Protected | Local /** Modules always have these flags set */ final val ModuleCreationFlags = ModuleVal | Lazy | Final | Stable @@ -502,7 +502,7 @@ object Flags { */ final val RetainedModuleValAndClassFlags: FlagSet = AccessFlags | Package | Case | - Synthetic | ExpandedName | JavaDefined | JavaStatic | Artifact | + Synthetic | JavaDefined | JavaStatic | Artifact | Erroneous | Lifted | MixedIn | Specialized /** Flags that can apply to a module val */ @@ -550,9 +550,6 @@ object Flags { /** A private accessor */ final val PrivateAccessor = allOf(Private, Accessor) - /** A type parameter with synthesized name */ - final val ExpandedTypeParam = allOf(ExpandedName, TypeParam) - /** An inline method */ final val InlineMethod = allOf(Inline, Method) @@ -578,7 +575,7 @@ object Flags { final val FinalOrInline = Final | Inline /** If symbol of a type alias has these flags, prefer the alias */ - final val AliasPreferred = TypeParam | BaseTypeArg | ExpandedName + final val AliasPreferred = TypeParam | BaseTypeArg /** A covariant type parameter instance */ final val LocalCovariant = allOf(Local, Covariant) diff --git a/compiler/src/dotty/tools/dotc/core/NameExtractors.scala b/compiler/src/dotty/tools/dotc/core/NameExtractors.scala index ae7d65829..eaac30bf5 100644 --- a/compiler/src/dotty/tools/dotc/core/NameExtractors.scala +++ b/compiler/src/dotty/tools/dotc/core/NameExtractors.scala @@ -45,7 +45,7 @@ object NameExtractors { class PrefixNameExtractor(tag: Int, prefix: String, infoString: String) extends ClassifiedNameExtractor(tag, infoString) { def mkString(underlying: TermName, info: ThisInfo) = - underlying.mapLast(n => termName(prefix + n)).toString + underlying.mapLast(n => termName(prefix + n.toString)).toString } class SuffixNameExtractor(tag: Int, suffix: String, infoString: String) extends ClassifiedNameExtractor(tag, infoString) { @@ -99,7 +99,7 @@ object NameExtractors { object QualifiedName extends QualifiedNameExtractor(QUALIFIED, ".", "Qualified") object FlattenedName extends QualifiedNameExtractor(FLATTENED, "$", "Flattened") - object XpandedName extends QualifiedNameExtractor(EXPANDED, str.EXPAND_SEPARATOR, "Expanded") + object ExpandedName extends QualifiedNameExtractor(EXPANDED, str.EXPAND_SEPARATOR, "Expanded") object TraitSetterName extends QualifiedNameExtractor(TRAITSETTER, str.TRAIT_SETTER_SEPARATOR, "TraitSetter") object DefaultGetterName extends NumberedNameExtractor(DEFAULTGETTER, "DefaultGetter") { @@ -146,6 +146,6 @@ object NameExtractors { val separatorToQualified: Map[String, QualifiedNameExtractor] = Map("." -> QualifiedName, "$" -> FlattenedName, - str.EXPAND_SEPARATOR -> XpandedName, + str.EXPAND_SEPARATOR -> ExpandedName, str.TRAIT_SETTER_SEPARATOR -> TraitSetterName) }
\ No newline at end of file diff --git a/compiler/src/dotty/tools/dotc/core/NameOps.scala b/compiler/src/dotty/tools/dotc/core/NameOps.scala index c837bc25c..f467fbcd5 100644 --- a/compiler/src/dotty/tools/dotc/core/NameOps.scala +++ b/compiler/src/dotty/tools/dotc/core/NameOps.scala @@ -138,7 +138,7 @@ object NameOps { /** The expanded name of `name` relative to given class `base`. */ def expandedName(base: Symbol, separator: Name)(implicit ctx: Context): N = - expandedName(if (base is Flags.ExpandedName) base.name else base.fullNameSeparated("$"), separator) + expandedName(if (base.name.is(ExpandedName)) base.name else base.fullNameSeparated("$"), separator) def expandedName(base: Symbol)(implicit ctx: Context): N = expandedName(base, nme.EXPAND_SEPARATOR) @@ -161,7 +161,7 @@ object NameOps { /** Revert the expanded name. */ def unexpandedName: N = likeTyped { - name.rewrite { case XpandedName(_, unexp) => unexp } + name.rewrite { case ExpandedName(_, unexp) => unexp } } def unexpandedNameOfMangled: N = likeTyped { @@ -175,8 +175,8 @@ object NameOps { if (idx < 0) name else (name drop (idx + nme.EXPAND_SEPARATOR.length)) } - def expandedPrefix: N = likeTyped { name.exclude(XpandedName) } - + def expandedPrefix: N = likeTyped { name.exclude(ExpandedName) } + def expandedPrefixOfMangled: N = { val idx = name.lastIndexOfSlice(nme.EXPAND_SEPARATOR) assert(idx >= 0) @@ -188,7 +188,7 @@ object NameOps { val unmangled = unexpandedNameOfMangled if (name eq unmangled) name else likeTyped( - XpandedName(expandedPrefixOfMangled.toTermName, unmangled.asSimpleName)) + ExpandedName(expandedPrefixOfMangled.toTermName, unmangled.asSimpleName)) } else name diff --git a/compiler/src/dotty/tools/dotc/core/Signature.scala b/compiler/src/dotty/tools/dotc/core/Signature.scala index fcd1e2376..4699cecf2 100644 --- a/compiler/src/dotty/tools/dotc/core/Signature.scala +++ b/compiler/src/dotty/tools/dotc/core/Signature.scala @@ -34,6 +34,14 @@ import scala.annotation.tailrec case class Signature(paramsSig: List[TypeName], resSig: TypeName) { import Signature._ +/* FIXME does not compile under dotty, we get a missing param error + def checkUnqual(name: TypeName) = name mapParts { part => + assert(!part.contains('.'), name) + part + } + paramsSig.foreach(checkUnqual) + checkUnqual(resSig) +*/ /** Two names are consistent if they are the same or one of them is tpnme.Uninstantiated */ private def consistent(name1: TypeName, name2: TypeName) = name1 == name2 || name1 == tpnme.Uninstantiated || name2 == tpnme.Uninstantiated diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 4e40d1e05..bbebdd21d 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -367,7 +367,7 @@ object SymDenotations { /** The expanded name of this denotation. */ final def expandedName(implicit ctx: Context) = - if (is(ExpandedName) || isConstructor) name + if (name.is(ExpandedName) || isConstructor) name else { def legalize(name: Name): Name = // JVM method names may not contain `<' or `>' characters if (is(Method)) name.replace('<', '(').replace('>', ')') else name @@ -1210,9 +1210,7 @@ object SymDenotations { /** If denotation is private, remove the Private flag and expand the name if necessary */ def ensureNotPrivate(implicit ctx: Context) = if (is(Private)) - copySymDenotation( - name = expandedName, - initFlags = this.flags &~ Private | ExpandedName) + copySymDenotation(name = expandedName, initFlags = this.flags &~ Private) else this } diff --git a/compiler/src/dotty/tools/dotc/core/TypeApplications.scala b/compiler/src/dotty/tools/dotc/core/TypeApplications.scala index 94b726491..0220928a2 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeApplications.scala @@ -11,6 +11,7 @@ import util.Stats._ import util.common._ import Names._ import NameOps._ +import NameExtractors._ import Flags._ import StdNames.tpnme import util.Positions.Position @@ -464,11 +465,6 @@ class TypeApplications(val self: Type) extends AnyVal { self case _ => val v = tparam.paramVariance - /* Not neeeded. - if (v > 0 && !(tparam is Local) && !(tparam is ExpandedTypeParam)) TypeBounds.upper(self) - else if (v < 0 && !(tparam is Local) && !(tparam is ExpandedTypeParam)) TypeBounds.lower(self) - else - */ TypeAlias(self, v) } @@ -510,13 +506,14 @@ class TypeApplications(val self: Type) extends AnyVal { */ final def baseTypeWithArgs(base: Symbol)(implicit ctx: Context): Type = ctx.traceIndented(s"btwa ${self.show} wrt $base", core, show = true) { def default = self.baseTypeRef(base).appliedTo(baseArgInfos(base)) + def isExpandedTypeParam(sym: Symbol) = sym.is(TypeParam) && sym.name.is(ExpandedName) self match { case tp: TypeRef => tp.info match { case TypeBounds(_, hi) => hi.baseTypeWithArgs(base) case _ => default } - case tp @ RefinedType(parent, name, _) if !tp.member(name).symbol.is(ExpandedTypeParam) => + case tp @ RefinedType(parent, name, _) if !isExpandedTypeParam(tp.member(name).symbol) => tp.wrapIfMember(parent.baseTypeWithArgs(base)) case tp: TermRef => tp.underlying.baseTypeWithArgs(base) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala b/compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala index 74c4265f2..a09a21964 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala @@ -62,7 +62,7 @@ class NameBuffer extends TastyBuffer(10000) { withLength { writeNameRef(qualified); writeNameRef(selector) } case FlattenedName(qualified, selector) => withLength { writeNameRef(qualified); writeNameRef(selector) } - case XpandedName(prefix, original) => + case ExpandedName(prefix, original) => withLength { writeNameRef(prefix); writeNameRef(original) } case SignedName(original, Signature(params, result)) => withLength( diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala index 6dd22db88..d20e890c2 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala @@ -54,7 +54,7 @@ class TastyUnpickler(reader: TastyReader) { case FLATTENED => FlattenedName(readName(), readName().asSimpleName) case EXPANDED => - XpandedName(readName(), readName().asSimpleName) + ExpandedName(readName(), readName().asSimpleName) case SIGNED => val original = readName() val result = readName().toTypeName diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala index 2da638291..e697ff028 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala @@ -13,6 +13,7 @@ import NameOps._, NameExtractors._ import StdNames.nme import TastyBuffer._ import TypeApplications._ +import transform.SymUtils._ import config.Config class TreePickler(pickler: TastyPickler) { @@ -141,7 +142,7 @@ class TreePickler(pickler: TastyPickler) { withLength { pickleType(tycon); args.foreach(pickleType(_)) } case ConstantType(value) => pickleConstant(value) - case tpe: TypeRef if tpe.info.isAlias && tpe.symbol.is(Flags.AliasPreferred) => + case tpe: TypeRef if tpe.info.isAlias && tpe.symbol.isAliasPreferred => pickleType(tpe.superType) case tpe: WithFixedSym => val sym = tpe.symbol diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 11c04e2b4..d8497f39d 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -428,7 +428,6 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi if (!rhsIsEmpty) skipTree() val (givenFlags, annots, privateWithin) = readModifiers(end) val nameFlags = - (if (name.is(XpandedName)) ExpandedName else EmptyFlags) | (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) diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/PickleBuffer.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/PickleBuffer.scala index 6ee9f1f9e..773c6760e 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/PickleBuffer.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/PickleBuffer.scala @@ -229,7 +229,7 @@ object PickleBuffer { MODULEVAR -> Scala2ModuleVar, LAZY -> Lazy, MIXEDIN -> (MixedIn, Scala2Existential), - EXPANDEDNAME -> ExpandedName, + EXPANDEDNAME -> Scala2ExpandedName, IMPLCLASS -> (Scala2PreSuper, ImplClass), SPECIALIZED -> Specialized, VBRIDGE -> VBridge, diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index c37d60b41..aed0e97f1 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -437,7 +437,10 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas if (name == nme.TRAIT_CONSTRUCTOR) nme.CONSTRUCTOR else name.asTermName.unmangleMethodName } - if (flags is ExpandedName) name = name.unmangleExpandedName + if (flags is Scala2ExpandedName) { + name = name.unmangleExpandedName + flags = flags &~ Scala2ExpandedName + } if (flags is SuperAccessor) name = name.asTermName.unmangleSuperName def isClassRoot = (name == classRoot.name) && (owner == classRoot.owner) && !(flags is ModuleClass) @@ -476,7 +479,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas var flags1 = flags if (flags is TypeParam) { name1 = name1.expandedName(owner) - flags1 |= owner.typeParamCreationFlags | ExpandedName + flags1 |= owner.typeParamCreationFlags } ctx.newSymbol(owner, name1, flags1, localMemberUnpickler, coord = start) case CLASSsym => |