@@ -38,7 +38,8 @@ import config.Printers.{core, typr, matchTypes}
38
38
import reporting .{trace , Message }
39
39
import java .lang .ref .WeakReference
40
40
import compiletime .uninitialized
41
- import cc .{CapturingType , CaptureSet , derivedCapturingType , isBoxedCapturing , isCaptureChecking , isRetains , isRetainsLike }
41
+ import cc .{CapturingType , CaptureRef , CaptureSet , SingletonCaptureRef , isTrackableRef ,
42
+ derivedCapturingType , isBoxedCapturing , isCaptureChecking , isRetains , isRetainsLike }
42
43
import CaptureSet .{CompareResult , IdempotentCaptRefMap , IdentityCaptRefMap }
43
44
44
45
import scala .annotation .internal .sharable
@@ -522,45 +523,6 @@ object Types extends TypeUtils {
522
523
*/
523
524
def isDeclaredVarianceLambda : Boolean = false
524
525
525
- /** Is this type a CaptureRef that can be tracked?
526
- * This is true for
527
- * - all ThisTypes and all TermParamRef,
528
- * - stable TermRefs with NoPrefix or ThisTypes as prefixes,
529
- * - the root capability `caps.cap`
530
- * - abstract or parameter TypeRefs that derive from caps.CapSet
531
- * - annotated types that represent reach or maybe capabilities
532
- */
533
- final def isTrackableRef (using Context ): Boolean = this match
534
- case _ : (ThisType | TermParamRef ) =>
535
- true
536
- case tp : TermRef =>
537
- ((tp.prefix eq NoPrefix )
538
- || tp.symbol.is(ParamAccessor ) && tp.prefix.isThisTypeOf(tp.symbol.owner)
539
- || tp.isRootCapability
540
- ) && ! tp.symbol.isOneOf(UnstableValueFlags )
541
- case tp : TypeRef =>
542
- tp.symbol.isAbstractOrParamType && tp.derivesFrom(defn.Caps_CapSet )
543
- case tp : TypeParamRef =>
544
- tp.derivesFrom(defn.Caps_CapSet )
545
- case AnnotatedType (parent, annot) =>
546
- annot.symbol == defn.ReachCapabilityAnnot
547
- || annot.symbol == defn.MaybeCapabilityAnnot
548
- case _ =>
549
- false
550
-
551
- /** The capture set of a type. This is:
552
- * - For trackable capture references: The singleton capture set consisting of
553
- * just the reference, provided the underlying capture set of their info is not empty.
554
- * - For other capture references: The capture set of their info
555
- * - For all other types: The result of CaptureSet.ofType
556
- */
557
- final def captureSet (using Context ): CaptureSet = this match
558
- case tp : CaptureRef if tp.isTrackableRef =>
559
- val cs = tp.captureSetOfInfo
560
- if cs.isAlwaysEmpty then cs else tp.singletonCaptureSet
561
- case tp : SingletonCaptureRef => tp.captureSetOfInfo
562
- case _ => CaptureSet .ofType(this , followResult = false )
563
-
564
526
/** Does this type contain wildcard types? */
565
527
final def containsWildcardTypes (using Context ) =
566
528
existsPart(_.isInstanceOf [WildcardType ], StopAt .Static , forceLazy = false )
@@ -2077,20 +2039,6 @@ object Types extends TypeUtils {
2077
2039
case _ =>
2078
2040
this
2079
2041
2080
- /** A type capturing `ref` */
2081
- def capturing (ref : CaptureRef )(using Context ): Type =
2082
- if captureSet.accountsFor(ref) then this
2083
- else CapturingType (this , ref.singletonCaptureSet)
2084
-
2085
- /** A type capturing the capture set `cs`. If this type is already a capturing type
2086
- * the two capture sets are combined.
2087
- */
2088
- def capturing (cs : CaptureSet )(using Context ): Type =
2089
- if cs.isAlwaysEmpty || cs.isConst && cs.subCaptures(captureSet, frozen = true ).isOK then this
2090
- else this match
2091
- case CapturingType (parent, cs1) => parent.capturing(cs1 ++ cs)
2092
- case _ => CapturingType (this , cs)
2093
-
2094
2042
/** The set of distinct symbols referred to by this type, after all aliases are expanded */
2095
2043
def coveringSet (using Context ): Set [Symbol ] =
2096
2044
(new CoveringSetAccumulator ).apply(Set .empty[Symbol ], this )
@@ -2289,86 +2237,6 @@ object Types extends TypeUtils {
2289
2237
def isOverloaded (using Context ): Boolean = false
2290
2238
}
2291
2239
2292
- /** A trait for references in CaptureSets. These can be NamedTypes, ThisTypes or ParamRefs */
2293
- trait CaptureRef extends TypeProxy , ValueType :
2294
- private var myCaptureSet : CaptureSet | Null = uninitialized
2295
- private var myCaptureSetRunId : Int = NoRunId
2296
- private var mySingletonCaptureSet : CaptureSet .Const | Null = null
2297
-
2298
- /** Is the reference tracked? This is true if it can be tracked and the capture
2299
- * set of the underlying type is not always empty.
2300
- */
2301
- final def isTracked (using Context ): Boolean =
2302
- isTrackableRef && (isMaxCapability || ! captureSetOfInfo.isAlwaysEmpty)
2303
-
2304
- /** Is this a reach reference of the form `x*`? */
2305
- final def isReach (using Context ): Boolean = this match
2306
- case AnnotatedType (_, annot) => annot.symbol == defn.ReachCapabilityAnnot
2307
- case _ => false
2308
-
2309
- /** Is this a maybe reference of the form `x?`? */
2310
- final def isMaybe (using Context ): Boolean = this match
2311
- case AnnotatedType (_, annot) => annot.symbol == defn.MaybeCapabilityAnnot
2312
- case _ => false
2313
-
2314
- final def stripReach (using Context ): CaptureRef =
2315
- if isReach then
2316
- val AnnotatedType (parent : CaptureRef , _) = this : @ unchecked
2317
- parent
2318
- else this
2319
-
2320
- final def stripMaybe (using Context ): CaptureRef =
2321
- if isMaybe then
2322
- val AnnotatedType (parent : CaptureRef , _) = this : @ unchecked
2323
- parent
2324
- else this
2325
-
2326
- /** Is this reference the generic root capability `cap` ? */
2327
- final def isRootCapability (using Context ): Boolean = this match
2328
- case tp : TermRef => tp.name == nme.CAPTURE_ROOT && tp.symbol == defn.captureRoot
2329
- case _ => false
2330
-
2331
- /** Is this reference capability that does not derive from another capability ? */
2332
- final def isMaxCapability (using Context ): Boolean = this match
2333
- case tp : TermRef => tp.isRootCapability || tp.info.derivesFrom(defn.Caps_Exists )
2334
- case tp : TermParamRef => tp.underlying.derivesFrom(defn.Caps_Exists )
2335
- case _ => false
2336
-
2337
- /** Normalize reference so that it can be compared with `eq` for equality */
2338
- final def normalizedRef (using Context ): CaptureRef = this match
2339
- case tp @ AnnotatedType (parent : CaptureRef , annot) if isTrackableRef =>
2340
- tp.derivedAnnotatedType(parent.normalizedRef, annot)
2341
- case tp : TermRef if isTrackableRef =>
2342
- tp.symbol.termRef
2343
- case _ => this
2344
-
2345
- /** The capture set consisting of exactly this reference */
2346
- final def singletonCaptureSet (using Context ): CaptureSet .Const =
2347
- if mySingletonCaptureSet == null then
2348
- mySingletonCaptureSet = CaptureSet (this .normalizedRef)
2349
- mySingletonCaptureSet.uncheckedNN
2350
-
2351
- /** The capture set of the type underlying this reference */
2352
- final def captureSetOfInfo (using Context ): CaptureSet =
2353
- if ctx.runId == myCaptureSetRunId then myCaptureSet.nn
2354
- else if myCaptureSet.asInstanceOf [AnyRef ] eq CaptureSet .Pending then CaptureSet .empty
2355
- else
2356
- myCaptureSet = CaptureSet .Pending
2357
- val computed = CaptureSet .ofInfo(this )
2358
- if ! isCaptureChecking || underlying.isProvisional then
2359
- myCaptureSet = null
2360
- else
2361
- myCaptureSet = computed
2362
- myCaptureSetRunId = ctx.runId
2363
- computed
2364
-
2365
- final def invalidateCaches () =
2366
- myCaptureSetRunId = NoRunId
2367
-
2368
- end CaptureRef
2369
-
2370
- trait SingletonCaptureRef extends SingletonType , CaptureRef
2371
-
2372
2240
/** A trait for types that bind other types that refer to them.
2373
2241
* Instances are: LambdaType, RecType.
2374
2242
*/
0 commit comments