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