Skip to content

Commit bd0533a

Browse files
committed
Make captureSetofInfo cache in CaptureRefs depend on iteration count
1 parent 58d052e commit bd0533a

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureRef.scala

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,30 @@ import typer.ErrorReporting.Addenda
99
import util.common.alwaysTrue
1010
import scala.collection.mutable
1111
import CCState.*
12-
import Periods.NoRunId
12+
import Periods.{NoRunId, RunWidth}
1313
import compiletime.uninitialized
1414
import StdNames.nme
1515
import CaptureSet.VarState
1616
import Annotations.Annotation
1717
import config.Printers.capt
1818

19+
object CaptureRef:
20+
opaque type Validity = Int
21+
def validId(runId: Int, iterId: Int): Validity =
22+
runId + (iterId << RunWidth)
23+
def currentId(using Context): Validity = validId(ctx.runId, ccState.iterCount)
24+
val invalid: Validity = validId(NoRunId, 0)
25+
1926
/** A trait for references in CaptureSets. These can be NamedTypes, ThisTypes or ParamRefs,
2027
* as well as three kinds of AnnotatedTypes representing readOnly, reach, and maybe capabilities.
2128
* If there are several annotations they come with an order:
2229
* `*` first, `.rd` next, `?` last.
2330
*/
2431
trait CaptureRef extends TypeProxy, ValueType:
32+
import CaptureRef.*
33+
2534
private var myCaptureSet: CaptureSet | Null = uninitialized
26-
private var myCaptureSetRunId: Int = NoRunId
35+
private var myCaptureSetValid: Validity = invalid
2736
private var mySingletonCaptureSet: CaptureSet.Const | Null = null
2837
private var myDerivedRefs: List[AnnotatedType] = Nil
2938

@@ -130,7 +139,7 @@ trait CaptureRef extends TypeProxy, ValueType:
130139

131140
/** The capture set of the type underlying this reference */
132141
final def captureSetOfInfo(using Context): CaptureSet =
133-
if ctx.runId == myCaptureSetRunId then myCaptureSet.nn
142+
if myCaptureSetValid == currentId then myCaptureSet.nn
134143
else if myCaptureSet.asInstanceOf[AnyRef] eq CaptureSet.Pending then CaptureSet.empty
135144
else
136145
myCaptureSet = CaptureSet.Pending
@@ -143,11 +152,11 @@ trait CaptureRef extends TypeProxy, ValueType:
143152
myCaptureSet = null
144153
else
145154
myCaptureSet = computed
146-
myCaptureSetRunId = ctx.runId
155+
myCaptureSetValid = currentId
147156
computed
148157

149158
final def invalidateCaches() =
150-
myCaptureSetRunId = NoRunId
159+
myCaptureSetValid = invalid
151160

152161
/** x subsumes x
153162
* x =:= y ==> x subsumes y

compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ class CheckCaptures extends Recheck, SymTransformer:
268268
needAnotherRun = false
269269
resetNuTypes()
270270
todoAtPostCheck.clear()
271-
for (sym, completer) <- completed do sym.info = completer
271+
for (sym, completer) <- completed do
272+
sym.info = completer
273+
sym.resetFlag(Touched)
272274
completed.clear()
273275

274276
extension [T <: Tree](tree: T)

0 commit comments

Comments
 (0)