Skip to content

Commit 3e8c9cf

Browse files
committed
Comments and general polishing
1 parent d223e79 commit 3e8c9cf

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,14 @@ def ccState(using Context): CCState =
5252
extension (tree: Tree)
5353

5454
/** The type representing the capture set of @retains, @retainsCap or @retainsByName
55-
* annotation tree.
55+
* annotation tree (represented as an Apply node).
5656
*/
57-
def retainedSet(using Context): Type =
58-
val rcap = defn.RetainsCapAnnot
59-
if tree.symbol == rcap || tree.symbol.maybeOwner == rcap then
60-
defn.captureRoot.termRef
61-
else tree match
62-
case Apply(TypeApply(_, refs :: Nil), _) => refs.tpe
63-
case _ => NoType
57+
def retainedSet(using Context): Type = tree match
58+
case Apply(TypeApply(_, refs :: Nil), _) => refs.tpe
59+
case _ =>
60+
if tree.symbol.maybeOwner == defn.RetainsCapAnnot
61+
then defn.captureRoot.termRef
62+
else NoType
6463

6564
extension (tp: Type)
6665

@@ -85,7 +84,7 @@ extension (tp: Type)
8584
def retainedElementsRaw(using Context): List[Type] = tp match
8685
case OrType(tp1, tp2) =>
8786
tp1.retainedElementsRaw ++ tp2.retainedElementsRaw
88-
case AnnotatedType(tp1, ann: RetainingAnnotation) if tp1.derivesFrom(defn.Caps_CapSet) && ann.isStrict =>
87+
case AnnotatedType(tp1, ann: RetainingAnnotation) if tp1.derivesFrom(defn.Caps_CapSet) =>
8988
ann.retainedType.retainedElementsRaw
9089
case tp =>
9190
tp.dealiasKeepAnnots match
@@ -229,7 +228,8 @@ extension (tp: Type)
229228
if tp.isBoxed || parent.derivesFrom(defn.Caps_CapSet) then tp
230229
else tp.boxed
231230
case tp @ AnnotatedType(parent, ann: RetainingAnnotation)
232-
if ann.isStrict && !parent.derivesFrom(defn.Caps_CapSet) =>
231+
if !parent.derivesFrom(defn.Caps_CapSet) =>
232+
assert(ann.isStrict)
233233
CapturingType(parent, ann.toCaptureSet, boxed = true)
234234
case tp @ AnnotatedType(parent, ann) =>
235235
tp.derivedAnnotatedType(parent.boxDeeply, ann)

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,10 +1672,8 @@ object CaptureSet:
16721672
case tp: (TypeRef | TypeParamRef) =>
16731673
if tp.derivesFrom(defn.Caps_CapSet) then tp.captureSet
16741674
else empty
1675-
case CapturingType(parent, refs) =>
1675+
case CapturingOrRetainsType(parent, refs) =>
16761676
recur(parent) ++ refs
1677-
case tp @ AnnotatedType(parent, ann: RetainingAnnotation) if ann.isStrict =>
1678-
recur(parent) ++ ann.toCaptureSet
16791677
case tpd @ defn.RefinedFunctionOf(rinfo: MethodOrPoly) if followResult =>
16801678
ofType(tpd.parent, followResult = false) // pick up capture set from parent type
16811679
++ recur(rinfo.resType).freeInResult(rinfo) // add capture set of result

compiler/src/dotty/tools/dotc/core/Annotations.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ object Annotations {
127127
case class ConcreteAnnotation(t: Tree) extends Annotation:
128128
def tree(using Context): Tree = t
129129

130+
/** A class for optimized, compact annotations that are defined by a type
131+
* instead of a tree. This makes mapping such annotations a lot faster and safer.
132+
* In fact, in retrospect, most annotations would better be represented as
133+
* CompactAnnotations.
134+
*
135+
* CompactAnnotation is extended by cc.RetainingAnnotation, which is reserved
136+
* for @retains, @retainsByName and @retainsCap. For now there are no
137+
* CompactAnnotations other than RetainingAnnotations but this could be changed
138+
* in the future, after 3.9 has shipped.
139+
*/
130140
class CompactAnnotation(val tpe: Type) extends Annotation:
131141
assert(tpe.isInstanceOf[AppliedType | TypeRef], tpe)
132142

0 commit comments

Comments
 (0)