Skip to content

Commit 140fac3

Browse files
committed
Adapt operations in Types
So far, everything up to parents is adapted to new scheme. Parents is half done; needs more work once we change layour of ClassInfo.
1 parent 5f8820c commit 140fac3

File tree

11 files changed

+66
-36
lines changed

11 files changed

+66
-36
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
213213
ta.assignType(untpd.TypeDef(sym.name, TypeTree(sym.info)), sym)
214214

215215
def ClassDef(cls: ClassSymbol, constr: DefDef, body: List[Tree], superArgs: List[Tree] = Nil)(implicit ctx: Context): TypeDef = {
216-
val firstParentRef :: otherParentRefs = cls.info.parents
216+
val firstParentRef :: otherParentRefs = cls.info.parentRefs
217217
val firstParent = cls.typeRef.baseTypeWithArgs(firstParentRef.symbol)
218218
val superRef =
219219
if (cls is Trait) TypeTree(firstParent)
@@ -261,7 +261,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
261261
def AnonClass(parents: List[Type], fns: List[TermSymbol], methNames: List[TermName])(implicit ctx: Context): Block = {
262262
val owner = fns.head.owner
263263
val parents1 =
264-
if (parents.head.classSymbol.is(Trait)) parents.head.parents.head :: parents
264+
if (parents.head.classSymbol.is(Trait)) parents.head.parentRefs.head :: parents
265265
else parents
266266
val cls = ctx.newNormalizedClassSymbol(owner, tpnme.ANON_FUN, Synthetic, parents1,
267267
coord = fns.map(_.pos).reduceLeft(_ union _))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,7 @@ object SymDenotations {
16201620
tp
16211621
else subcls.denot match {
16221622
case cdenot: ClassDenotation =>
1623-
if (cdenot.baseClassSet contains symbol) foldGlb(NoType, tp.parents)
1623+
if (cdenot.baseClassSet contains symbol) foldGlb(NoType, tp.parentsNEW) // !!! change to parents
16241624
else NoType
16251625
case _ =>
16261626
baseTypeOf(tp.superType)

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

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,10 @@ object Types {
129129
case TypeAlias(tp) =>
130130
assert((tp ne this) && (tp ne this1), s"$tp / $this")
131131
tp.isRef(sym)
132-
case _ => this1.symbol eq sym
132+
case _ => this1.symbol eq sym
133133
}
134134
case this1: RefinedOrRecType => this1.parent.isRef(sym)
135+
case this1: AppliedType => this1.underlying.isRef(sym)
135136
case this1: HKApply => this1.superType.isRef(sym)
136137
case _ => false
137138
}
@@ -210,7 +211,7 @@ object Types {
210211
*/
211212
private final def phantomLatticeType(implicit ctx: Context): Type = widen match {
212213
case tp: ClassInfo if defn.isPhantomTerminalClass(tp.classSymbol) => tp.prefix
213-
case tp: TypeProxy if tp.superType ne this => tp.underlying.phantomLatticeType
214+
case tp: TypeProxy if tp.superType ne this => tp.underlying.phantomLatticeType // ??? guard needed ???
214215
case tp: AndOrType => tp.tp1.phantomLatticeType
215216
case _ => NoType
216217
}
@@ -483,6 +484,8 @@ object Types {
483484
})
484485
case tp: TypeRef =>
485486
tp.denot.findMember(name, pre, excluded)
487+
case tp: AppliedType =>
488+
goApplied(tp)
486489
case tp: ThisType =>
487490
goThis(tp)
488491
case tp: RefinedType =>
@@ -494,7 +497,7 @@ object Types {
494497
case tp: SuperType =>
495498
goSuper(tp)
496499
case tp: HKApply =>
497-
goApply(tp)
500+
goHKApply(tp)
498501
case tp: TypeProxy =>
499502
go(tp.underlying)
500503
case tp: ClassInfo =>
@@ -584,7 +587,15 @@ object Types {
584587
}
585588
}
586589

587-
def goApply(tp: HKApply) = tp.tycon match {
590+
def goApplied(tp: AppliedType) = tp.tycon match {
591+
case tl: HKTypeLambda =>
592+
go(tl.resType).mapInfo(info =>
593+
tl.derivedLambdaAbstraction(tl.paramNames, tl.paramInfos, info).appliedTo(tp.args))
594+
case _ =>
595+
go(tp.superType)
596+
}
597+
598+
def goHKApply(tp: HKApply) = tp.tycon match {
588599
case tl: HKTypeLambda =>
589600
go(tl.resType).mapInfo(info =>
590601
tl.derivedLambdaAbstraction(tl.paramNames, tl.paramInfos, info).appliedTo(tp.args))
@@ -963,6 +974,14 @@ object Types {
963974
case TypeAlias(tp) => tp.dealias(keepAnnots): @tailrec
964975
case _ => tp
965976
}
977+
case app @ AppliedType(tycon, args) =>
978+
val tycon1 = tycon.dealias(keepAnnots)
979+
if (tycon1 ne tycon) app.superType.dealias(keepAnnots): @tailrec
980+
else this
981+
case app @ HKApply(tycon, args) =>
982+
val tycon1 = tycon.dealias(keepAnnots)
983+
if (tycon1 ne tycon) app.superType.dealias(keepAnnots): @tailrec
984+
else this
966985
case tp: TypeVar =>
967986
val tp1 = tp.instanceOpt
968987
if (tp1.exists) tp1.dealias(keepAnnots): @tailrec else tp
@@ -971,10 +990,6 @@ object Types {
971990
if (keepAnnots) tp.derivedAnnotatedType(tp1, tp.annot) else tp1
972991
case tp: LazyRef =>
973992
tp.ref.dealias(keepAnnots): @tailrec
974-
case app @ HKApply(tycon, args) =>
975-
val tycon1 = tycon.dealias(keepAnnots)
976-
if (tycon1 ne tycon) app.superType.dealias(keepAnnots): @tailrec
977-
else this
978993
case _ => this
979994
}
980995

@@ -1021,6 +1036,8 @@ object Types {
10211036
if (tp.symbol.isClass) tp
10221037
else if (tp.symbol.isAliasType) tp.underlying.underlyingClassRef(refinementOK)
10231038
else NoType
1039+
case tp: AppliedType =>
1040+
tp.superType.underlyingClassRef(refinementOK)
10241041
case tp: AnnotatedType =>
10251042
tp.underlying.underlyingClassRef(refinementOK)
10261043
case tp: RefinedType =>
@@ -1158,19 +1175,33 @@ object Types {
11581175
* Inherited by all type proxies. Empty for all other types.
11591176
* Overwritten in ClassInfo, where parents is cached.
11601177
*/
1161-
def parents(implicit ctx: Context): List[TypeRef] = this match {
1162-
case tp: TypeProxy => tp.underlying.parents
1163-
case _ => List()
1178+
def parentRefs(implicit ctx: Context): List[TypeRef] = this match {
1179+
case tp: TypeProxy => tp.underlying.parentRefs
1180+
case _ => Nil
11641181
}
11651182

11661183
/** The full parent types, including all type arguments */
11671184
def parentsWithArgs(implicit ctx: Context): List[Type] = this match {
11681185
case tp: TypeProxy => tp.superType.parentsWithArgs
1169-
case _ => List()
1186+
case _ => Nil
1187+
}
1188+
1189+
/** The full parent types, including (in new scheme) all type arguments */
1190+
def parentsNEW(implicit ctx: Context): List[Type] = this match {
1191+
case AppliedType(tycon: HKTypeLambda, args) => // TODO: can be eliminated once ClassInfo is changed, also: cache?
1192+
tycon.resType.parentsWithArgs.map(_.substParams(tycon, args))
1193+
case tp: TypeProxy => tp.superType.parentsNEW
1194+
case _ => Nil
1195+
}
1196+
1197+
/** The first parent of this type, AnyRef if list of parents is empty */
1198+
def firstParentRef(implicit ctx: Context): TypeRef = parentRefs match {
1199+
case p :: _ => p
1200+
case _ => defn.AnyType
11701201
}
11711202

11721203
/** The first parent of this type, AnyRef if list of parents is empty */
1173-
def firstParent(implicit ctx: Context): TypeRef = parents match {
1204+
def firstParentNEW(implicit ctx: Context): Type = parentsNEW match {
11741205
case p :: _ => p
11751206
case _ => defn.AnyType
11761207
}
@@ -3020,21 +3051,17 @@ object Types {
30203051
override def underlying(implicit ctx: Context): Type = tycon
30213052

30223053
override def superType(implicit ctx: Context): Type = {
3023-
def reapply(tp: Type) = tp match {
3024-
case tp: TypeRef if tp.symbol.isClass => tp
3025-
case _ => tp.applyIfParameterized(args)
3026-
}
30273054
if (ctx.period != validSuper) {
30283055
validSuper = ctx.period
30293056
cachedSuper = tycon match {
30303057
case tp: HKTypeLambda => defn.AnyType
30313058
case tp: TypeVar if !tp.inst.exists =>
30323059
// supertype not stable, since underlying might change
30333060
validSuper = Nowhere
3034-
reapply(tp.underlying)
3061+
tp.underlying.applyIfParameterized(args)
30353062
case tp: TypeProxy =>
30363063
if (tp.typeSymbol.is(Provisional)) validSuper = Nowhere
3037-
reapply(tp.superType)
3064+
tp.superType.applyIfParameterized(args)
30383065
case _ => defn.AnyType
30393066
}
30403067
}
@@ -3441,22 +3468,25 @@ object Types {
34413468
private var parentsCache: List[TypeRef] = null
34423469

34433470
/** The parent type refs as seen from the given prefix */
3444-
override def parents(implicit ctx: Context): List[TypeRef] = {
3471+
override def parentRefs(implicit ctx: Context): List[TypeRef] = {
34453472
if (parentsCache == null)
34463473
parentsCache = cls.classParents.mapConserve(_.asSeenFrom(prefix, cls.owner).asInstanceOf[TypeRef])
34473474
parentsCache
34483475
}
34493476

34503477
/** The parent types with all type arguments */
34513478
override def parentsWithArgs(implicit ctx: Context): List[Type] =
3452-
parents mapConserve { pref =>
3479+
parentRefs mapConserve { pref =>
34533480
((pref: Type) /: pref.classSymbol.typeParams) { (parent, tparam) =>
34543481
val targSym = decls.lookup(tparam.name)
34553482
if (targSym.exists) RefinedType(parent, targSym.name, targSym.info)
34563483
else parent
34573484
}
34583485
}
34593486

3487+
override def parentsNEW(implicit ctx: Context): List[Type] =
3488+
parentRefs // !!! TODO: change
3489+
34603490
def derivedClassInfo(prefix: Type)(implicit ctx: Context) =
34613491
if (prefix eq this.prefix) this
34623492
else ClassInfo(prefix, cls, classParents, decls, selfInfo)
@@ -3929,12 +3959,12 @@ object Types {
39293959
abstract class DeepTypeMap(implicit ctx: Context) extends TypeMap {
39303960
override def mapClassInfo(tp: ClassInfo) = {
39313961
val prefix1 = this(tp.prefix)
3932-
val parents1 = (tp.parents mapConserve this).asInstanceOf[List[TypeRef]]
3962+
val parentRefs1 = (tp.parentRefs mapConserve this).asInstanceOf[List[TypeRef]]
39333963
val selfInfo1 = tp.selfInfo match {
39343964
case selfInfo: Type => this(selfInfo)
39353965
case selfInfo => selfInfo
39363966
}
3937-
tp.derivedClassInfo(prefix1, parents1, tp.decls, selfInfo1)
3967+
tp.derivedClassInfo(prefix1, parentRefs1, tp.decls, selfInfo1)
39383968
}
39393969
}
39403970

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
323323
val declsText =
324324
if (trueDecls.isEmpty || !ctx.settings.debug.value) Text()
325325
else dclsText(trueDecls)
326-
tparamsText ~ " extends " ~ toTextParents(tp.parents) ~ "{" ~ selfText ~ declsText ~
326+
tparamsText ~ " extends " ~ toTextParents(tp.parentsNEW) ~ "{" ~ selfText ~ declsText ~
327327
"} at " ~ preText
328328
case tp =>
329329
": " ~ toTextGlobal(tp)
@@ -401,7 +401,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
401401

402402
def toText(sym: Symbol): Text =
403403
(kindString(sym) ~~ {
404-
if (sym.isAnonymousClass) toText(sym.info.parents, " with ") ~ "{...}"
404+
if (sym.isAnonymousClass) toText(sym.info.parentsNEW, " with ") ~ "{...}"
405405
else if (hasMeaninglessName(sym)) simpleNameString(sym.owner) + idString(sym)
406406
else nameString(sym)
407407
}).close

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

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

1261-
private val parents: Seq[String] = (cls.info.parents map (_.name.show)).sorted
1261+
private val parents: Seq[String] = (cls.info.parentRefs map (_.name.show)).sorted
12621262

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ object Erasure {
391391
cpy.Super(qual)(thisQual, untpd.Ident(sym.owner.asClass.name))
392392
.withType(SuperType(thisType, sym.owner.typeRef))
393393
else
394-
qual.withType(SuperType(thisType, thisType.firstParent))
394+
qual.withType(SuperType(thisType, thisType.firstParentRef))
395395
case _ =>
396396
qual
397397
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ object ExplicitOuter {
194194
needsOuterIfReferenced(cls) &&
195195
(!hasLocalInstantiation(cls) || // needs outer because we might not know whether outer is referenced or not
196196
cls.mixins.exists(needsOuterIfReferenced) || // needs outer for parent traits
197-
cls.classInfo.parents.exists(parent => // needs outer to potentially pass along to parent
197+
cls.info.parentsNEW.exists(parent => // needs outer to potentially pass along to parent
198198
needsOuterIfReferenced(parent.classSymbol.asClass)))
199199

200200
/** Class is always instantiated in the compilation unit where it is defined */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ object OverridingPairs {
3535
* pair has already been treated in a parent class.
3636
* This may be refined in subclasses. @see Bridges for a use case.
3737
*/
38-
protected def parents: Array[Symbol] = base.info.parents.toArray map (_.typeSymbol)
38+
protected def parents: Array[Symbol] = base.info.parentsNEW.toArray map (_.typeSymbol)
3939

4040
/** Does `sym1` match `sym2` so that it qualifies as overriding.
4141
* Types always match. Term symbols match if their membertypes

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
891891
def isSubTypeOfParent(subtp: Type, tp: Type)(implicit ctx: Context): Boolean =
892892
if (subtp <:< tp) true
893893
else tp match {
894-
case tp: TypeRef if tp.symbol.isClass => isSubTypeOfParent(subtp, tp.firstParent)
894+
case tp: TypeRef if tp.symbol.isClass => isSubTypeOfParent(subtp, tp.firstParentNEW)
895895
case tp: TypeProxy => isSubTypeOfParent(subtp, tp.superType)
896896
case _ => false
897897
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ object RefChecks {
285285
//Console.println(infoString(member) + " shadows1 " + infoString(other) " in " + clazz);//DEBUG
286286
return
287287
}
288-
val parentSymbols = clazz.info.parents.map(_.typeSymbol)
288+
val parentSymbols = clazz.info.parentsNEW.map(_.typeSymbol)
289289
if (parentSymbols exists (p => subOther(p) && subMember(p) && deferredCheck)) {
290290
//Console.println(infoString(member) + " shadows2 " + infoString(other) + " in " + clazz);//DEBUG
291291
return

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ trait TypeAssigner {
293293
case err: ErrorType => untpd.cpy.Super(tree)(qual, mix).withType(err)
294294
case qtype @ ThisType(_) =>
295295
val cls = qtype.cls
296-
def findMixinSuper(site: Type): Type = site.parents filter (_.name == mix.name) match {
296+
def findMixinSuper(site: Type): Type = site.parentRefs filter (_.name == mix.name) match {
297297
case p :: Nil =>
298298
p
299299
case Nil =>
@@ -304,7 +304,7 @@ trait TypeAssigner {
304304
val owntype =
305305
if (mixinClass.exists) mixinClass.typeRef
306306
else if (!mix.isEmpty) findMixinSuper(cls.info)
307-
else if (inConstrCall || ctx.erasedTypes) cls.info.firstParent
307+
else if (inConstrCall || ctx.erasedTypes) cls.info.firstParentRef
308308
else {
309309
val ps = cls.classInfo.parentsWithArgs
310310
if (ps.isEmpty) defn.AnyType else ps.reduceLeft((x: Type, y: Type) => x & y)

0 commit comments

Comments
 (0)