Skip to content

Commit 12b91f9

Browse files
committed
Invalidate less on info_=
1 parent 7a2f158 commit 12b91f9

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ object DenotTransformers {
4444
val info1 = transformInfo(ref.info, ref.symbol)
4545
if (info1 eq ref.info) ref
4646
else ref match {
47-
case ref: SymDenotation => ref.copySymDenotation(info = info1)
48-
case _ => ref.derivedSingleDenotation(ref.symbol, info1)
47+
case ref: SymDenotation =>
48+
ref.copySymDenotation(info = info1).copyCaches(ref, ctx.phase.next)
49+
case _ =>
50+
ref.derivedSingleDenotation(ref.symbol, info1)
4951
}
5052
}
5153
}

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ object SymDenotations {
11701170
{ // simulate default parameters, while also passing implicit context ctx to the default values
11711171
val initFlags1 = (if (initFlags != UndefinedFlags) initFlags else this.flags) &~ Frozen
11721172
val info1 = if (info != null) info else this.info
1173-
if (ctx.isAfterTyper && changedClassParents(info, info1))
1173+
if (ctx.isAfterTyper && changedClassParents(info, info1, completersMatter = false))
11741174
assert(ctx.phase.changesParents, i"undeclared parent change at ${ctx.phase} for $this, was: $info, now: $info1")
11751175
val privateWithin1 = if (privateWithin != null) privateWithin else this.privateWithin
11761176
val annotations1 = if (annotations != null) annotations else this.annotations
@@ -1185,15 +1185,17 @@ object SymDenotations {
11851185
*/
11861186
def copyCaches(from: SymDenotation, phase: Phase)(implicit ctx: Context): this.type = this
11871187

1188-
/** Are `info1` and `info2` ClassInfo types with different parents? */
1189-
protected def changedClassParents(info1: Type, info2: Type): Boolean =
1188+
/** Are `info1` and `info2` ClassInfo types with different parents?
1189+
* @param completersMatter if `true`, consider parents changed if `info1` or `info2 `is a type completer
1190+
*/
1191+
protected def changedClassParents(info1: Type, info2: Type, completersMatter: Boolean): Boolean =
11901192
info2 match {
11911193
case info2: ClassInfo =>
11921194
info1 match {
11931195
case info1: ClassInfo => info1.classParents ne info2.classParents
1194-
case _ => false
1196+
case _ => completersMatter
11951197
}
1196-
case _ => false
1198+
case _ => completersMatter
11971199
}
11981200

11991201
override def initial: SymDenotation = super.initial.asSymDenotation
@@ -1307,12 +1309,11 @@ object SymDenotations {
13071309
}
13081310

13091311
override protected[dotc] final def info_=(tp: Type) = {
1310-
super.info_=(tp)
1311-
if (changedClassParents(infoOrCompleter, tp) || true) {
1312+
if (changedClassParents(infoOrCompleter, tp, completersMatter = true))
13121313
invalidateBaseDataCache()
1313-
}
13141314
invalidateMemberNamesCache()
13151315
myTypeParams = null // changing the info might change decls, and with it typeParams
1316+
super.info_=(tp)
13161317
}
13171318

13181319
/** The denotations of all parents in this class. */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ class Namer { typer: Typer =>
911911
Checking.checkWellFormed(cls)
912912
if (isDerivedValueClass(cls)) cls.setFlag(Final)
913913
cls.info = avoidPrivateLeaks(cls, cls.pos)
914-
cls.baseClasses.foreach(_.invalidateBaseTypeRefCache) // TODO: needed?
914+
cls.baseClasses.foreach(_.invalidateBaseTypeRefCache) // we might have looked before and found nothing
915915
}
916916
}
917917

0 commit comments

Comments
 (0)