@@ -9,21 +9,30 @@ import typer.ErrorReporting.Addenda
99import util .common .alwaysTrue
1010import scala .collection .mutable
1111import CCState .*
12- import Periods .NoRunId
12+ import Periods .{ NoRunId , RunWidth }
1313import compiletime .uninitialized
1414import StdNames .nme
1515import CaptureSet .VarState
1616import Annotations .Annotation
1717import 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 */
2431trait 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
0 commit comments