Skip to content

Commit 44cb461

Browse files
committed
Use SymbolImpl in all Denotation class parameters
Use SymbolImpl instead of Symbol in all Denotation class parameters. This is necessary to avoid cyclic references when Symbols are made subclasses of SymDenotations.
1 parent a3b542b commit 44cb461

File tree

5 files changed

+40
-33
lines changed

5 files changed

+40
-33
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,11 @@ object Denotations {
176176
*
177177
* @param symbol The referencing symbol, or NoSymbol is none exists
178178
*/
179-
abstract class Denotation(val symbol: Symbol, protected var myInfo: Type) extends PreDenotation with printing.Showable {
179+
abstract class Denotation(_symbol: SymbolImpl, protected var myInfo: Type) extends PreDenotation with printing.Showable {
180180
type AsSeenFromResult <: Denotation
181181

182+
val symbol: Symbol = _symbol.fromSymbolImpl
183+
182184
/** The type info.
183185
* The info is an instance of TypeType iff this is a type denotation
184186
* Uncompleted denotations set myInfo to a LazyType.
@@ -477,7 +479,7 @@ object Denotations {
477479
val jointInfo = infoMeet(info1, info2, safeIntersection)
478480
if jointInfo.exists then
479481
val sym = if symScore >= 0 then sym1 else sym2
480-
JointRefDenotation(sym, jointInfo, denot1.validFor & denot2.validFor, pre)
482+
JointRefDenotation(sym.toSymbolImpl, jointInfo, denot1.validFor & denot2.validFor, pre)
481483
else if symScore == 2 then denot1
482484
else if symScore == -2 then denot2
483485
else
@@ -568,7 +570,7 @@ object Denotations {
568570
end infoMeet
569571

570572
/** A non-overloaded denotation */
571-
abstract class SingleDenotation(symbol: Symbol, initInfo: Type) extends Denotation(symbol, initInfo) {
573+
abstract class SingleDenotation(_symbol: SymbolImpl, initInfo: Type) extends Denotation(_symbol, initInfo) {
572574
protected def newLikeThis(symbol: Symbol, info: Type, pre: Type): SingleDenotation
573575

574576
final def name(using Context): Name = symbol.name
@@ -1077,34 +1079,34 @@ object Denotations {
10771079
}
10781080
}
10791081

1080-
abstract class NonSymSingleDenotation(symbol: Symbol, initInfo: Type, override val prefix: Type) extends SingleDenotation(symbol, initInfo) {
1082+
abstract class NonSymSingleDenotation(_symbol: SymbolImpl, initInfo: Type, override val prefix: Type) extends SingleDenotation(_symbol, initInfo) {
10811083
def infoOrCompleter: Type = initInfo
10821084
def isType: Boolean = infoOrCompleter.isInstanceOf[TypeType]
10831085
}
10841086

10851087
class UniqueRefDenotation(
1086-
symbol: Symbol,
1088+
_symbol: SymbolImpl,
10871089
initInfo: Type,
10881090
initValidFor: Period,
1089-
prefix: Type) extends NonSymSingleDenotation(symbol, initInfo, prefix) {
1091+
prefix: Type) extends NonSymSingleDenotation(_symbol, initInfo, prefix) {
10901092
validFor = initValidFor
10911093
override def hasUniqueSym: Boolean = true
10921094
protected def newLikeThis(s: Symbol, i: Type, pre: Type): SingleDenotation =
1093-
new UniqueRefDenotation(s, i, validFor, pre)
1095+
new UniqueRefDenotation(s.toSymbolImpl, i, validFor, pre)
10941096
}
10951097

10961098
class JointRefDenotation(
1097-
symbol: Symbol,
1099+
_symbol: SymbolImpl,
10981100
initInfo: Type,
10991101
initValidFor: Period,
1100-
prefix: Type) extends NonSymSingleDenotation(symbol, initInfo, prefix) {
1102+
prefix: Type) extends NonSymSingleDenotation(_symbol, initInfo, prefix) {
11011103
validFor = initValidFor
11021104
override def hasUniqueSym: Boolean = false
11031105
protected def newLikeThis(s: Symbol, i: Type, pre: Type): SingleDenotation =
1104-
new JointRefDenotation(s, i, validFor, pre)
1106+
new JointRefDenotation(s.toSymbolImpl, i, validFor, pre)
11051107
}
11061108

1107-
class ErrorDenotation(using Context) extends NonSymSingleDenotation(NoSymbol, NoType, NoType) {
1109+
class ErrorDenotation(using Context) extends NonSymSingleDenotation(NoSymbol.toSymbolImpl, NoType, NoType) {
11081110
override def exists: Boolean = false
11091111
override def hasUniqueSym: Boolean = false
11101112
validFor = Period.allInRun(ctx.runId)
@@ -1171,7 +1173,7 @@ object Denotations {
11711173

11721174
/** An overloaded denotation consisting of the alternatives of both given denotations.
11731175
*/
1174-
case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation(NoSymbol, NoType) with MultiPreDenotation {
1176+
case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation(NoSymbol.toSymbolImpl, NoType) with MultiPreDenotation {
11751177
final def infoOrCompleter: Type = multiHasNot("info")
11761178
final def validFor: Period = denot1.validFor & denot2.validFor
11771179
final def isType: Boolean = false

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,17 @@ object SymDenotations {
3333
* during a period.
3434
*/
3535
class SymDenotation private[SymDenotations] (
36-
symbol: Symbol,
37-
final val maybeOwner: Symbol,
36+
_symbol: SymbolImpl,
37+
final val _maybeOwner: SymbolImpl,
3838
final val name: Name,
3939
initFlags: FlagSet,
4040
initInfo: Type,
41-
initPrivateWithin: Symbol = NoSymbol) extends SingleDenotation(symbol, initInfo) {
41+
initPrivateWithin: SymbolImpl = NoSymbol.toSymbolImpl) extends SingleDenotation(_symbol, initInfo) {
4242

4343
//assert(symbol.id != 4940, name)
4444

45+
final val maybeOwner: Symbol = _maybeOwner.fromSymbolImpl
46+
4547
override def hasUniqueSym: Boolean = exists
4648

4749
/** Debug only
@@ -54,7 +56,7 @@ object SymDenotations {
5456
// ------ Getting and setting fields -----------------------------
5557

5658
private var myFlags: FlagSet = adaptFlags(initFlags)
57-
private var myPrivateWithin: Symbol = initPrivateWithin
59+
private var myPrivateWithin: Symbol = initPrivateWithin.fromSymbolImpl
5860
private var myAnnotations: List[Annotation] = Nil
5961
private var myParamss: List[List[Symbol]] = Nil
6062

@@ -1498,7 +1500,7 @@ object SymDenotations {
14981500
// ----- copies and transforms ----------------------------------------
14991501

15001502
protected def newLikeThis(s: Symbol, i: Type, pre: Type): SingleDenotation =
1501-
new UniqueRefDenotation(s, i, validFor, pre)
1503+
new UniqueRefDenotation(s.toSymbolImpl, i, validFor, pre)
15021504

15031505
/** Copy this denotation, overriding selective fields */
15041506
final def copySymDenotation(
@@ -2208,13 +2210,13 @@ object SymDenotations {
22082210
/** The contents of a class definition during a period
22092211
*/
22102212
class ClassDenotationImpl private[SymDenotations] (
2211-
symbol: Symbol,
2212-
maybeOwner: Symbol,
2213+
_symbol: SymbolImpl,
2214+
_maybeOwner: SymbolImpl,
22132215
name: Name,
22142216
initFlags: FlagSet,
22152217
initInfo: Type,
2216-
initPrivateWithin: Symbol)
2217-
extends SymDenotation(symbol, maybeOwner, name, initFlags, initInfo, initPrivateWithin),
2218+
initPrivateWithin: SymbolImpl)
2219+
extends SymDenotation(_symbol, _maybeOwner, name, initFlags, initInfo, initPrivateWithin),
22182220
ClassDenotation
22192221

22202222
/** The denotation of a package class.
@@ -2381,18 +2383,18 @@ object SymDenotations {
23812383
end PackageClassDenotation
23822384

23832385
class PackageClassDenotationImpl private[SymDenotations] (
2384-
symbol: Symbol,
2385-
ownerIfExists: Symbol,
2386+
_symbol: SymbolImpl,
2387+
_maybeOwner: SymbolImpl,
23862388
name: Name,
23872389
initFlags: FlagSet,
23882390
initInfo: Type,
2389-
initPrivateWithin: Symbol)
2391+
initPrivateWithin: SymbolImpl)
23902392
extends
2391-
ClassDenotationImpl(symbol, ownerIfExists, name, initFlags, initInfo, initPrivateWithin),
2393+
ClassDenotationImpl(_symbol, _maybeOwner, name, initFlags, initInfo, initPrivateWithin),
23922394
PackageClassDenotation
23932395

23942396
@sharable object NoDenotation
2395-
extends SymDenotation(NoSymbol, NoSymbol, "<none>".toTermName, Permanent, NoType) {
2397+
extends SymDenotation(NoSymbol.toSymbolImpl, NoSymbol.toSymbolImpl, "<none>".toTermName, Permanent, NoType) {
23962398
override def isType: Boolean = false
23972399
override def isTerm: Boolean = false
23982400
override def exists: Boolean = false
@@ -2434,9 +2436,9 @@ object SymDenotations {
24342436
initPrivateWithin: Symbol = NoSymbol)(using Context): SymDenotation = {
24352437
val result =
24362438
if (symbol.isClass)
2437-
if (initFlags.is(Package)) new PackageClassDenotationImpl(symbol, owner, name, initFlags, initInfo, initPrivateWithin)
2438-
else new ClassDenotationImpl(symbol, owner, name, initFlags, initInfo, initPrivateWithin)
2439-
else new SymDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin)
2439+
if (initFlags.is(Package)) new PackageClassDenotationImpl(symbol.toSymbolImpl, owner.toSymbolImpl, name, initFlags, initInfo, initPrivateWithin.toSymbolImpl)
2440+
else new ClassDenotationImpl(symbol.toSymbolImpl, owner.toSymbolImpl, name, initFlags, initInfo, initPrivateWithin.toSymbolImpl)
2441+
else new SymDenotation(symbol.toSymbolImpl, owner.toSymbolImpl, name, initFlags, initInfo, initPrivateWithin.toSymbolImpl)
24402442
result.validFor = currentStablePeriod
24412443
result
24422444
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ object Symbols {
4545
type TermSymbol = Symbol { type ThisName = TermName }
4646
type TypeSymbol = Symbol { type ThisName = TypeName }
4747

48+
extension (sym: Symbol) def toSymbolImpl: SymbolImpl = sym
49+
extension (sym: SymbolImpl) def fromSymbolImpl: Symbol = sym
50+
4851
implicit def eqSymbol: CanEqual[Symbol, Symbol] = CanEqual.derived
4952

5053
/** Tree attachment containing the identifiers in a tree as a sorted array */

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ object Types {
757757
}
758758
else
759759
val joint = pdenot.meet(
760-
new JointRefDenotation(NoSymbol, rinfo, Period.allInRun(ctx.runId), pre),
760+
new JointRefDenotation(NoSymbol.toSymbolImpl, rinfo, Period.allInRun(ctx.runId), pre),
761761
pre,
762762
safeIntersection = ctx.base.pendingMemberSearches.contains(name))
763763
joint match
@@ -814,7 +814,7 @@ object Types {
814814
def goSuper(tp: SuperType) = go(tp.underlying) match {
815815
case d: JointRefDenotation =>
816816
typr.println(i"redirecting super.$name from $tp to ${d.symbol.showLocated}")
817-
new UniqueRefDenotation(d.symbol, tp.memberInfo(d.symbol), d.validFor, pre)
817+
new UniqueRefDenotation(d.symbol.toSymbolImpl, tp.memberInfo(d.symbol), d.validFor, pre)
818818
case d => d
819819
}
820820

@@ -4681,7 +4681,7 @@ object Types {
46814681
// also other information about the named type (e.g. bounds).
46824682
contains(
46834683
TypeRef(tp.prefix, cls)
4684-
.withDenot(new UniqueRefDenotation(cls, tp, cls.validFor, tp.prefix)))
4684+
.withDenot(new UniqueRefDenotation(cls.toSymbolImpl, tp, cls.validFor, tp.prefix)))
46854685
case _ =>
46864686
lo <:< tp && tp <:< hi
46874687
}

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class Erasure extends Phase with DenotTransformer {
112112
}
113113
case ref: JointRefDenotation =>
114114
new UniqueRefDenotation(
115-
ref.symbol, transformInfo(ref.symbol, ref.symbol.info), ref.validFor, ref.prefix)
115+
ref.symbol.toSymbolImpl, transformInfo(ref.symbol, ref.symbol.info), ref.validFor, ref.prefix)
116116
case _ =>
117117
ref.derivedSingleDenotation(ref.symbol, transformInfo(ref.symbol, ref.symbol.info))
118118
}

0 commit comments

Comments
 (0)