Skip to content

Commit 93775dd

Browse files
committed
Turn ClassDenotations into traits
Last step before we can make Symbols inherit from Denotations
1 parent 875c94f commit 93775dd

File tree

2 files changed

+37
-23
lines changed

2 files changed

+37
-23
lines changed

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

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,17 +1601,7 @@ object SymDenotations {
16011601
end children
16021602
}
16031603

1604-
/** The contents of a class definition during a period
1605-
*/
1606-
class ClassDenotation private[SymDenotations] (
1607-
symbol: Symbol,
1608-
maybeOwner: Symbol,
1609-
name: Name,
1610-
initFlags: FlagSet,
1611-
initInfo: Type,
1612-
initPrivateWithin: Symbol)
1613-
extends SymDenotation(symbol, maybeOwner, name, initFlags, initInfo, initPrivateWithin) {
1614-
1604+
trait ClassDenotation extends SymDenotation:
16151605
import util.EqHashMap
16161606

16171607
// ----- caches -------------------------------------------------------
@@ -1687,7 +1677,7 @@ object SymDenotations {
16871677

16881678
// ----- denotation fields and accessors ------------------------------
16891679

1690-
if (initFlags.is(Module, butNot = Package))
1680+
if (flagsUNSAFE.is(Module, butNot = Package))
16911681
assert(name.is(ModuleClassName), s"module naming inconsistency: ${name.debugString}")
16921682

16931683
/** The symbol asserted to have type ClassSymbol */
@@ -2213,19 +2203,24 @@ object SymDenotations {
22132203
override def nestingLevel(using Context) =
22142204
if myNestingLevel == -1 then myNestingLevel = owner.nestingLevel + 1
22152205
myNestingLevel
2216-
}
2206+
end ClassDenotation
22172207

2218-
/** The denotation of a package class.
2219-
* It overrides ClassDenotation to take account of package objects when looking for members
2208+
/** The contents of a class definition during a period
22202209
*/
2221-
final class PackageClassDenotation private[SymDenotations] (
2210+
class ClassDenotationImpl private[SymDenotations] (
22222211
symbol: Symbol,
2223-
ownerIfExists: Symbol,
2212+
maybeOwner: Symbol,
22242213
name: Name,
22252214
initFlags: FlagSet,
22262215
initInfo: Type,
22272216
initPrivateWithin: Symbol)
2228-
extends ClassDenotation(symbol, ownerIfExists, name, initFlags, initInfo, initPrivateWithin) {
2217+
extends SymDenotation(symbol, maybeOwner, name, initFlags, initInfo, initPrivateWithin),
2218+
ClassDenotation
2219+
2220+
/** The denotation of a package class.
2221+
* It overrides ClassDenotation to take account of package objects when looking for members
2222+
*/
2223+
trait PackageClassDenotation extends ClassDenotation:
22292224

22302225
private var packageObjsCache: List[ClassDenotation] = _
22312226
private var packageObjsRunId: RunId = NoRunId
@@ -2383,7 +2378,18 @@ object SymDenotations {
23832378
if (sym.defRunId != ctx.runId && sym.isClass && sym.asClass.assocFile == file)
23842379
scope.unlink(sym, sym.lastKnownDenotation.name)
23852380
}
2386-
}
2381+
end PackageClassDenotation
2382+
2383+
class PackageClassDenotationImpl private[SymDenotations] (
2384+
symbol: Symbol,
2385+
ownerIfExists: Symbol,
2386+
name: Name,
2387+
initFlags: FlagSet,
2388+
initInfo: Type,
2389+
initPrivateWithin: Symbol)
2390+
extends
2391+
ClassDenotationImpl(symbol, ownerIfExists, name, initFlags, initInfo, initPrivateWithin),
2392+
PackageClassDenotation
23872393

23882394
@sharable object NoDenotation
23892395
extends SymDenotation(NoSymbol, NoSymbol, "<none>".toTermName, Permanent, NoType) {
@@ -2428,8 +2434,8 @@ object SymDenotations {
24282434
initPrivateWithin: Symbol = NoSymbol)(using Context): SymDenotation = {
24292435
val result =
24302436
if (symbol.isClass)
2431-
if (initFlags.is(Package)) new PackageClassDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin)
2432-
else new ClassDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin)
2437+
if (initFlags.is(Package)) new PackageClassDenotationImpl(symbol, owner, name, initFlags, initInfo, initPrivateWithin)
2438+
else new ClassDenotationImpl(symbol, owner, name, initFlags, initInfo, initPrivateWithin)
24332439
else new SymDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin)
24342440
result.validFor = currentStablePeriod
24352441
result

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ object Symbols {
4040

4141
opaque type Symbol >: Null <: SymbolDecl = SymbolImpl
4242
opaque type ClassSymbol >: Null <: Symbol & ClassSymbolDecl = ClassSymbolImpl
43+
opaque type PackageSymbol >: Null <: ClassSymbol = PackageClassSymbolImpl
4344

4445
type TermSymbol = Symbol { type ThisName = TermName }
4546
type TypeSymbol = Symbol { type ThisName = TypeName }
@@ -590,6 +591,9 @@ object Symbols {
590591
override protected def prefixString: String = "ClassSymbol"
591592
}
592593

594+
/** Kept separate since it keeps only PackageClassDenotation */
595+
class PackageClassSymbolImpl(id: Int) extends ClassSymbolImpl(NoCoord, null, id)
596+
593597
@sharable
594598
val NoSymbol: Symbol = new SymbolImpl(NoCoord, 0) {
595599
override def associatedFile(using Context): AbstractFile = NoSource.file
@@ -649,7 +653,7 @@ object Symbols {
649653
info: Type,
650654
privateWithin: Symbol = NoSymbol,
651655
coord: Coord = NoCoord)(using Context): Symbol { type ThisName = N } = {
652-
val sym = new Symbol(coord, ctx.base.nextSymId).asInstanceOf[Symbol { type ThisName = N }]
656+
val sym = new SymbolImpl(coord, ctx.base.nextSymId).asInstanceOf[Symbol { type ThisName = N }]
653657
val denot = SymDenotation(sym, owner, name, flags, info, privateWithin)
654658
sym.denot = denot
655659
sym
@@ -667,7 +671,11 @@ object Symbols {
667671
coord: Coord = NoCoord,
668672
assocFile: AbstractFile = null)(using Context): ClassSymbol
669673
= {
670-
val cls = new ClassSymbol(coord, assocFile, ctx.base.nextSymId)
674+
val cls =
675+
if flags.is(Package) then
676+
new PackageClassSymbolImpl(ctx.base.nextSymId)
677+
else
678+
new ClassSymbolImpl(coord, assocFile, ctx.base.nextSymId)
671679
val denot = SymDenotation(cls, owner, name, flags, infoFn(cls), privateWithin)
672680
cls.denot = denot
673681
cls

0 commit comments

Comments
 (0)