Skip to content

Commit 3abe2f0

Browse files
committed
Drop toClassDenot implicit conversion
1 parent 01e2e96 commit 3abe2f0

File tree

12 files changed

+49
-25
lines changed

12 files changed

+49
-25
lines changed

compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
9494

9595
private def setClassInfo(classSym: Symbol, classBType: ClassBType): ClassBType = {
9696
val superClassSym: Symbol = {
97-
val t = classSym.asClass.superClass
97+
val t = classSym.classDenot.superClass
9898
if (t.exists) t
9999
else if (classSym.is(ModuleClass)) {
100100
// workaround #371
@@ -124,7 +124,7 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
124124
def (sym: Symbol).superInterfaces: List[Symbol] = {
125125
val directlyInheritedTraits = sym.directlyInheritedTraits
126126
val directlyInheritedTraitsSet = directlyInheritedTraits.toSet
127-
val allBaseClasses = directlyInheritedTraits.iterator.flatMap(_.asClass.baseClasses.drop(1)).toSet
127+
val allBaseClasses = directlyInheritedTraits.iterator.flatMap(_.classDenot.baseClasses.drop(1)).toSet
128128
val superCalls = superCallsMap.getOrElse(sym, Set.empty)
129129
val additional = (superCalls -- directlyInheritedTraitsSet).filter(_.is(Trait))
130130
// if (additional.nonEmpty)

compiler/src/dotty/tools/dotc/CompilationUnit.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ object CompilationUnit {
7878

7979
class SuspendException extends Exception
8080

81-
/** Make a compilation unit for top class `clsd` with the contents of the `unpickled` tree */
82-
def apply(clsd: ClassDenotation, unpickled: Tree, forceTrees: Boolean)(implicit ctx: Context): CompilationUnit =
83-
apply(new SourceFile(clsd.symbol.associatedFile, Array.empty[Char]), unpickled, forceTrees)
81+
/** Make a compilation unit for top class `cls` with the contents of the `unpickled` tree */
82+
def apply(cls: ClassSymbol, unpickled: Tree, forceTrees: Boolean)(implicit ctx: Context): CompilationUnit =
83+
apply(new SourceFile(cls.associatedFile, Array.empty[Char]), unpickled, forceTrees)
8484

8585
/** Make a compilation unit, given picked bytes and unpickled tree */
8686
def apply(source: SourceFile, unpickled: Tree, forceTrees: Boolean)(implicit ctx: Context): CompilationUnit = {

compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class TreeTypeMap(
6969
case pdef: MemberDef =>
7070
val prevSym = pdef.symbol
7171
val newSym = newStats.head.symbol
72-
val newCls = newSym.owner.asClass
73-
if (prevSym != newSym) newCls.replace(prevSym, newSym)
72+
if prevSym != newSym then
73+
newSym.owner.classDenot.replace(prevSym, newSym)
7474
case _ =>
7575
}
7676
updateDecls(prevStats.tail, newStats.tail)
@@ -191,7 +191,7 @@ class TreeTypeMap(
191191
val mappedDcls = ctx.mapSymbols(origDcls, tmap)
192192
val tmap1 = tmap.withMappedSyms(origDcls, mappedDcls)
193193
if (symsChanged)
194-
origDcls.lazyZip(mappedDcls).foreach(cls.asClass.replace)
194+
origDcls.lazyZip(mappedDcls).foreach(cls.classDenot.replace)
195195
tmap1
196196
}
197197
if (symsChanged || (fullMap eq substMap)) fullMap

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class CheckRealizable(implicit ctx: Context) {
174174
}
175175
}
176176
val baseProblems =
177-
tp.baseClasses.map(_.baseTypeOf(tp)).flatMap(baseTypeProblems)
177+
tp.baseClasses.map(_.classDenot.baseTypeOf(tp)).flatMap(baseTypeProblems)
178178

179179
baseProblems.foldLeft(
180180
refinementProblems.foldLeft(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ object SymbolLoaders {
7777
if (ctx.settings.YtermConflict.value == "package" || ctx.mode.is(Mode.Interactive)) {
7878
ctx.warning(
7979
s"Resolving package/object name conflict in favor of package ${preExisting.fullName}. The object will be inaccessible.")
80-
owner.asClass.delete(preExisting)
80+
owner.classDenot.delete(preExisting)
8181
}
8282
else if (ctx.settings.YtermConflict.value == "object") {
8383
ctx.warning(

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

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Decorators._
1010
import Symbols._
1111
import Contexts._
1212
import SymDenotations._
13+
import Denotations.PreDenotation
1314
import printing.Texts._
1415
import printing.Printer
1516
import Types._
@@ -508,6 +509,9 @@ object Symbols {
508509
final def lastKnownDenotation: SymDenotation =
509510
lastDenot
510511

512+
final def classDenot(using Context): ClassDenotation =
513+
denot.asInstanceOf[ClassDenotation]
514+
511515
private[core] def defRunId: RunId =
512516
if (lastDenot == null) NoRunId else lastDenot.validFor.runId
513517

@@ -590,16 +594,16 @@ object Symbols {
590594
denot.validFor |= InitialPeriod
591595
if (this.is(Module)) this.moduleClass.validFor |= InitialPeriod
592596
}
593-
else owner.ensureFreshScopeAfter(phase)
597+
else owner.classDenot.ensureFreshScopeAfter(phase)
594598
assert(isPrivate || phase.changesMembers, i"$this entered in $owner at undeclared phase $phase")
595599
entered
596600
case _ => this
597601
}
598602

599603
/** Remove symbol from scope of owning class */
600604
final def drop()(implicit ctx: Context): Unit = {
601-
this.owner.asClass.delete(this)
602-
if (this.is(Module)) this.owner.asClass.delete(this.moduleClass)
605+
this.owner.classDenot.delete(this)
606+
if (this.is(Module)) this.owner.classDenot.delete(this.moduleClass)
603607
}
604608

605609
/** Remove symbol from scope of owning class after given `phase`. Create a fresh
@@ -610,7 +614,7 @@ object Symbols {
610614
if (ctx.phaseId != phase.next.id) dropAfter(phase)(ctx.withPhase(phase.next))
611615
else {
612616
assert (!this.owner.is(Package))
613-
this.owner.asClass.ensureFreshScopeAfter(phase)
617+
this.owner.classDenot.ensureFreshScopeAfter(phase)
614618
assert(isPrivate || phase.changesMembers, i"$this deleted in ${this.owner} at undeclared phase $phase")
615619
drop()
616620
}
@@ -818,10 +822,30 @@ object Symbols {
818822
mySource
819823
}
820824

821-
final def classDenot(implicit ctx: Context): ClassDenotation =
822-
denot.asInstanceOf[ClassDenotation]
823-
824825
override protected def prefixString: String = "ClassSymbol"
826+
827+
828+
// ClassDenotation forwarders
829+
final def classInfo(using Context): ClassInfo =
830+
classDenot.classInfo
831+
final def superClass(using Context): Symbol =
832+
classDenot.superClass
833+
final def classParents(using Context): List[Type] =
834+
classDenot.classParents
835+
final def baseClasses(using BaseData, Context): List[ClassSymbol] =
836+
classDenot.baseClasses
837+
final def givenSelfType(using Context): Type =
838+
classDenot.givenSelfType
839+
final def paramAccessors(using Context): List[Symbol] =
840+
classDenot.paramAccessors
841+
final def memberNames(keepOnly: NameFilter)(using MemberNames, Context) =
842+
classDenot.memberNames(keepOnly)
843+
final def membersNamed(name: Name)(using Context): PreDenotation =
844+
classDenot.membersNamed(name)
845+
final def nonPrivateMembersNamed(name: Name)(using Context): PreDenotation =
846+
classDenot.nonPrivateMembersNamed(name)
847+
final def enter(sym: Symbol, scope: Scope = EmptyScope)(using Context): Unit =
848+
classDenot.enter(sym, scope)
825849
}
826850

827851
@sharable object NoSymbol extends Symbol(NoCoord, 0) {
@@ -859,7 +883,7 @@ object Symbols {
859883
implicit def toDenot(sym: Symbol)(implicit ctx: Context): SymDenotation = sym.denot
860884

861885
/** Makes all class denotation operations available on class symbols */
862-
implicit def toClassDenot(cls: ClassSymbol)(implicit ctx: Context): ClassDenotation = cls.classDenot
886+
def toClassDenot(cls: ClassSymbol)(using Context): ClassDenotation = cls.classDenot
863887

864888
/** The Definitions object */
865889
def defn(implicit ctx: Context): Definitions = ctx.definitions

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ class ClassfileParser(
196196
}
197197
else if (result == Some(NoEmbedded))
198198
for (sym <- List(moduleRoot.sourceModule, moduleRoot.symbol, classRoot.symbol)) {
199-
classRoot.owner.asClass.delete(sym)
199+
classRoot.owner.classDenot.delete(sym)
200200
if (classRoot.owner == defn.ScalaShadowingPackage.moduleClass)
201201
// Symbols in scalaShadowing are also added to scala
202-
defn.ScalaPackageClass.delete(sym)
202+
defn.ScalaPackageClass.classDenot.delete(sym)
203203
sym.markAbsent()
204204
}
205205

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Bridges(root: ClassSymbol, thisPhase: DenotTransformer)(implicit ctx: Cont
9494
bridgesScope.enter(bridge)
9595

9696
if (other.owner == root) {
97-
root.delete(other)
97+
root.classDenot.delete(other)
9898
toBeRemoved += other
9999
}
100100

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class MoveStatics extends MiniPhase with SymTransformer {
2626
def transformSym(sym: SymDenotation)(implicit ctx: Context): SymDenotation =
2727
if (sym.hasAnnotation(defn.ScalaStaticAnnot) && sym.owner.is(Flags.Module) && sym.owner.companionClass.exists &&
2828
(sym.is(Flags.Method) || !(sym.is(Flags.Mutable) && sym.owner.companionClass.is(Flags.Trait)))) {
29-
sym.owner.asClass.delete(sym.symbol)
29+
sym.owner.classDenot.delete(sym.symbol)
3030
sym.owner.companionClass.asClass.enter(sym.symbol)
3131
sym.copySymDenotation(owner = sym.owner.companionClass)
3232
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ object TypeTestsCasts {
150150
case _ =>
151151
// always false test warnings are emitted elsewhere
152152
X.classSymbol.exists && P.classSymbol.exists &&
153-
!X.classSymbol.asClass.mayHaveCommonChild(P.classSymbol.asClass) ||
153+
!X.classSymbol.classDenot.mayHaveCommonChild(P.classSymbol.asClass) ||
154154
// first try without striping type parameters for performance
155155
typeArgsTrivial(X, tpe) ||
156156
typeArgsTrivial(stripTypeParam(X), tpe)

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,7 @@ class Namer { typer: Typer =>
13281328
Checking.checkWellFormed(cls)
13291329
if (isDerivedValueClass(cls)) cls.setFlag(Final)
13301330
cls.info = avoidPrivateLeaks(cls)
1331-
cls.baseClasses.foreach(_.invalidateBaseTypeCache()) // we might have looked before and found nothing
1331+
cls.baseClasses.foreach(_.classDenot.invalidateBaseTypeCache()) // we might have looked before and found nothing
13321332
cls.setNoInitsFlags(parentsKind(parents), untpd.bodyKind(rest))
13331333
if (cls.isNoInitsClass) cls.primaryConstructor.setFlag(StableRealizable)
13341334
processExports(localCtx)

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ object RefChecks {
9797
def checkSelfConforms(other: ClassSymbol, category: String, relation: String) = {
9898
val otherSelf = other.declaredSelfTypeAsSeenFrom(cls.thisType)
9999
if otherSelf.exists && !(cinfo.selfType <:< otherSelf) then
100-
ctx.error(DoesNotConformToSelfType(category, cinfo.selfType, cls, otherSelf, relation, other.classSymbol),
100+
ctx.error(DoesNotConformToSelfType(category, cinfo.selfType, cls, otherSelf, relation, other),
101101
cls.sourcePos)
102102
}
103103
for (parent <- cinfo.classParents)

0 commit comments

Comments
 (0)