@@ -9,21 +9,30 @@ import typer.ErrorReporting.Addenda
9
9
import util .common .alwaysTrue
10
10
import scala .collection .mutable
11
11
import CCState .*
12
- import Periods .NoRunId
12
+ import Periods .{ NoRunId , RunWidth }
13
13
import compiletime .uninitialized
14
14
import StdNames .nme
15
15
import CaptureSet .VarState
16
16
import Annotations .Annotation
17
17
import config .Printers .capt
18
18
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
+
19
26
/** A trait for references in CaptureSets. These can be NamedTypes, ThisTypes or ParamRefs,
20
27
* as well as three kinds of AnnotatedTypes representing readOnly, reach, and maybe capabilities.
21
28
* If there are several annotations they come with an order:
22
29
* `*` first, `.rd` next, `?` last.
23
30
*/
24
31
trait CaptureRef extends TypeProxy , ValueType :
32
+ import CaptureRef .*
33
+
25
34
private var myCaptureSet : CaptureSet | Null = uninitialized
26
- private var myCaptureSetRunId : Int = NoRunId
35
+ private var myCaptureSetValid : Validity = invalid
27
36
private var mySingletonCaptureSet : CaptureSet .Const | Null = null
28
37
private var myDerivedRefs : List [AnnotatedType ] = Nil
29
38
@@ -130,7 +139,7 @@ trait CaptureRef extends TypeProxy, ValueType:
130
139
131
140
/** The capture set of the type underlying this reference */
132
141
final def captureSetOfInfo (using Context ): CaptureSet =
133
- if ctx.runId == myCaptureSetRunId then myCaptureSet.nn
142
+ if myCaptureSetValid == currentId then myCaptureSet.nn
134
143
else if myCaptureSet.asInstanceOf [AnyRef ] eq CaptureSet .Pending then CaptureSet .empty
135
144
else
136
145
myCaptureSet = CaptureSet .Pending
@@ -143,11 +152,11 @@ trait CaptureRef extends TypeProxy, ValueType:
143
152
myCaptureSet = null
144
153
else
145
154
myCaptureSet = computed
146
- myCaptureSetRunId = ctx.runId
155
+ myCaptureSetValid = currentId
147
156
computed
148
157
149
158
final def invalidateCaches () =
150
- myCaptureSetRunId = NoRunId
159
+ myCaptureSetValid = invalid
151
160
152
161
/** x subsumes x
153
162
* x =:= y ==> x subsumes y
0 commit comments