Skip to content

Commit e609851

Browse files
oderskysmarter
authored andcommitted
Alternative fix for 10044
1 parent a690de2 commit e609851

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

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

+18-26
Original file line numberDiff line numberDiff line change
@@ -2097,7 +2097,6 @@ object Types {
20972097
private var lastDenotation: Denotation | Null = null
20982098
private var lastSymbol: Symbol | Null = null
20992099
private var checkedPeriod: Period = Nowhere
2100-
private var firstValidPhaseId: Int = 0
21012100
private var myStableHash: Byte = 0
21022101
private var mySignature: Signature = _
21032102
private var mySignatureRunId: Int = NoRunId
@@ -2213,8 +2212,6 @@ object Types {
22132212
val now = ctx.period
22142213
// Even if checkedPeriod == now we still need to recheck lastDenotation.validFor
22152214
// as it may have been mutated by SymDenotation#installAfter
2216-
if firstValidPhaseId > now.phaseId then
2217-
revalidateDenot()
22182215
if (checkedPeriod != Nowhere && lastDenotation.nn.validFor.contains(now)) {
22192216
checkedPeriod = now
22202217
lastDenotation.nn
@@ -2343,18 +2340,6 @@ object Types {
23432340
def recomputeDenot()(using Context): Unit =
23442341
setDenot(memberDenot(name, allowPrivate = !symbol.exists || symbol.is(Private)))
23452342

2346-
/** Try to recompute denotation and reset `firstValidPhaseId`.
2347-
* @pre Current phase id < firstValidPhaseId
2348-
*/
2349-
def revalidateDenot()(using Context): Unit =
2350-
if (prefix ne NoPrefix) then
2351-
core.println(i"revalidate $prefix . $name, $firstValidPhaseId > ${ctx.phaseId}")
2352-
val newDenot = memberDenot(name, allowPrivate =
2353-
lastSymbol == null || !lastSymbol.nn.exists || lastSymbol.nn.is(Private))
2354-
if newDenot.exists then
2355-
setDenot(newDenot)
2356-
firstValidPhaseId = ctx.phaseId
2357-
23582343
private def setDenot(denot: Denotation)(using Context): Unit = {
23592344
if (Config.checkNoDoubleBindings)
23602345
if (ctx.settings.YnoDoubleBindings.value)
@@ -2576,7 +2561,7 @@ object Types {
25762561
* A test case is neg/opaque-self-encoding.scala.
25772562
*/
25782563
final def withDenot(denot: Denotation)(using Context): ThisType =
2579-
if (denot.exists) {
2564+
if denot.exists then
25802565
val adapted = withSym(denot.symbol)
25812566
val result =
25822567
if (adapted.eq(this)
@@ -2586,17 +2571,24 @@ object Types {
25862571
adapted
25872572
else this
25882573
val lastDenot = result.lastDenotation
2589-
if denot.isInstanceOf[SymDenotation] && lastDenot != null && !lastDenot.isInstanceOf[SymDenotation] then
2590-
// In this case the new SymDenotation might be valid for all phases, which means
2591-
// we would not recompute the denotation when travelling to an earlier phase, maybe
2592-
// in the next run. We fix that problem by recording in this case in the NamedType
2593-
// the phase from which the denotation is valid. Taking the denotation at an earlier
2594-
// phase will then lead to a `revalidateDenot`.
2595-
core.println(i"overwrite ${result.toString} / ${result.lastDenotation} with $denot")
2596-
result.firstValidPhaseId = ctx.phaseId
2597-
result.setDenot(denot)
2574+
denot match
2575+
case denot: SymDenotation
2576+
if denot.validFor.firstPhaseId < ctx.phase.id
2577+
&& lastDenot != null
2578+
&& lastDenot.validFor.lastPhaseId > denot.validFor.firstPhaseId
2579+
&& !lastDenot.isInstanceOf[SymDenotation] =>
2580+
// In this case the new SymDenotation might be valid for all phases, which means
2581+
// we would not recompute the denotation when travelling to an earlier phase, maybe
2582+
// in the next run. We fix that problem by creating a UniqueRefDenotation instead.
2583+
core.println(i"overwrite ${result.toString} / ${result.lastDenotation}, ${result.lastDenotation.getClass} with $denot at ${ctx.phaseId}")
2584+
result.setDenot(
2585+
UniqueRefDenotation(
2586+
denot.symbol, denot.info,
2587+
Period(ctx.runId, ctx.phaseId, denot.validFor.lastPhaseId),
2588+
this.prefix))
2589+
case _ =>
2590+
result.setDenot(denot)
25982591
result.asInstanceOf[ThisType]
2599-
}
26002592
else // don't assign NoDenotation, we might need to recover later. Test case is pos/avoid.scala.
26012593
this
26022594

0 commit comments

Comments
 (0)