Skip to content

Commit a8f7572

Browse files
committed
Avoid unnecessary uses of parentSyms
`parentSyms` maps all parent types. We don't need that if we just want to work on the superclass.
1 parent 2eb0303 commit a8f7572

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,19 +1877,21 @@ object SymDenotations {
18771877
super.info_=(tp)
18781878
}
18791879

1880-
/** The symbols of the parent classes. */
1881-
def parentSyms(using Context): List[Symbol] = info match {
1882-
case classInfo: ClassInfo => classInfo.declaredParents.map(_.classSymbol)
1880+
/** The types of the parent classes. */
1881+
def parentTypes(using Context): List[Type] = info match
1882+
case classInfo: ClassInfo => classInfo.declaredParents
18831883
case _ => Nil
1884-
}
1884+
1885+
/** The symbols of the parent classes. */
1886+
def parentSyms(using Context): List[Symbol] =
1887+
parentTypes.map(_.classSymbol)
18851888

18861889
/** The symbol of the superclass, NoSymbol if no superclass exists */
1887-
def superClass(using Context): Symbol = parentSyms match {
1888-
case parent :: _ =>
1889-
if (parent.is(Trait)) NoSymbol else parent
1890-
case _ =>
1891-
NoSymbol
1892-
}
1890+
def superClass(using Context): Symbol = parentTypes match
1891+
case parentType :: _ =>
1892+
val parentCls = parentType.classSymbol
1893+
if parentCls.is(Trait) then NoSymbol else parentCls
1894+
case _ => NoSymbol
18931895

18941896
/** The explicitly given self type (self types of modules are assumed to be
18951897
* explcitly given here).
@@ -1951,20 +1953,20 @@ object SymDenotations {
19511953
def computeBaseData(implicit onBehalf: BaseData, ctx: Context): (List[ClassSymbol], BaseClassSet) = {
19521954
def emptyParentsExpected =
19531955
is(Package) || (symbol == defn.AnyClass) || ctx.erasedTypes && (symbol == defn.ObjectClass)
1954-
val psyms = parentSyms
1955-
if (psyms.isEmpty && !emptyParentsExpected)
1956+
val parents = parentTypes
1957+
if (parents.isEmpty && !emptyParentsExpected)
19561958
onBehalf.signalProvisional()
19571959
val builder = new BaseDataBuilder
1958-
def traverse(parents: List[Symbol]): Unit = parents match {
1960+
def traverse(parents: List[Type]): Unit = parents match {
19591961
case p :: parents1 =>
1960-
p match {
1962+
p.classSymbol match {
19611963
case pcls: ClassSymbol => builder.addAll(pcls.baseClasses)
19621964
case _ => assert(isRefinementClass || p.isError || ctx.mode.is(Mode.Interactive), s"$this has non-class parent: $p")
19631965
}
19641966
traverse(parents1)
19651967
case nil =>
19661968
}
1967-
traverse(psyms)
1969+
traverse(parents)
19681970
(classSymbol :: builder.baseClasses, builder.baseClassSet)
19691971
}
19701972

@@ -2312,9 +2314,11 @@ object SymDenotations {
23122314
var names = Set[Name]()
23132315
def maybeAdd(name: Name) = if (keepOnly(thisType, name)) names += name
23142316
try {
2315-
for (p <- parentSyms if p.isClass)
2316-
for (name <- p.asClass.memberNames(keepOnly))
2317-
maybeAdd(name)
2317+
for ptype <- parentTypes do
2318+
ptype.classSymbol match
2319+
case pcls: ClassSymbol =>
2320+
for name <- pcls.memberNames(keepOnly) do
2321+
maybeAdd(name)
23182322
val ownSyms =
23192323
if (keepOnly eq implicitFilter)
23202324
if (this.is(Package)) Iterator.empty

0 commit comments

Comments
 (0)