Skip to content

Commit 8ad9b10

Browse files
authored
Merge pull request #4206 from dotty-staging/fix/checkedPeriod-cache
Fix denotation caching in NamedType
2 parents 4bc6c65 + 3e6ebe4 commit 8ad9b10

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,12 +1020,6 @@ object Denotations {
10201020
interval
10211021
}
10221022

1023-
/** For ClassDenotations only:
1024-
* If caches influenced by parent classes are still valid, the denotation
1025-
* itself, otherwise a freshly initialized copy.
1026-
*/
1027-
def syncWithParents(implicit ctx: Context): SingleDenotation = this
1028-
10291023
/** Show declaration string; useful for showing declarations
10301024
* as seen from subclasses.
10311025
*/

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,8 @@ object Types {
16481648
}
16491649

16501650
final def symbol(implicit ctx: Context): Symbol =
1651+
// We can rely on checkedPeriod (unlike in the definition of `denot` below)
1652+
// because SymDenotation#installAfter never changes the symbol
16511653
if (checkedPeriod == ctx.period) lastSymbol else computeSymbol
16521654

16531655
private def computeSymbol(implicit ctx: Context): Symbol =
@@ -1692,17 +1694,11 @@ object Types {
16921694
/** The denotation currently denoted by this type */
16931695
final def denot(implicit ctx: Context): Denotation = {
16941696
val now = ctx.period
1695-
val lastd = lastDenotation
1696-
if (checkedPeriod == now) lastd else denotAt(lastd, now)
1697-
}
1698-
1699-
/** A first fall back to do a somewhat more expensive calculation in case the first
1700-
* attempt in `denot` does not yield a denotation.
1701-
*/
1702-
private def denotAt(lastd: Denotation, now: Period)(implicit ctx: Context): Denotation = {
1703-
if (checkedPeriod != Nowhere && lastd.validFor.contains(now)) {
1697+
// Even if checkedPeriod == now we still need to recheck lastDenotation.validFor
1698+
// as it may have been mutated by SymDenotation#installAfter
1699+
if (checkedPeriod != Nowhere && lastDenotation.validFor.contains(now)) {
17041700
checkedPeriod = now
1705-
lastd
1701+
lastDenotation
17061702
}
17071703
else computeDenot
17081704
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class ExtensionMethods extends MiniPhase with DenotTransformer with FullParamete
108108
moduleClassSym
109109
}
110110
case ref: SymDenotation =>
111-
if (isMethodWithExtension(ref) && ref.hasAnnotation(defn.TailrecAnnot)) {
111+
if (isMethodWithExtension(ref.symbol) && ref.hasAnnotation(defn.TailrecAnnot)) {
112112
val ref1 = ref.copySymDenotation()
113113
ref1.removeAnnotation(defn.TailrecAnnot)
114114
ref1

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ object ValueClasses {
2121
!d.isPrimitiveValueClass
2222
}
2323

24-
def isMethodWithExtension(d: SymDenotation)(implicit ctx: Context) =
25-
d.isRealMethod &&
24+
def isMethodWithExtension(sym: Symbol)(implicit ctx: Context) =
25+
ctx.atPhaseNotLaterThan(ctx.extensionMethodsPhase) { implicit ctx =>
26+
val d = sym.denot
27+
d.validFor.containsPhaseId(ctx.phaseId) &&
28+
d.isRealMethod &&
2629
isDerivedValueClass(d.owner) &&
2730
!d.isConstructor &&
2831
!d.isSuperAccessor &&
2932
!d.is(Macro)
33+
}
3034

3135
/** The member of a derived value class that unboxes it. */
3236
def valueClassUnbox(d: ClassDenotation)(implicit ctx: Context): Symbol =

0 commit comments

Comments
 (0)