diff options
Diffstat (limited to 'compiler/src/dotty/tools/dotc/core')
12 files changed, 165 insertions, 109 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/Contexts.scala b/compiler/src/dotty/tools/dotc/core/Contexts.scala index 8707b66f9..c80ad876a 100644 --- a/compiler/src/dotty/tools/dotc/core/Contexts.scala +++ b/compiler/src/dotty/tools/dotc/core/Contexts.scala @@ -174,9 +174,6 @@ object Contexts { protected def freshNames_=(freshNames: FreshNameCreator) = _freshNames = freshNames def freshNames: FreshNameCreator = _freshNames - def freshName(prefix: String = ""): String = freshNames.newName(prefix) - def freshName(prefix: Name): String = freshName(prefix.toString) - /** A map in which more contextual properties can be stored */ private var _moreProperties: Map[Key[Any], Any] = _ protected def moreProperties_=(moreProperties: Map[Key[Any], Any]) = _moreProperties = moreProperties diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index 60a506291..42837122a 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -1193,8 +1193,8 @@ object Denotations { recur(underlying, n => wrap(ModuleClassName(n))) case QualifiedName(prefix, selector) => select(recur(prefix), wrap(selector)) - case AnyQualifiedName(prefix, info) => - recur(prefix, n => wrap(info.mkString(n).toTermName)) + case qn @ AnyQualifiedName(prefix, _) => + recur(prefix, n => wrap(qn.info.mkString(n).toTermName)) case path: SimpleTermName => def recurSimple(len: Int, wrap: TermName => Name): Denotation = { val point = path.lastIndexOf('.', len - 1) diff --git a/compiler/src/dotty/tools/dotc/core/NameExtractors.scala b/compiler/src/dotty/tools/dotc/core/NameExtractors.scala index 2c5f5c164..1439ce002 100644 --- a/compiler/src/dotty/tools/dotc/core/NameExtractors.scala +++ b/compiler/src/dotty/tools/dotc/core/NameExtractors.scala @@ -8,33 +8,38 @@ import StdNames._ import util.DotClass import tasty.TastyFormat._ import Decorators._ +import Contexts.Context import collection.mutable object NameExtractors { - @sharable private val extractors = new mutable.HashMap[Int, ClassifiedNameExtractor] + @sharable private val simpleExtractors = new mutable.HashMap[Int, ClassifiedNameExtractor] + @sharable private val uniqueExtractors = new mutable.HashMap[String, UniqueNameExtractor] + @sharable private val qualifiedExtractors = new mutable.HashMap[String, QualifiedNameExtractor] abstract class NameInfo extends DotClass { - def tag: Int - def definesNewName: Boolean = false + def extractor: NameExtractor def mkString(underlying: TermName): String def map(f: SimpleTermName => SimpleTermName): NameInfo = this } - val simpleTermNameInfo = new NameInfo { - def tag = UTF8 - def mkString(underlying: TermName): String = unsupported("mkString") - } - abstract class NameExtractor(val tag: Int) extends DotClass { self => - def mkString(underlying: TermName, info: ThisInfo): String - def infoString: String type ThisInfo <: Info class Info extends NameInfo { this: ThisInfo => - def tag = self.tag + def extractor = self def mkString(underlying: TermName) = self.mkString(underlying, this) override def toString = infoString } + def definesNewName = false + def mkString(underlying: TermName, info: ThisInfo): String + def infoString: String + } + + object SimpleTermNameExtractor extends NameExtractor(UTF8) { self => + type ThisInfo = Info + val info = new Info + def mkString(underlying: TermName, info: ThisInfo) = unsupported("mkString") + def infoString = unsupported("infoString") } abstract class ClassifiedNameExtractor(tag: Int, val infoString: String) extends NameExtractor(tag) { @@ -46,15 +51,17 @@ object NameExtractors { case DerivedTermName(underlying, `info`) => Some(underlying) case _ => None } - extractors(tag) = this + simpleExtractors(tag) = this } - class PrefixNameExtractor(tag: Int, prefix: String, infoString: String) extends ClassifiedNameExtractor(tag, infoString) { + class PrefixNameExtractor(tag: Int, prefix: String, optInfoString: String = "") + extends ClassifiedNameExtractor(tag, if (optInfoString.isEmpty) s"Prefix $prefix" else optInfoString) { def mkString(underlying: TermName, info: ThisInfo) = underlying.mapLast(n => termName(prefix + n.toString)).toString } - class SuffixNameExtractor(tag: Int, suffix: String, infoString: String) extends ClassifiedNameExtractor(tag, infoString) { + class SuffixNameExtractor(tag: Int, suffix: String, optInfoString: String = "") + extends ClassifiedNameExtractor(tag, if (optInfoString.isEmpty) s"Suffix $suffix" else optInfoString) { def mkString(underlying: TermName, info: ThisInfo) = underlying.toString ++ suffix } @@ -62,10 +69,10 @@ object NameExtractors { val name: SimpleTermName } - abstract class QualifiedNameExtractor(tag: Int, val separator: String, val infoString: String) extends NameExtractor(tag) { + class QualifiedNameExtractor(tag: Int, val separator: String) + extends NameExtractor(tag) { type ThisInfo = QualInfo case class QualInfo(val name: SimpleTermName) extends Info with QualifiedInfo { - override def definesNewName = true override def map(f: SimpleTermName => SimpleTermName): NameInfo = new QualInfo(f(name)) override def toString = s"$infoString $name" } @@ -75,26 +82,32 @@ object NameExtractors { case DerivedTermName(qual, info: this.QualInfo) => Some((qual, info.name)) case _ => None } + + override def definesNewName = true + def mkString(underlying: TermName, info: ThisInfo) = s"$underlying$separator${info.name}" + def infoString = s"Qualified $separator" + + qualifiedExtractors(separator) = this } object AnyQualifiedName { - def unapply(name: DerivedTermName): Option[(TermName, QualifiedInfo)] = name match { + def unapply(name: DerivedTermName): Option[(TermName, SimpleTermName)] = name match { case DerivedTermName(qual, info: QualifiedInfo) => - Some((name.underlying, info)) + Some((name.underlying, info.name)) case _ => None } } trait NumberedInfo { def num: Int + def extractor: NameExtractor } abstract class NumberedNameExtractor(tag: Int, val infoString: String) extends NameExtractor(tag) { self => type ThisInfo = NumberedInfo case class NumberedInfo(val num: Int) extends Info with NameExtractors.NumberedInfo { - override def definesNewName = self.definesNewName override def toString = s"$infoString $num" } def apply(qual: TermName, num: Int) = @@ -103,20 +116,66 @@ object NameExtractors { case DerivedTermName(underlying, info: this.NumberedInfo) => Some((underlying, info.num)) case _ => None } - def definesNewName = false } - class UniqueNameExtractor(sep: String) extends NumberedNameExtractor(UNIQUE, "Unique") { - val separator = if (sep.isEmpty) "$" else sep - override def definesNewName = !sep.isEmpty - def mkString(underlying: TermName, info: ThisInfo) = - underlying.toString + separator + info.num + case class UniqueNameExtractor(val separator: String) + extends NumberedNameExtractor(UNIQUE, s"Unique $separator") { + override def definesNewName = true + def mkString(underlying: TermName, info: ThisInfo) = { + val safePrefix = str.sanitize(underlying.toString + separator) + safePrefix + info.num + } + + def fresh(prefix: TermName = EmptyTermName)(implicit ctx: Context): TermName = + ctx.freshNames.newName(prefix, this) + + uniqueExtractors(separator) = this + } + + object AnyUniqueName { + def unapply(name: DerivedTermName): Option[(TermName, String, Int)] = name match { + case DerivedTermName(qual, info: NumberedInfo) => + info.extractor match { + case unique: UniqueNameExtractor => Some((qual, unique.separator, info.num)) + case _ => None + } + case _ => None + } } - object QualifiedName extends QualifiedNameExtractor(QUALIFIED, ".", "Qualified") - object FlattenedName extends QualifiedNameExtractor(FLATTENED, "$", "Flattened") - object ExpandedName extends QualifiedNameExtractor(EXPANDED, str.EXPAND_SEPARATOR, "Expanded") - object TraitSetterName extends QualifiedNameExtractor(TRAITSETTER, str.TRAIT_SETTER_SEPARATOR, "TraitSetter") + val QualifiedName = new QualifiedNameExtractor(QUALIFIED, ".") + val FlattenedName = new QualifiedNameExtractor(FLATTENED, "$") + val ExpandedName = new QualifiedNameExtractor(EXPANDED, str.EXPAND_SEPARATOR) + val TraitSetterName = new QualifiedNameExtractor(TRAITSETTER, str.TRAIT_SETTER_SEPARATOR) + + val UniqueName = new UniqueNameExtractor("$") { + override def mkString(underlying: TermName, info: ThisInfo) = + if (underlying.isEmpty) "$" + info.num + "$" else super.mkString(underlying, info) + } + + val InlineAccessorName = new UniqueNameExtractor("$_inlineAccessor_$") + val TempResultName = new UniqueNameExtractor("ev$") + val EvidenceParamName = new UniqueNameExtractor("evidence$") + val DepParamName = new UniqueNameExtractor("<param>") + val LazyImplicitName = new UniqueNameExtractor("$_lazy_implicit_$") + val LazyLocalName = new UniqueNameExtractor("$lzy") + val LazyLocalInitName = new UniqueNameExtractor("$lzyINIT") + val LazyFieldOffsetName = new UniqueNameExtractor("$OFFSET") + val LazyBitMapName = new UniqueNameExtractor(nme.BITMAP_PREFIX.toString) + val NonLocalReturnKeyName = new UniqueNameExtractor("nonLocalReturnKey") + val WildcardParamName = new UniqueNameExtractor("_$") + val TailLabelName = new UniqueNameExtractor("tailLabel") + val ExceptionBinderName = new UniqueNameExtractor("ex") + val SkolemName = new UniqueNameExtractor("?") + val LiftedTreeName = new UniqueNameExtractor("liftedTree") + + val PatMatStdBinderName = new UniqueNameExtractor("x") + val PatMatPiName = new UniqueNameExtractor("pi") // FIXME: explain what this is + val PatMatPName = new UniqueNameExtractor("p") // FIXME: explain what this is + val PatMatOName = new UniqueNameExtractor("o") // FIXME: explain what this is + val PatMatCaseName = new UniqueNameExtractor("case") + val PatMatMatchFailName = new UniqueNameExtractor("matchFail") + val PatMatSelectorName = new UniqueNameExtractor("selector") object DefaultGetterName extends NumberedNameExtractor(DEFAULTGETTER, "DefaultGetter") { def mkString(underlying: TermName, info: ThisInfo) = { @@ -133,12 +192,11 @@ object NameExtractors { } } - val SuperAccessorName = new PrefixNameExtractor(SUPERACCESSOR, str.SUPER_PREFIX, "SuperAccessor") - val InitializerName = new PrefixNameExtractor(INITIALIZER, str.INITIALIZER_PREFIX, "Initializer") - val ShadowedName = new PrefixNameExtractor(SHADOWED, str.SHADOWED_PREFIX, "Shadowed") - val LocalDummyName = new PrefixNameExtractor(LOCALDUMMY, str.LOCAL_DUMMY_PREFIX, "LocalDummy") - val AvoidClashName = new SuffixNameExtractor(AVOIDCLASH, str.AVOID_CLASH_SUFFIX, "AvoidClash") - val ModuleClassName = new SuffixNameExtractor(OBJECTCLASS, "$", "ModuleClass") + val SuperAccessorName = new PrefixNameExtractor(SUPERACCESSOR, "super$") + val InitializerName = new PrefixNameExtractor(INITIALIZER, "initial$") + val ShadowedName = new PrefixNameExtractor(SHADOWED, "(shadowed)") + val AvoidClashName = new SuffixNameExtractor(AVOIDCLASH, "$_avoid_name_clash_$") + val ModuleClassName = new SuffixNameExtractor(OBJECTCLASS, "$", optInfoString = "ModuleClass") object SignedName extends NameExtractor(63) { @@ -159,11 +217,7 @@ object NameExtractors { def infoString: String = "Signed" } - def extractorOfTag(tag: Int) = extractors(tag) - - val separatorToQualified: Map[String, QualifiedNameExtractor] = - Map("." -> QualifiedName, - "$" -> FlattenedName, - str.EXPAND_SEPARATOR -> ExpandedName, - str.TRAIT_SETTER_SEPARATOR -> TraitSetterName) + def simpleExtractorOfTag : collection.Map[Int, ClassifiedNameExtractor] = simpleExtractors + def qualifiedExtractorOfSeparator: collection.Map[String, QualifiedNameExtractor] = qualifiedExtractors + def uniqueExtractorOfSeparator : collection.Map[String, UniqueNameExtractor] = uniqueExtractors }
\ 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 031cda1bd..6f2c75313 100644 --- a/compiler/src/dotty/tools/dotc/core/NameOps.scala +++ b/compiler/src/dotty/tools/dotc/core/NameOps.scala @@ -71,9 +71,7 @@ object NameOps { def isModuleVarName(name: Name): Boolean = name.stripAnonNumberSuffix endsWith MODULE_VAR_SUFFIX def isSelectorName = name.startsWith(" ") && name.tail.forall(_.isDigit) - def isLazyLocal = name.endsWith(nme.LAZY_LOCAL) def isOuterSelect = name.endsWith(nme.OUTER_SELECT) - def isInlineAccessor = name.startsWith(nme.INLINE_ACCESSOR_PREFIX) /** Is name a variable name? */ def isVariableName: Boolean = name.length > 0 && { @@ -112,16 +110,16 @@ object NameOps { def moduleClassName: TypeName = name.derived(ModuleClassName).toTypeName /** Convert this module class name to corresponding source module name */ - def sourceModuleName: TermName = stripModuleClassSuffix.toTermName + def sourceModuleName: TermName = name.toTermName.exclude(ModuleClassName) /** If name ends in module class suffix, drop it */ def stripModuleClassSuffix: Name = name.exclude(ModuleClassName) /** If flags is a ModuleClass but not a Package, add module class suffix */ - def adjustIfModuleClass(flags: Flags.FlagSet): N = { + def adjustIfModuleClass(flags: Flags.FlagSet): N = likeTyped { if (flags is (ModuleClass, butNot = Package)) name.asTypeName.moduleClassName - else likeTyped(name.toTermName.exclude(AvoidClashName)) - }.asInstanceOf[N] + else name.toTermName.exclude(AvoidClashName) + } /** The superaccessor for method with given name */ def superName: TermName = SuperAccessorName(name.toTermName) @@ -138,7 +136,7 @@ object NameOps { def expandedName(prefix: Name, separator: Name = nme.EXPAND_SEPARATOR): N = likeTyped { def qualify(name: SimpleTermName) = - separatorToQualified(separator.toString)(prefix.toTermName, name) + qualifiedExtractorOfSeparator(separator.toString)(prefix.toTermName, name) name rewrite { case name: SimpleTermName => qualify(name) @@ -220,6 +218,13 @@ object NameOps { } */ + def freshened(implicit ctx: Context): N = likeTyped { + name.toTermName match { + case ModuleClassName(original) => ModuleClassName(original.freshened) + case name => UniqueName.fresh(name) + } + } + def unmangleClassName: N = if (name.isSimple && name.isTypeName) if (name.endsWith(MODULE_SUFFIX) && !tpnme.falseModuleClassNames.contains(name.asTypeName)) @@ -504,14 +509,6 @@ object NameOps { case name => name } - def lazyLocalName = name ++ nme.LAZY_LOCAL - def nonLazyName = { - assert(name.isLazyLocal) - name.dropRight(nme.LAZY_LOCAL.length) - } - - def inlineAccessorName = nme.INLINE_ACCESSOR_PREFIX ++ name ++ "$" - def unmangleMethodName: TermName = if (name.isSimple) { val idx = name.defaultGetterIndexOfMangled diff --git a/compiler/src/dotty/tools/dotc/core/Names.scala b/compiler/src/dotty/tools/dotc/core/Names.scala index 81429a8d9..e4ebe61c2 100644 --- a/compiler/src/dotty/tools/dotc/core/Names.scala +++ b/compiler/src/dotty/tools/dotc/core/Names.scala @@ -130,7 +130,7 @@ object Names { def likeKinded(name: Name): TermName = name.toTermName - def info: NameInfo = simpleTermNameInfo + def info: NameInfo = SimpleTermNameExtractor.info def underlying: TermName = unsupported("underlying") @sharable private var derivedNames: AnyRef /* SimpleMap | j.u.HashMap */ = @@ -174,9 +174,10 @@ object Names { * name as underlying name. */ def derived(info: NameInfo): TermName = { - val ownTag = this.info.tag - if (ownTag < info.tag || info.definesNewName) add(info) - else if (ownTag > info.tag) rewrap(underlying.derived(info)) + val thisKind = this.info.extractor + val thatKind = info.extractor + if (thisKind.tag < thatKind.tag || thatKind.definesNewName) add(info) + else if (thisKind.tag > thatKind.tag) rewrap(underlying.derived(info)) else { assert(info == this.info) this @@ -184,16 +185,16 @@ object Names { } def exclude(kind: NameExtractor): TermName = { - val ownTag = this.info.tag - if (ownTag < kind.tag || info.definesNewName) this - else if (ownTag > kind.tag) rewrap(underlying.exclude(kind)) + val thisKind = this.info.extractor + if (thisKind.tag < kind.tag || thisKind.definesNewName) this + else if (thisKind.tag > kind.tag) rewrap(underlying.exclude(kind)) else underlying } def is(kind: NameExtractor): Boolean = { - val ownTag = this.info.tag - ownTag == kind.tag || - !info.definesNewName && ownTag > kind.tag && underlying.is(kind) + val thisKind = this.info.extractor + thisKind == kind || + !thisKind.definesNewName && thisKind.tag > kind.tag && underlying.is(kind) } override def hashCode = System.identityHashCode(this) @@ -511,7 +512,7 @@ object Names { implicit val NameOrdering: Ordering[Name] = new Ordering[Name] { private def compareInfos(x: NameInfo, y: NameInfo): Int = - if (x.tag != y.tag) x.tag - y.tag + if (x.extractor.tag != y.extractor.tag) x.extractor.tag - y.extractor.tag else x match { case x: QualifiedInfo => y match { diff --git a/compiler/src/dotty/tools/dotc/core/StdNames.scala b/compiler/src/dotty/tools/dotc/core/StdNames.scala index 09e808c7d..598d55650 100644 --- a/compiler/src/dotty/tools/dotc/core/StdNames.scala +++ b/compiler/src/dotty/tools/dotc/core/StdNames.scala @@ -22,7 +22,8 @@ object StdNames { val INITIALIZER_PREFIX = "initial$" val SHADOWED_PREFIX = "(shadowed)" val AVOID_CLASH_SUFFIX = "$_avoid_name_clash_$" - val LOCAL_DUMMY_PREFIX = "<local>_" // owner of local blocks + + def sanitize(str: String) = str.replaceAll("""[<>]""", """\$""") } abstract class DefinedNames[N <: Name] { @@ -96,7 +97,7 @@ object StdNames { val ANON_CLASS: N = "$anon" val ANON_FUN: N = "$anonfun" - val BITMAP_PREFIX: N = "bitmap$" + val BITMAP_PREFIX: N = "bitmap$" // @darkdimius: $bitmap? Also, the next 4 names are unused. val BITMAP_NORMAL: N = BITMAP_PREFIX // initialization bitmap for public/protected lazy vals val BITMAP_TRANSIENT: N = BITMAP_PREFIX + "trans$" // initialization bitmap for transient lazy vals val BITMAP_CHECKINIT: N = BITMAP_PREFIX + "init$" // initialization bitmap for checkinit values @@ -106,13 +107,10 @@ object StdNames { val DO_WHILE_PREFIX: N = "doWhile$" val EMPTY: N = "" val EMPTY_PACKAGE: N = Names.EMPTY_PACKAGE.toString - val EVIDENCE_PARAM_PREFIX: N = "evidence$" - val DEP_PARAM_PREFIX = "<param>" val EXCEPTION_RESULT_PREFIX: N = "exceptionResult" val EXPAND_SEPARATOR: N = str.EXPAND_SEPARATOR val IMPL_CLASS_SUFFIX: N = "$class" val IMPORT: N = "<import>" - val INLINE_ACCESSOR_PREFIX = "$inlineAccessor$" val INTERPRETER_IMPORT_WRAPPER: N = "$iw" val INTERPRETER_LINE_PREFIX: N = "line" val INTERPRETER_VAR_PREFIX: N = "res" @@ -121,7 +119,6 @@ object StdNames { val MODULE_SUFFIX: N = NameTransformer.MODULE_SUFFIX_STRING val MODULE_VAR_SUFFIX: N = "$module" val NAME_JOIN: N = NameTransformer.NAME_JOIN_STRING - val USCORE_PARAM_PREFIX: N = "_$" val OPS_PACKAGE: N = "<special-ops>" val OVERLOADED: N = "<overloaded>" val PACKAGE: N = "package" @@ -139,9 +136,6 @@ object StdNames { val COMPANION_CLASS_METHOD: N = "companion$class" val TRAIT_SETTER_SEPARATOR: N = str.TRAIT_SETTER_SEPARATOR val DIRECT_SUFFIX: N = "$direct" - val LAZY_IMPLICIT_PREFIX: N = "$lazy_implicit$" - val DOLLAR_VALUES: N = "$values" - val DOLLAR_NEW: N = "$new" // value types (and AnyRef) are all used as terms as well // as (at least) arguments to the @specialize annotation. @@ -249,8 +243,6 @@ object StdNames { val EVT2U: N = "evt2u$" val EQEQ_LOCAL_VAR: N = "eqEqTemp$" val FAKE_LOCAL_THIS: N = "this$" - val LAZY_LOCAL: N = "$lzy" - val LAZY_LOCAL_INIT: N = "$lzyINIT" val LAZY_FIELD_OFFSET: N = "OFFSET$" val LAZY_SLOW_SUFFIX: N = "$lzycompute" val LOCAL_SUFFIX: N = "$$local" @@ -448,7 +440,6 @@ object StdNames { val lang: N = "lang" val length: N = "length" val lengthCompare: N = "lengthCompare" - val liftedTree: N = "liftedTree" val `macro` : N = "macro" val macroThis : N = "_this" val macroContext : N = "c" diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index eb16b2188..5e5a5df2d 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -406,14 +406,14 @@ object SymDenotations { } var prefix = encl.fullNameSeparated(separator) val fn = - if (separatorToQualified.contains(sep)) { + if (qualifiedExtractorOfSeparator.contains(sep)) { if (sep == "$") // duplicate scalac's behavior: don't write a double '$$' for module class members. prefix = prefix.exclude(ModuleClassName) name rewrite { case n: SimpleTermName => val n1 = if (filler.isEmpty) n else termName(filler ++ n) - separatorToQualified(sep)(prefix.toTermName, n1) + qualifiedExtractorOfSeparator(sep)(prefix.toTermName, n1) } } else { @@ -1541,7 +1541,7 @@ object SymDenotations { !(this is Frozen) || (scope ne this.unforcedDecls) || sym.hasAnnotation(defn.ScalaStaticAnnot) || - sym.name.isInlineAccessor || + sym.name.is(InlineAccessorName) || isUsecase, i"trying to enter $sym in $this, frozen = ${this is Frozen}") scope.enter(sym) diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index 95ff1cb75..69d6e8db3 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -19,6 +19,7 @@ import util.Positions._ import DenotTransformers._ import StdNames._ import NameOps._ +import NameExtractors.LazyImplicitName import ast.tpd.Tree import ast.TreeTypeMap import Constants.Constant @@ -260,7 +261,7 @@ trait Symbols { this: Context => /** Create a synthetic lazy implicit value */ def newLazyImplicit(info: Type) = - newSymbol(owner, freshName(nme.LAZY_IMPLICIT_PREFIX).toTermName, Lazy, info) + newSymbol(owner, LazyImplicitName.fresh(), Lazy, info) /** Create a symbol representing a selftype declaration for class `cls`. */ def newSelfSym(cls: ClassSymbol, name: TermName = nme.WILDCARD, selfInfo: Type = NoType): TermSymbol = diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index b2502ee94..3f5a30922 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -7,7 +7,7 @@ import Symbols._ import Flags._ import Names._ import StdNames._, NameOps._ -import NameExtractors.ShadowedName +import NameExtractors.{ShadowedName, SkolemName} import Scopes._ import Constants._ import Contexts._ @@ -3001,9 +3001,9 @@ object Types { override def hashCode: Int = identityHash override def equals(that: Any) = this eq that.asInstanceOf[AnyRef] - private var myRepr: String = null - def repr(implicit ctx: Context) = { - if (myRepr == null) myRepr = ctx.freshName("?") + private var myRepr: Name = null + def repr(implicit ctx: Context): Name = { + if (myRepr == null) myRepr = SkolemName.fresh() myRepr } diff --git a/compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala b/compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala index df43eabb2..2fd078bef 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala @@ -26,10 +26,13 @@ class NameBuffer extends TastyBuffer(10000) { name1 match { case SignedName(original, Signature(params, result)) => nameIndex(original); nameIndex(result); params.foreach(nameIndex) - case AnyQualifiedName(prefix, info) => - nameIndex(prefix); nameIndex(info.name) - case DerivedTermName(prefix, _) => - nameIndex(prefix) + case AnyQualifiedName(prefix, name) => + nameIndex(prefix); nameIndex(name) + case AnyUniqueName(original, separator, num) => + nameIndex(separator.toTermName) + if (original.nonEmpty) nameIndex(original) + case DerivedTermName(original, _) => + nameIndex(original) case _ => } val ref = NameRef(nameRefs.size) @@ -50,7 +53,8 @@ class NameBuffer extends TastyBuffer(10000) { def writeNameRef(name: Name): Unit = writeNameRef(nameRefs(name.toTermName)) def pickleNameContents(name: Name): Unit = { - writeByte(name.toTermName.info.tag) + val tag = name.toTermName.info.extractor.tag + writeByte(tag) name.toTermName match { case name: SimpleTermName => val bytes = @@ -58,17 +62,23 @@ class NameBuffer extends TastyBuffer(10000) { else Codec.toUTF8(chrs, name.start, name.length) writeNat(bytes.length) writeBytes(bytes, bytes.length) - case AnyQualifiedName(prefix, info) => - withLength { writeNameRef(prefix); writeNameRef(info.name) } - case SignedName(original, Signature(params, result)) => - withLength( - { writeNameRef(original); writeNameRef(result); params.foreach(writeNameRef) }, - if ((params.length + 2) * maxIndexWidth <= maxNumInByte) 1 else 2) + case AnyQualifiedName(prefix, name) => + withLength { writeNameRef(prefix); writeNameRef(name) } + case AnyUniqueName(original, separator, num) => + withLength { + writeNameRef(separator.toTermName) + writeNat(num) + if (original.nonEmpty) writeNameRef(original) + } case DefaultGetterName(method, paramNumber) => withLength { writeNameRef(method); writeNat(paramNumber) } case VariantName(original, sign) => withLength { writeNameRef(original); writeNat(sign + 1) } - case DerivedTermName(original, info) => + case SignedName(original, Signature(params, result)) => + withLength( + { writeNameRef(original); writeNameRef(result); params.foreach(writeNameRef) }, + if ((params.length + 2) * maxIndexWidth <= maxNumInByte) 1 else 2) + case DerivedTermName(original, _) => withLength { writeNameRef(original) } } } diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala index d0fee04df..18d4a6344 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala @@ -33,11 +33,11 @@ Macro-format: QUALIFIED Length qualified_NameRef selector_NameRef SIGNED Length original_NameRef resultSig_NameRef paramSig_NameRef* EXPANDED Length original_NameRef + UNIQUE Length separator_NameRef num_Nat original_NameRef? OBJECTCLASS Length module_NameRef SUPERACCESSOR Length accessed_NameRef DEFAULTGETTER Length method_NameRef paramNumber_Nat SHADOWED Length original_NameRef - MANGLED Length mangle_NameRef name_NameRef ... NameRef = Nat // ordinal number of name in name table, starting from 1. @@ -231,7 +231,6 @@ object TastyFormat { final val SUPERACCESSOR = 20 final val INITIALIZER = 21 final val SHADOWED = 22 - final val LOCALDUMMY = 23 final val AVOIDCLASH = 27 final val OBJECTCLASS = 29 diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala index 7ebf3a2ea..756b7db5c 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala @@ -5,7 +5,7 @@ package tasty import scala.collection.mutable import TastyFormat._ import TastyBuffer.NameRef -import Names.{Name, TermName, termName} +import Names.{Name, TermName, termName, EmptyTermName} import NameExtractors._ import java.util.UUID @@ -55,6 +55,12 @@ class TastyUnpickler(reader: TastyReader) { FlattenedName(readName(), readName().asSimpleName) case EXPANDED => ExpandedName(readName(), readName().asSimpleName) + case UNIQUE => + val separator = readName().toString + val num = readNat() + val originals = until(end)(readName()) + val original = if (originals.isEmpty) EmptyTermName else originals.head + uniqueExtractorOfSeparator(separator)(original, num) case DEFAULTGETTER => DefaultGetterName(readName(), readNat()) case VARIANT => @@ -67,7 +73,7 @@ class TastyUnpickler(reader: TastyReader) { if (sig == Signature.NotAMethod) sig = Signature.NotAMethod SignedName(original, sig) case _ => - extractorOfTag(tag)(readName()) + simpleExtractorOfTag(tag)(readName()) } assert(currentAddr == end, s"bad name $result $start $currentAddr $end") result |