@@ -66,6 +66,9 @@ extension (using qctx: Quotes)(ann: qctx.reflect.Symbol)
66
66
67
67
def isReachCapabilityAnnot : Boolean =
68
68
ann == CaptureDefs .ReachCapabilityAnnot
69
+
70
+ def isReadOnlyCapabilityAnnot : Boolean =
71
+ ann == CaptureDefs .ReadOnlyCapabilityAnnot
69
72
end extension
70
73
71
74
extension (using qctx : Quotes )(tpe : qctx.reflect.TypeRepr ) // FIXME clean up and have versions on Symbol for those
@@ -113,6 +116,15 @@ object ReachCapability:
113
116
case _ => None
114
117
end ReachCapability
115
118
119
+ object ReadOnlyCapability :
120
+ def unapply (using qctx : Quotes )(ty : qctx.reflect.TypeRepr ): Option [qctx.reflect.TypeRepr ] =
121
+ import qctx .reflect ._
122
+ ty match
123
+ case AnnotatedType (base, Apply (Select (New (annot), _), Nil )) if annot.symbol.isReadOnlyCapabilityAnnot =>
124
+ Some (base)
125
+ case _ => None
126
+ end ReadOnlyCapability
127
+
116
128
/** Decompose capture sets in the union-type-encoding into the sequence of atomic `TypeRepr`s.
117
129
* Returns `None` if the type is not a capture set.
118
130
*/
@@ -122,11 +134,12 @@ def decomposeCaptureRefs(using qctx: Quotes)(typ0: qctx.reflect.TypeRepr): Optio
122
134
def include (t : TypeRepr ): Boolean = { buffer += t; true }
123
135
def traverse (typ : TypeRepr ): Boolean =
124
136
typ match
125
- case OrType (t1, t2) => traverse(t1) && traverse(t2)
126
- case t @ ThisType (_) => include(t)
127
- case t @ TermRef (_, _) => include(t)
128
- case t @ ParamRef (_, _) => include(t)
129
- case t @ ReachCapability (_) => include(t)
137
+ case OrType (t1, t2) => traverse(t1) && traverse(t2)
138
+ case t @ ThisType (_) => include(t)
139
+ case t @ TermRef (_, _) => include(t)
140
+ case t @ ParamRef (_, _) => include(t)
141
+ case t @ ReachCapability (_) => include(t)
142
+ case t @ ReadOnlyCapability (_) => include(t)
130
143
case t if t.typeSymbol == defn.NothingClass => true
131
144
// TODO: are atoms only ever the above? Then we could refine the return type
132
145
case _ => report.warning(s " Unexpected type tree $typ while trying to extract capture references from $typ0" ); false // TODO remove warning eventually
0 commit comments