Skip to content

Commit 8f9b213

Browse files
committed
Decode names of package members on enter
Avoids mutable names and the hassles associated with them.
1 parent fade319 commit 8f9b213

File tree

4 files changed

+6
-26
lines changed

4 files changed

+6
-26
lines changed

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ object SymDenotations {
107107
class SymDenotation private[SymDenotations] (
108108
symbol: Symbol,
109109
ownerIfExists: Symbol,
110-
initName: Name,
110+
val name: Name,
111111
initFlags: FlagSet,
112112
initInfo: Type,
113113
initPrivateWithin: Symbol = NoSymbol) extends SingleDenotation(symbol) {
@@ -125,18 +125,11 @@ object SymDenotations {
125125

126126
// ------ Getting and setting fields -----------------------------
127127

128-
private[this] var myName = initName
129128
private[this] var myFlags: FlagSet = adaptFlags(initFlags)
130129
private[this] var myInfo: Type = initInfo
131130
private[this] var myPrivateWithin: Symbol = initPrivateWithin
132131
private[this] var myAnnotations: List[Annotation] = Nil
133132

134-
/** The name of the symbol */
135-
def name = myName
136-
137-
/** Update the name; only called when unpickling top-level classes */
138-
private[core] def name_=(n: Name) = myName = n
139-
140133
/** The owner of the symbol; overridden in NoDenotation */
141134
def owner: Symbol = ownerIfExists
142135

@@ -1212,12 +1205,12 @@ object SymDenotations {
12121205
class ClassDenotation private[SymDenotations] (
12131206
symbol: Symbol,
12141207
ownerIfExists: Symbol,
1215-
initName: Name,
1208+
name: Name,
12161209
initFlags: FlagSet,
12171210
initInfo: Type,
12181211
initPrivateWithin: Symbol,
12191212
initRunId: RunId)
1220-
extends SymDenotation(symbol, ownerIfExists, initName, initFlags, initInfo, initPrivateWithin) {
1213+
extends SymDenotation(symbol, ownerIfExists, name, initFlags, initInfo, initPrivateWithin) {
12211214

12221215
import util.LRUCache
12231216

@@ -1260,11 +1253,6 @@ object SymDenotations {
12601253
myTypeParams
12611254
}
12621255

1263-
override private[core] def name_=(n: Name) = {
1264-
fullNameCache = SimpleMap.Empty
1265-
super.name_=(n)
1266-
}
1267-
12681256
override protected[dotc] final def info_=(tp: Type) = {
12691257
super.info_=(tp)
12701258
myTypeParams = null // changing the info might change decls, and with it typeParams

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class SymbolLoaders {
4040
def enterClass(
4141
owner: Symbol, name: PreName, completer: SymbolLoader,
4242
flags: FlagSet = EmptyFlags, scope: Scope = EmptyScope)(implicit ctx: Context): Symbol = {
43-
val cls = ctx.newClassSymbol(owner, name.toTypeName, flags, completer, assocFile = completer.sourceFileOrNull)
43+
val cls = ctx.newClassSymbol(owner, name.toTypeName.unmangleClassName.decode, flags, completer, assocFile = completer.sourceFileOrNull)
4444
enterNew(owner, cls, completer, scope)
4545
}
4646

@@ -50,7 +50,7 @@ class SymbolLoaders {
5050
owner: Symbol, name: PreName, completer: SymbolLoader,
5151
modFlags: FlagSet = EmptyFlags, clsFlags: FlagSet = EmptyFlags, scope: Scope = EmptyScope)(implicit ctx: Context): Symbol = {
5252
val module = ctx.newModuleSymbol(
53-
owner, name.toTermName, modFlags, clsFlags,
53+
owner, name.toTermName.decode, modFlags, clsFlags,
5454
(module, _) => completer.proxy withDecls newScope withSourceModule (_ => module),
5555
assocFile = completer.sourceFileOrNull)
5656
enterNew(owner, module, completer, scope)
@@ -166,13 +166,7 @@ class SymbolLoaders {
166166
override def lookupEntry(name: Name)(implicit ctx: Context): ScopeEntry = {
167167
val mangled = name.mangled
168168
val e = super.lookupEntry(mangled)
169-
if (e != null) {
170-
// Eagerly update symbol's name to undecoded name to avpid the name
171-
// spearding to types.
172-
if (name.toSimpleName != mangled && e.sym.initialDenot.name == mangled)
173-
e.sym.initialDenot.name = name
174-
e
175-
}
169+
if (e != null) e
176170
else if (_sourceModule.initialDenot.name == nme.scala_ && _sourceModule == defn.ScalaPackageVal &&
177171
name.isTypeName && name.isSyntheticFunction)
178172
newScopeEntry(defn.newFunctionNTrait(name.asTypeName))

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,6 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
436436
roots.find(root => (root.owner eq ctx.owner) && root.name.mangled == mname) match {
437437
case Some(rootd) =>
438438
pickling.println(i"overwriting ${rootd.symbol} # ${rootd.hashCode}")
439-
rootd.name = name
440439
rootd.info = adjustIfModule(
441440
new Completer(ctx.owner, subReader(start, end)) with SymbolLoaders.SecondCompleter)
442441
rootd.flags = flags &~ Touched // allow one more completion

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
460460
//if (isModuleClassRoot) println(s"moduleClassRoot of $moduleClassRoot found at $readIndex, flags = $flags") // !!! DEBUG
461461

462462
def completeRoot(denot: ClassDenotation, completer: LazyType): Symbol = {
463-
denot.name = name
464463
denot.setFlag(flags)
465464
denot.resetFlag(Touched) // allow one more completion
466465
denot.info = completer

0 commit comments

Comments
 (0)