Skip to content

Commit 5e6b666

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 03000e2 commit 5e6b666

File tree

11 files changed

+67
-37
lines changed

11 files changed

+67
-37
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: 54 additions & 24 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))
@@ -958,7 +969,7 @@ object Types {
958969

959970
/** Eliminate anonymous classes */
960971
final def deAnonymize(implicit ctx: Context): Type = this match {
961-
case tp:TypeRef if tp.symbol.isAnonymousClass =>
972+
case tp: TypeRef if tp.symbol.isAnonymousClass =>
962973
tp.symbol.asClass.typeRef.asSeenFrom(tp.prefix, tp.symbol.owner)
963974
case tp => tp
964975
}
@@ -970,6 +981,14 @@ object Types {
970981
case TypeAlias(tp) => tp.dealias(keepAnnots): @tailrec
971982
case _ => tp
972983
}
984+
case app @ AppliedType(tycon, args) =>
985+
val tycon1 = tycon.dealias(keepAnnots)
986+
if (tycon1 ne tycon) app.superType.dealias(keepAnnots): @tailrec
987+
else this
988+
case app @ HKApply(tycon, args) =>
989+
val tycon1 = tycon.dealias(keepAnnots)
990+
if (tycon1 ne tycon) app.superType.dealias(keepAnnots): @tailrec
991+
else this
973992
case tp: TypeVar =>
974993
val tp1 = tp.instanceOpt
975994
if (tp1.exists) tp1.dealias(keepAnnots): @tailrec else tp
@@ -978,10 +997,6 @@ object Types {
978997
if (keepAnnots) tp.derivedAnnotatedType(tp1, tp.annot) else tp1
979998
case tp: LazyRef =>
980999
tp.ref.dealias(keepAnnots): @tailrec
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
9851000
case _ => this
9861001
}
9871002

@@ -1028,6 +1043,8 @@ object Types {
10281043
if (tp.symbol.isClass) tp
10291044
else if (tp.symbol.isAliasType) tp.underlying.underlyingClassRef(refinementOK)
10301045
else NoType
1046+
case tp: AppliedType =>
1047+
tp.superType.underlyingClassRef(refinementOK)
10311048
case tp: AnnotatedType =>
10321049
tp.underlying.underlyingClassRef(refinementOK)
10331050
case tp: RefinedType =>
@@ -1165,19 +1182,33 @@ object Types {
11651182
* Inherited by all type proxies. Empty for all other types.
11661183
* Overwritten in ClassInfo, where parents is cached.
11671184
*/
1168-
def parents(implicit ctx: Context): List[TypeRef] = this match {
1169-
case tp: TypeProxy => tp.underlying.parents
1170-
case _ => List()
1185+
def parentRefs(implicit ctx: Context): List[TypeRef] = this match {
1186+
case tp: TypeProxy => tp.underlying.parentRefs
1187+
case _ => Nil
11711188
}
11721189

11731190
/** The full parent types, including all type arguments */
11741191
def parentsWithArgs(implicit ctx: Context): List[Type] = this match {
11751192
case tp: TypeProxy => tp.superType.parentsWithArgs
1176-
case _ => List()
1193+
case _ => Nil
1194+
}
1195+
1196+
/** The full parent types, including (in new scheme) all type arguments */
1197+
def parentsNEW(implicit ctx: Context): List[Type] = this match {
1198+
case AppliedType(tycon: HKTypeLambda, args) => // TODO: can be eliminated once ClassInfo is changed, also: cache?
1199+
tycon.resType.parentsWithArgs.map(_.substParams(tycon, args))
1200+
case tp: TypeProxy => tp.superType.parentsNEW
1201+
case _ => Nil
1202+
}
1203+
1204+
/** The first parent of this type, AnyRef if list of parents is empty */
1205+
def firstParentRef(implicit ctx: Context): TypeRef = parentRefs match {
1206+
case p :: _ => p
1207+
case _ => defn.AnyType
11771208
}
11781209

11791210
/** The first parent of this type, AnyRef if list of parents is empty */
1180-
def firstParent(implicit ctx: Context): TypeRef = parents match {
1211+
def firstParentNEW(implicit ctx: Context): Type = parentsNEW match {
11811212
case p :: _ => p
11821213
case _ => defn.AnyType
11831214
}
@@ -3027,21 +3058,17 @@ object Types {
30273058
override def underlying(implicit ctx: Context): Type = tycon
30283059

30293060
override def superType(implicit ctx: Context): Type = {
3030-
def reapply(tp: Type) = tp match {
3031-
case tp: TypeRef if tp.symbol.isClass => tp
3032-
case _ => tp.applyIfParameterized(args)
3033-
}
30343061
if (ctx.period != validSuper) {
30353062
validSuper = ctx.period
30363063
cachedSuper = tycon match {
30373064
case tp: HKTypeLambda => defn.AnyType
30383065
case tp: TypeVar if !tp.inst.exists =>
30393066
// supertype not stable, since underlying might change
30403067
validSuper = Nowhere
3041-
reapply(tp.underlying)
3068+
tp.underlying.applyIfParameterized(args)
30423069
case tp: TypeProxy =>
30433070
if (tp.typeSymbol.is(Provisional)) validSuper = Nowhere
3044-
reapply(tp.superType)
3071+
tp.superType.applyIfParameterized(args)
30453072
case _ => defn.AnyType
30463073
}
30473074
}
@@ -3448,22 +3475,25 @@ object Types {
34483475
private var parentsCache: List[TypeRef] = null
34493476

34503477
/** The parent type refs as seen from the given prefix */
3451-
override def parents(implicit ctx: Context): List[TypeRef] = {
3478+
override def parentRefs(implicit ctx: Context): List[TypeRef] = {
34523479
if (parentsCache == null)
34533480
parentsCache = cls.classParents.mapConserve(_.asSeenFrom(prefix, cls.owner).asInstanceOf[TypeRef])
34543481
parentsCache
34553482
}
34563483

34573484
/** The parent types with all type arguments */
34583485
override def parentsWithArgs(implicit ctx: Context): List[Type] =
3459-
parents mapConserve { pref =>
3486+
parentRefs mapConserve { pref =>
34603487
((pref: Type) /: pref.classSymbol.typeParams) { (parent, tparam) =>
34613488
val targSym = decls.lookup(tparam.name)
34623489
if (targSym.exists) RefinedType(parent, targSym.name, targSym.info)
34633490
else parent
34643491
}
34653492
}
34663493

3494+
override def parentsNEW(implicit ctx: Context): List[Type] =
3495+
parentRefs // !!! TODO: change
3496+
34673497
def derivedClassInfo(prefix: Type)(implicit ctx: Context) =
34683498
if (prefix eq this.prefix) this
34693499
else ClassInfo(prefix, cls, classParents, decls, selfInfo)
@@ -3936,12 +3966,12 @@ object Types {
39363966
abstract class DeepTypeMap(implicit ctx: Context) extends TypeMap {
39373967
override def mapClassInfo(tp: ClassInfo) = {
39383968
val prefix1 = this(tp.prefix)
3939-
val parents1 = (tp.parents mapConserve this).asInstanceOf[List[TypeRef]]
3969+
val parentRefs1 = (tp.parentRefs mapConserve this).asInstanceOf[List[TypeRef]]
39403970
val selfInfo1 = tp.selfInfo match {
39413971
case selfInfo: Type => this(selfInfo)
39423972
case selfInfo => selfInfo
39433973
}
3944-
tp.derivedClassInfo(prefix1, parents1, tp.decls, selfInfo1)
3974+
tp.derivedClassInfo(prefix1, parentRefs1, tp.decls, selfInfo1)
39453975
}
39463976
}
39473977

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)