Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate newNakedSymbol methods #13641

Merged
merged 1 commit into from
Oct 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 17 additions & 49 deletions compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -506,21 +506,6 @@ object Symbols {
def MutableSymbolMap[T](): EqHashMap[Symbol, T] = EqHashMap[Symbol, T]()
def MutableSymbolMap[T](initialCapacity: Int): EqHashMap[Symbol, T] = EqHashMap[Symbol, T](initialCapacity)

// ---- Factory methods for symbol creation ----------------------
//
// All symbol creations should be done via the next two methods.

/** Create a symbol without a denotation.
* Note this uses a cast instead of a direct type refinement because
* it's debug-friendlier not to create an anonymous class here.
*/
def newNakedSymbol[N <: Name](coord: Coord = NoCoord)(using Context): Symbol { type ThisName = N } =
new Symbol(coord, ctx.base.nextSymId).asInstanceOf[Symbol { type ThisName = N }]

/** Create a class symbol without a denotation. */
def newNakedClassSymbol(coord: Coord = NoCoord, assocFile: AbstractFile = null)(using Context): ClassSymbol =
new ClassSymbol(coord, assocFile, ctx.base.nextSymId)

// ---- Symbol creation methods ----------------------------------

/** Create a symbol from its fields (info may be lazy) */
Expand All @@ -531,20 +516,12 @@ object Symbols {
info: Type,
privateWithin: Symbol = NoSymbol,
coord: Coord = NoCoord)(using Context): Symbol { type ThisName = N } = {
val sym = newNakedSymbol[N](coord)
val sym = new Symbol(coord, ctx.base.nextSymId).asInstanceOf[Symbol { type ThisName = N }]
val denot = SymDenotation(sym, owner, name, flags, info, privateWithin)
sym.denot = denot
sym
}

/** Create a class symbol from a function producing its denotation */
def newClassSymbolDenoting(denotFn: ClassSymbol => SymDenotation,
coord: Coord = NoCoord, assocFile: AbstractFile = null)(using Context): ClassSymbol = {
val cls = newNakedClassSymbol(coord, assocFile)
cls.denot = denotFn(cls)
cls
}

/** Create a class symbol from its non-info fields and a function
* producing its info (the produced info may be lazy).
*/
Expand All @@ -557,7 +534,7 @@ object Symbols {
coord: Coord = NoCoord,
assocFile: AbstractFile = null)(using Context): ClassSymbol
= {
val cls = newNakedClassSymbol(coord, assocFile)
val cls = new ClassSymbol(coord, assocFile, ctx.base.nextSymId)
val denot = SymDenotation(cls, owner, name, flags, infoFn(cls), privateWithin)
cls.denot = denot
cls
Expand Down Expand Up @@ -620,19 +597,15 @@ object Symbols {
assocFile: AbstractFile = null)(using Context): TermSymbol
= {
val base = owner.thisType
val module = newNakedSymbol[TermName](coord)
val modcls = newNakedClassSymbol(coord, assocFile)
val modclsFlags = clsFlags | ModuleClassCreationFlags
val modclsName = name.toTypeName.adjustIfModuleClass(modclsFlags)
val cdenot = SymDenotation(
modcls, owner, modclsName, modclsFlags,
infoFn(module, modcls), privateWithin)
val mdenot = SymDenotation(
module, owner, name, modFlags | ModuleValCreationFlags,
if (cdenot.isCompleted) TypeRef(owner.thisType, modcls)
else new ModuleCompleter(modcls))
module.denot = mdenot
modcls.denot = cdenot
val module = newSymbol(
owner, name, modFlags | ModuleValCreationFlags, NoCompleter, privateWithin, coord)
val modcls = newClassSymbol(
owner, modclsName, modclsFlags, infoFn(module, _), privateWithin, coord, assocFile)
module.info =
if (modcls.isCompleted) TypeRef(owner.thisType, modcls)
else new ModuleCompleter(modcls)
module
}

Expand Down Expand Up @@ -802,12 +775,13 @@ object Symbols {
originals
else {
val copies: List[Symbol] = for (original <- originals) yield
original match {
case original: ClassSymbol =>
newNakedClassSymbol(original.coord, original.assocFile)
case _ =>
newNakedSymbol[original.ThisName](original.coord)
}
val odenot = original.denot
original.copy(
owner = ttmap.mapOwner(odenot.owner),
flags = odenot.flags &~ Touched,
info = NoCompleter,
privateWithin = ttmap.mapOwner(odenot.privateWithin),
coord = original.coord)
val ttmap1 = ttmap.withSubstitution(originals, copies)
originals.lazyZip(copies) foreach { (original, copy) =>
val odenot = original.denot
Expand Down Expand Up @@ -845,13 +819,7 @@ object Symbols {

end completer

copy.denot = odenot.copySymDenotation(
symbol = copy,
owner = ttmap1.mapOwner(odenot.owner),
initFlags = odenot.flags &~ Touched,
info = completer,
privateWithin = ttmap1.mapOwner(odenot.privateWithin), // since this refers to outer symbols, need not include copies (from->to) in ownermap here.
annotations = odenot.annotations)
copy.info = completer
copy.denot match
case cd: ClassDenotation =>
cd.registeredCompanion = cd.unforcedRegisteredCompanion.subst(originals, copies)
Expand Down