Skip to content

Commit 6807a60

Browse files
committed
Rename CaptureRef -> Capability
1 parent 98e6259 commit 6807a60

12 files changed

+134
-135
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureRef.scala renamed to compiler/src/dotty/tools/dotc/cc/Capability.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import printing.{Printer, Showable}
2323
import printing.Texts.Text
2424
import annotation.internal.sharable
2525

26-
type CaptureRef = Capabilities.Capability
27-
2826
/** Capability --+-- RootCapabilty -----+-- GlobalCap
2927
* | +-- FreshCap
3028
* | +-- ResultCap
@@ -67,7 +65,7 @@ object Capabilities:
6765
trait DerivedCapability extends Capability:
6866
def underlying: Capability
6967

70-
/** If `x` is a capture ref, its maybe capability `x?`. `x?` stands for a capability
68+
/** If `x` is a capability, its maybe capability `x?`. `x?` stands for a capability
7169
* `x` that might or might not be part of a capture set. We have `{} <: {x?} <: {x}`.
7270
* Maybe capabilities cannot be propagated between sets. If `a <: b` and `a`
7371
* acquires `x?` then `x` is propagated to `b` as a conservative approximation.
@@ -96,7 +94,7 @@ object Capabilities:
9694
extends DerivedCapability:
9795
assert(!underlying.isInstanceOf[Maybe])
9896

99-
/** If `x` is a capture ref, its reach capability `x*`. `x*` stands for all
97+
/** If `x` is a capability, its reach capability `x*`. `x*` stands for all
10098
* capabilities reachable through `x`.
10199
* We have `{x} <: {x*} <: dcs(x)}` where the deep capture set `dcs(x)` of `x`
102100
* is the union of all capture sets that appear in covariant position in the
@@ -521,6 +519,6 @@ object Capabilities:
521519
def assumedContainsOf(x: TypeRef)(using Context): SimpleIdentitySet[Capability] =
522520
CaptureSet.assumedContains.getOrElse(x, SimpleIdentitySet.empty)
523521

524-
def toText(printer: Printer): Text = printer.toTextCaptureRef(this)
522+
def toText(printer: Printer): Text = printer.toTextCapability(this)
525523
end Capability
526524
end Capabilities

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def depFun(args: List[Type], resultType: Type, isContextual: Boolean, paramNames
3838
else make(args, resultType)
3939
mt.toFunctionType(alwaysDependent = true)
4040

41-
/** An exception thrown if a @retains argument is not syntactically a CaptureRef */
41+
/** An exception thrown if a @retains argument is not syntactically a Capability */
4242
class IllegalCaptureRef(tpe: Type)(using Context) extends Exception(tpe.show)
4343

4444
/** A base trait for data producing addenda to error messages */
@@ -50,21 +50,21 @@ def ccState(using Context): CCState =
5050

5151
extension (tree: Tree)
5252

53-
/** Map tree with CaptureRef type to its type,
53+
/** Map tree with a Capability type to the corresponding capability,
5454
* map CapSet^{refs} to the `refs` references,
5555
* throw IllegalCaptureRef otherwise
5656
*/
57-
def toCaptureRefs(using Context): List[CaptureRef] = tree match
57+
def toCapabilities(using Context): List[Capability] = tree match
5858
case ReachCapabilityApply(arg) =>
59-
arg.toCaptureRefs.map(_.reach)
59+
arg.toCapabilities.map(_.reach)
6060
case ReadOnlyCapabilityApply(arg) =>
61-
arg.toCaptureRefs.map(_.readOnly)
61+
arg.toCapabilities.map(_.readOnly)
6262
case CapsOfApply(arg) =>
63-
arg.toCaptureRefs
63+
arg.toCapabilities
6464
case _ => tree.tpe.dealiasKeepAnnots match
6565
case ref: TermRef if ref.isCapRef =>
6666
GlobalCap :: Nil
67-
case ref: CaptureRef if ref.isTrackableRef =>
67+
case ref: Capability if ref.isTrackableRef =>
6868
ref :: Nil
6969
case AnnotatedType(parent, ann)
7070
if ann.symbol.isRetains && parent.derivesFrom(defn.Caps_CapSet) =>
@@ -79,7 +79,7 @@ extension (tree: Tree)
7979
tree.getAttachment(Captures) match
8080
case Some(refs) => refs
8181
case None =>
82-
val refs = CaptureSet(tree.retainedElems.flatMap(_.toCaptureRefs)*)
82+
val refs = CaptureSet(tree.retainedElems.flatMap(_.toCapabilities)*)
8383
//.showing(i"toCaptureSet $tree --> $result", capt)
8484
tree.putAttachment(Captures, refs)
8585
refs
@@ -95,7 +95,7 @@ extension (tree: Tree)
9595

