Skip to content

Commit e36bc58

Browse files
committed
Get rid of parentRefs and associated operations
1 parent cce03ce commit e36bc58

18 files changed

+49
-115
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,9 @@ class Definitions {
8080
val typeParam = enterSyntheticTypeParam(cls, paramFlags, paramDecls)
8181
def instantiate(tpe: Type) =
8282
if (tpe.typeParams.nonEmpty) tpe.appliedTo(typeParam.typeRef)
83-
else tpe
84-
val parents = parentConstrs.toList map instantiate
85-
val parentRefs = ctx.normalizeToClassRefs(parents, cls, paramDecls)
86-
denot.info = ClassInfo(ScalaPackageClass.thisType, cls, parentRefs, paramDecls)
83+
else tpe.dealias
84+
val parents = parentConstrs.toList
85+
denot.info = ClassInfo(ScalaPackageClass.thisType, cls, parents, paramDecls)
8786
}
8887
}
8988
newClassSymbol(ScalaPackageClass, name, EmptyFlags, completer).entered
@@ -123,7 +122,7 @@ class Definitions {
123122
if (name.firstPart.startsWith(str.ImplicitFunction)) {
124123
val superTrait =
125124
FunctionType(arity).appliedTo(argParams.map(_.typeRef) ::: resParam.typeRef :: Nil)
126-
(ImplicitMethodType, ctx.normalizeToClassRefs(superTrait :: Nil, cls, decls))
125+
(ImplicitMethodType, superTrait :: Nil)
127126
}
128127
else (MethodType, Nil)
129128
val applyMeth =

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ object SymDenotations {
12231223
info2 match {
12241224
case info2: ClassInfo =>
12251225
info1 match {
1226-
case info1: ClassInfo => info1.classParentsNEW ne info2.classParentsNEW
1226+
case info1: ClassInfo => info1.classParents ne info2.classParents
12271227
case _ => completersMatter
12281228
}
12291229
case _ => completersMatter
@@ -1366,25 +1366,19 @@ object SymDenotations {
13661366
super.info_=(tp)
13671367
}
13681368

1369-
/** The denotations of all parents in this class. */
1370-
def classParentRefs(implicit ctx: Context): List[TypeRef] = info match {
1371-
case classInfo: ClassInfo => classInfo.parentRefs
1372-
case _ => Nil
1373-
}
1374-
1375-
/** The denotations of all parents in this class. */
1369+
/** The denotations of all parents in this class. */
13761370
def classParentsWithArgs(implicit ctx: Context): List[Type] = info match {
13771371
case classInfo: ClassInfo => classInfo.parentsWithArgs
13781372
case _ => Nil
13791373
}
13801374

1381-
def classParentsNEW(implicit ctx: Context): List[Type] = info match {
1375+
def classParents(implicit ctx: Context): List[Type] = info match {
13821376
case classInfo: ClassInfo => classInfo.parentsNEW
13831377
case _ => Nil
13841378
}
13851379

13861380
/** The symbol of the superclass, NoSymbol if no superclass exists */
1387-
def superClass(implicit ctx: Context): Symbol = classParentsNEW match {
1381+
def superClass(implicit ctx: Context): Symbol = classParents match {
13881382
case parent :: _ =>
13891383
val cls = parent.classSymbol
13901384
if (cls is Trait) NoSymbol else cls
@@ -1457,10 +1451,13 @@ object SymDenotations {
14571451
def computeBaseData(implicit onBehalf: BaseData, ctx: Context): (List[ClassSymbol], BaseClassSet) = {
14581452
def emptyParentsExpected =
14591453
is(Package) || (symbol == defn.AnyClass) || ctx.erasedTypes && (symbol == defn.ObjectClass)
1460-
if (classParentsNEW.isEmpty && !emptyParentsExpected)
1454+
if (classParents.isEmpty && !emptyParentsExpected)
14611455
onBehalf.signalProvisional()
14621456
val builder = new BaseDataBuilder
1463-
for (p <- classParentsNEW) builder.addAll(p.typeSymbol.asClass.baseClasses)
1457+
for (p <- classParents) {
1458+
assert(p.typeSymbol.isClass, s"$this has $p")
1459+
builder.addAll(p.typeSymbol.asClass.baseClasses)
1460+
}
14641461
(classSymbol :: builder.baseClasses, builder.baseClassSet)
14651462
}
14661463

@@ -1601,7 +1598,7 @@ object SymDenotations {
16011598
denots
16021599
}
16031600
if (name.isConstructorName) ownDenots
1604-
else collect(ownDenots, classParentsNEW)
1601+
else collect(ownDenots, classParents)
16051602
}
16061603

16071604
override final def findMember(name: Name, pre: Type, excluded: FlagSet)(implicit ctx: Context): Denotation = {
@@ -1659,7 +1656,7 @@ object SymDenotations {
16591656
case _ => false
16601657
}
16611658
if (isOwnThis)
1662-
if (clsd.baseClassSet.contains(symbol)) foldGlb(NoType, clsd.classParentsNEW)
1659+
if (clsd.baseClassSet.contains(symbol)) foldGlb(NoType, clsd.classParents)
16631660
else NoType
16641661
else
16651662
baseTypeOf(clsd.typeRef).asSeenFrom(prefix, owner)
@@ -1737,7 +1734,7 @@ object SymDenotations {
17371734
def computeMemberNames(keepOnly: NameFilter)(implicit onBehalf: MemberNames, ctx: Context): Set[Name] = {
17381735
var names = Set[Name]()
17391736
def maybeAdd(name: Name) = if (keepOnly(thisType, name)) names += name
1740-
for (p <- classParentsNEW)
1737+
for (p <- classParents)
17411738
for (name <- p.typeSymbol.asClass.memberNames(keepOnly))
17421739
maybeAdd(name)
17431740
val ownSyms =

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ trait Symbols { this: Context =>
123123
def complete(denot: SymDenotation)(implicit ctx: Context): Unit = {
124124
val cls = denot.asClass.classSymbol
125125
val decls = newScope
126-
val parentRefs = normalizeToClassRefs(parentTypes, cls, decls)
127-
denot.info = ClassInfo(owner.thisType, cls, parentRefs, decls)
126+
denot.info = ClassInfo(owner.thisType, cls, parentTypes.map(_.dealias), decls)
128127
}
129128
}
130129
newClassSymbol(owner, name, flags, completer, privateWithin, coord, assocFile)

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

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -271,54 +271,6 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
271271
parents.mapConserve(_.dealias) // !@@@ track and eliminate usages?
272272
}
273273

274-
/** Forward parameter bindings in baseclasses to argument types of
275-
* class `cls` if possible.
276-
* If there have member definitions
277-
*
278-
* type param v= middle
279-
* type middle v= to
280-
*
281-
* where the variances of both alias are the same, then enter a new definition
282-
*
283-
* type param v= to
284-
*
285-
* If multiple forwarders would be generated, join their `to` types with an `&`.
286-
*
287-
* @param cls The class for which parameter bindings should be forwarded
288-
* @param decls Its scope
289-
* @param parentRefs The parent type references of `cls`
290-
* @param paramBindings The type parameter bindings generated for `cls`
291-
*
292-
*/
293-
def forwardParamBindings(parentRefs: List[TypeRef],
294-
paramBindings: SimpleMap[TypeName, Type],
295-
cls: ClassSymbol, decls: Scope)(implicit ctx: Context) = {
296-
297-
def forwardRef(argSym: Symbol, from: TypeName, to: TypeAlias) = argSym.info match {
298-
case info @ TypeAlias(TypeRef(_: ThisType, `from`)) if info.variance == to.variance =>
299-
val existing = decls.lookup(argSym.name)
300-
if (existing.exists) existing.info = existing.info & to
301-
else enterArgBinding(argSym, to, cls, decls)
302-
case _ =>
303-
}
304-
305-
def forwardRefs(from: TypeName, to: Type) = to match {
306-
case to: TypeAlias =>
307-
for (pref <- parentRefs) {
308-
def forward()(implicit ctx: Context): Unit =
309-
for (argSym <- pref.decls)
310-
if (argSym is BaseTypeArg) forwardRef(argSym, from, to)
311-
pref.info match {
312-
case info: TempClassInfo => info.addSuspension(implicit ctx => forward())
313-
case _ => forward()
314-
}
315-
}
316-
case _ =>
317-
}
318-
319-
paramBindings.foreachBinding(forwardRefs)
320-
}
321-
322274
/** An argument bounds violation is a triple consisting of
323275
* - the argument tree
324276
* - a string "upper" or "lower" indicating which bound is violated

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

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,15 +1193,6 @@ object Types {
11931193
NoType
11941194
}
11951195

1196-
/** For a ClassInfo type, its parents,
1197-
* Inherited by all type proxies. Empty for all other types.
1198-
* Overwritten in ClassInfo, where parents is cached.
1199-
*/
1200-
def parentRefs(implicit ctx: Context): List[TypeRef] = this match {
1201-
case tp: TypeProxy => tp.underlying.parentRefs
1202-
case _ => Nil
1203-
}
1204-
12051196
/** The full parent types, including all type arguments */
12061197
def parentsWithArgs(implicit ctx: Context): List[Type] = this match {
12071198
case tp: TypeProxy => tp.superType.parentsWithArgs
@@ -1224,8 +1215,8 @@ object Types {
12241215
}
12251216

12261217
/** The first parent of this type, AnyRef if list of parents is empty */
1227-
def firstParentRef(implicit ctx: Context): TypeRef = parentRefs match {
1228-
case p :: _ => p
1218+
def firstParentRef(implicit ctx: Context): TypeRef = parentsNEW match { // @!!! needed?
1219+
case p :: _ => p.typeConstructor.asInstanceOf[TypeRef]
12291220
case _ => defn.AnyType
12301221
}
12311222

@@ -3559,7 +3550,7 @@ object Types {
35593550
abstract case class ClassInfo(
35603551
prefix: Type,
35613552
cls: ClassSymbol,
3562-
classParentsNEW: List[Type],
3553+
classParents: List[Type],
35633554
decls: Scope,
35643555
selfInfo: DotClass /* should be: Type | Symbol */) extends CachedGroundType with TypeType {
35653556

@@ -3622,30 +3613,26 @@ object Types {
36223613
// cached because baseType needs parents
36233614
private var parentsCache: List[Type] = null
36243615

3625-
/** The parent type refs as seen from the given prefix */
3626-
override def parentRefs(implicit ctx: Context): List[TypeRef] =
3627-
parentsNEW.map(_.typeConstructor.asInstanceOf[TypeRef])
3628-
36293616
/** The parent types with all type arguments */
36303617
override def parentsWithArgs(implicit ctx: Context): List[Type] = parentsNEW
36313618

36323619
override def parentsNEW(implicit ctx: Context): List[Type] = {
36333620
if (parentsCache == null)
3634-
parentsCache = classParentsNEW.mapConserve(_.asSeenFrom(prefix, cls.owner))
3621+
parentsCache = classParents.mapConserve(_.asSeenFrom(prefix, cls.owner))
36353622
parentsCache
36363623
}
36373624

36383625
def derivedClassInfo(prefix: Type)(implicit ctx: Context) =
36393626
if (prefix eq this.prefix) this
3640-
else ClassInfo(prefix, cls, classParentsNEW, decls, selfInfo)
3627+
else ClassInfo(prefix, cls, classParents, decls, selfInfo)
36413628

3642-
def derivedClassInfo(prefix: Type = this.prefix, classParentsNEW: List[Type] = this.classParentsNEW, decls: Scope = this.decls, selfInfo: DotClass = this.selfInfo)(implicit ctx: Context) =
3643-
if ((prefix eq this.prefix) && (classParentsNEW eq this.classParentsNEW) && (decls eq this.decls) && (selfInfo eq this.selfInfo)) this
3644-
else ClassInfo(prefix, cls, classParentsNEW, decls, selfInfo)
3629+
def derivedClassInfo(prefix: Type = this.prefix, classParents: List[Type] = this.classParents, decls: Scope = this.decls, selfInfo: DotClass = this.selfInfo)(implicit ctx: Context) =
3630+
if ((prefix eq this.prefix) && (classParents eq this.classParents) && (decls eq this.decls) && (selfInfo eq this.selfInfo)) this
3631+
else ClassInfo(prefix, cls, classParents, decls, selfInfo)
36453632

36463633
override def computeHash = doHash(cls, prefix)
36473634

3648-
override def toString = s"ClassInfo($prefix, $cls, $classParentsNEW)"
3635+
override def toString = s"ClassInfo($prefix, $cls, $classParents)"
36493636
}
36503637

36513638
class CachedClassInfo(prefix: Type, cls: ClassSymbol, classParents: List[Type], decls: Scope, selfInfo: DotClass)
@@ -3663,9 +3650,9 @@ object Types {
36633650

36643651
def addSuspension(suspension: Context => Unit): Unit = suspensions ::= suspension
36653652

3666-
/** Install classinfo with known parents in `denot` and resume all suspensions */
3653+
/** Install classinfo with known parents in `denot` and resume all suspensions */ // @!!! elim
36673654
def finalize(denot: SymDenotation, parents: List[Type])(implicit ctx: Context) = {
3668-
denot.info = derivedClassInfo(classParentsNEW = parents)
3655+
denot.info = derivedClassInfo(classParents = parents)
36693656
suspensions.foreach(_(ctx))
36703657
}
36713658

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,14 +731,14 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
731731
case _ => readTpt()
732732
}
733733
}
734-
val parentRefs = ctx.normalizeToClassRefs(parents.map(_.tpe), cls, cls.unforcedDecls)
734+
val parentTypes = parents.map(_.tpe.dealias)
735735
val self =
736736
if (nextByte == SELFDEF) {
737737
readByte()
738738
untpd.ValDef(readName(), readTpt(), EmptyTree).withType(NoType)
739739
}
740740
else EmptyValDef
741-
cls.info = ClassInfo(cls.owner.thisType, cls, parentRefs, cls.unforcedDecls,
741+
cls.info = ClassInfo(cls.owner.thisType, cls, parentTypes, cls.unforcedDecls,
742742
if (self.isEmpty) NoType else self.tpt.tpe)
743743
cls.setNoInitsFlags(fork.indexStats(end))
744744
val constr = readIndexedDef().asInstanceOf[DefDef]

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ object Scala2Unpickler {
9999
else selfInfo
100100
val tempInfo = new TempClassInfo(denot.owner.thisType, denot.classSymbol, decls, ost)
101101
denot.info = tempInfo // first rough info to avoid CyclicReferences
102-
var parentRefs = ctx.normalizeToClassRefs(parents, cls, decls)
103-
if (parentRefs.isEmpty) parentRefs = defn.ObjectType :: Nil
102+
val normalizedParents =
103+
if (parents.isEmpty) defn.ObjectType :: Nil
104+
else parents.map(_.dealias)
104105
for (tparam <- tparams) {
105106
val tsym = decls.lookup(tparam.name)
106107
if (tsym.exists) tsym.setFlag(TypeParam)
@@ -124,7 +125,7 @@ object Scala2Unpickler {
124125
registerCompanionPair(scalacCompanion, denot.classSymbol)
125126
}
126127

127-
tempInfo.finalize(denot, parentRefs) // install final info, except possibly for typeparams ordering
128+
tempInfo.finalize(denot, normalizedParents) // install final info, except possibly for typeparams ordering
128129
denot.ensureTypeParamsInCorrectOrder()
129130
}
130131
}

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ object messages {
12731273
val msg = hl"""|$qual does not name a parent of $cls"""
12741274
val kind = "Reference"
12751275

1276-
private val parents: Seq[String] = (cls.info.parentRefs map (_.name.show)).sorted
1276+
private val parents: Seq[String] = (cls.info.parentsNEW map (_.typeSymbol.name.show)).sorted
12771277

12781278
val explanation =
12791279
hl"""|When a qualifier ${"T"} is used in a ${"super"} prefix of the form ${"C.super[T]"},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class CheckReentrant extends MiniPhaseTransform { thisTransformer =>
8181
sym.info.widenExpr.classSymbols.foreach(addVars)
8282
}
8383
}
84-
for (parent <- cls.classInfo.classParentsNEW)
84+
for (parent <- cls.classInfo.classParents)
8585
addVars(parent.typeSymbol.asClass)
8686
}
8787
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class ExtensionMethods extends MiniPhaseTransform with DenotTransformer with Ful
102102
moduleClassSym.copySymDenotation(info =
103103
cinfo.derivedClassInfo(
104104
// FIXME: use of VC*Companion superclasses is disabled until the conflicts with SyntheticMethods are solved.
105-
//classParents = ctx.normalizeToClassRefs(List(newSuperClass), moduleSym, decls1),
105+
//classParents = List(newSuperClass)
106106
decls = decls1))
107107
case _ =>
108108
moduleClassSym

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
251251

252252
// Add Child annotation to sealed parents unless current class is anonymous
253253
if (!sym.isAnonymousClass) // ignore anonymous class
254-
sym.asClass.classParentsNEW.foreach { parent =>
254+
sym.asClass.classParents.foreach { parent =>
255255
val sym2 = if (sym.is(Module)) sym.sourceModule else sym
256256
registerChild(sym2, parent)
257257
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ object Checking {
455455
case tp: ClassInfo =>
456456
tp.derivedClassInfo(
457457
prefix = apply(tp.prefix),
458-
classParentsNEW =
458+
classParents =
459459
tp.parentsWithArgs.map { p =>
460460
apply(p).stripAnnots match {
461461
case ref: RefType => ref

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ trait ImplicitRunInfo { self: RunInfo =>
436436
iscopeRefs(tp.baseType(parent.typeSymbol)) foreach addRef
437437
val companion = cls.companionModule
438438
if (companion.exists) addRef(companion.valRef)
439-
cls.classParentsNEW foreach addParentScope
439+
cls.classParents foreach addParentScope
440440
}
441441
tp.classSymbols(liftingCtx) foreach addClassScope
442442
case _ =>

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ class Namer { typer: Typer =>
860860
* (4) If the class is sealed, it is defined in the same compilation unit as the current class
861861
*/
862862
def checkedParentType(parent: untpd.Tree): Type = {
863-
val ptype = parentType(parent)(ctx.superCallContext)
863+
val ptype = parentType(parent)(ctx.superCallContext).dealias
864864
if (cls.isRefinementClass) ptype
865865
else {
866866
val pt = checkClassType(ptype, parent.pos,
@@ -914,10 +914,9 @@ class Namer { typer: Typer =>
914914
symbolOfTree(constr).ensureCompleted()
915915

916916
val parentTypes = ensureFirstIsClass(parents.map(checkedParentType(_)), cls.pos)
917-
val parentRefs = ctx.normalizeToClassRefs(parentTypes, cls, decls)
918-
typr.println(i"completing $denot, parents = $parents%, %, parentTypes = $parentTypes%, %, parentRefs = $parentRefs%, %")
917+
typr.println(i"completing $denot, parents = $parents%, %, parentTypes = $parentTypes%, %")
919918

920-
tempInfo.finalize(denot, parentRefs)
919+
tempInfo.finalize(denot, parentTypes)
921920

922921
Checking.checkWellFormed(cls)
923922
if (isDerivedValueClass(cls)) cls.setFlag(Final)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ object RefChecks {
102102
ctx.error(DoesNotConformToSelfType(category, cinfo.selfType, cls, otherSelf, relation, other.classSymbol),
103103
cls.pos)
104104
}
105-
for (parent <- cinfo.classParentsNEW)
105+
for (parent <- cinfo.classParents)
106106
checkSelfConforms(parent.typeSymbol.asClass, "illegal inheritance", "parent")
107107
for (reqd <- cinfo.cls.givenSelfType.classSymbols)
108108
checkSelfConforms(reqd, "missing requirement", "required")

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,9 @@ trait TypeAssigner {
308308
case err: ErrorType => untpd.cpy.Super(tree)(qual, mix).withType(err)
309309
case qtype @ ThisType(_) =>
310310
val cls = qtype.cls
311-
def findMixinSuper(site: Type): Type = site.parentRefs filter (_.name == mix.name) match {
311+
def findMixinSuper(site: Type): Type = site.parentsNEW filter (_.typeSymbol.name == mix.name) match {
312312
case p :: Nil =>
313-
p
313+
p.typeConstructor
314314
case Nil =>
315315
errorType(SuperQualMustBeParent(mix, cls), tree.pos)
316316
case p :: q :: _ =>

0 commit comments

Comments
 (0)