9696
extension (tp: Type)
9797

98-
/** Is this type a CaptureRef that can be tracked?
98+
/** Is this type a Capability that can be tracked?
9999
* This is true for
100100
* - all ThisTypes and all TermParamRef,
101101
* - stable TermRefs with NoPrefix or ThisTypes as prefixes,
@@ -120,9 +120,9 @@ extension (tp: Type)
120120
false
121121

122122
/** The capture set of a type. This is:
123-
* - For trackable capture references: The singleton capture set consisting of
123+
* - For trackable capabilities: The singleton capture set consisting of
124124
* just the reference, provided the underlying capture set of their info is not empty.
125-
* - For other capture references: The capture set of their info
125+
* - For other capabilities: The capture set of their info
126126
* - For all other types: The result of CaptureSet.ofType
127127
*/
128128
final def captureSet(using Context): CaptureSet = tp match
@@ -149,7 +149,7 @@ extension (tp: Type)
149149
deepCaptureSet(includeTypevars = false)
150150

151151
/** A type capturing `ref` */
152-
def capturing(ref: CaptureRef)(using Context): Type =
152+
def capturing(ref: Capability)(using Context): Type =
153153
if tp.captureSet.accountsFor(ref) then tp
154154
else CapturingType(tp, ref.singletonCaptureSet)
155155

@@ -200,7 +200,7 @@ extension (tp: Type)
200200
/** The capture set consisting of all top-level captures of `tp` that appear under a box.
201201
* Unlike for `boxed` this also considers parents of capture types, unions and
202202
* intersections, and type proxies other than abstract types.
203-
* Furthermore, if the original type is a capture ref `x`, it replaces boxed universal sets
203+
* Furthermore, if the original type is a capability `x`, it replaces boxed universal sets
204204
* on the fly with x*.
205205
*/
206206
def boxedCaptureSet(using Context): CaptureSet =
@@ -215,7 +215,7 @@ extension (tp: Type)
215215
pcs ++ reachRef.singletonCaptureSet
216216
case _ =>
217217
pcs ++ refs
218-
case ref: CaptureRef if ref.isTracked && !pre.exists => getBoxed(ref, ref)
218+
case ref: Capability if ref.isTracked && !pre.exists => getBoxed(ref, ref)
219219
case tp: TypeRef if tp.symbol.isAbstractOrParamType => CaptureSet.empty
220220
case tp: TypeProxy => getBoxed(tp.superType, pre)
221221
case tp: AndType => getBoxed(tp.tp1, pre) ** getBoxed(tp.tp2, pre)
@@ -249,7 +249,7 @@ extension (tp: Type)
249249
def forceBoxStatus(boxed: Boolean)(using Context): Type = tp.widenDealias match
250250
case tp @ CapturingType(parent, refs) if tp.isBoxed != boxed =>
251251
val refs1 = tp match
252-
case ref: CaptureRef if ref.isTracked || ref.isReach || ref.isReadOnly =>
252+
case ref: Capability if ref.isTracked || ref.isReach || ref.isReadOnly =>
253253
ref.singletonCaptureSet
254254
case _ => refs
255255
CapturingType(parent, refs1, boxed)
@@ -347,7 +347,7 @@ extension (tp: Type)
347347
mapOver(t)
348348
tm(tp)
349349

350-
/** If `x` is a capture ref, replace all no-flip covariant occurrences of `cap`
350+
/** If `x` is a capability, replace all no-flip covariant occurrences of `cap`
351351
* in type `tp` with `x*`.
352352
*/
353353
def withReachCaptures(ref: Type)(using Context): Type = ref match
@@ -620,9 +620,9 @@ object ContainsImpl:
620620

621621
/** An extractor for a contains parameter */
622622
object ContainsParam:
623-
def unapply(sym: Symbol)(using Context): Option[(TypeRef, CaptureRef)] =
623+
def unapply(sym: Symbol)(using Context): Option[(TypeRef, Capability)] =
624624
sym.info.dealias match
625-
case AppliedType(tycon, (cs: TypeRef) :: (ref: CaptureRef) :: Nil)
625+
case AppliedType(tycon, (cs: TypeRef) :: (ref: Capability) :: Nil)
626626
if tycon.typeSymbol == defn.Caps_ContainsTrait
627627
&& cs.typeSymbol.isAbstractOrParamType => Some((cs, ref))
628628
case _ => None

0 commit comments

Comments
 (0)