@@ -11,6 +11,7 @@ import util.Property.Key
11
11
import tpd .*
12
12
13
13
private val Captures : Key [CaptureSet ] = Key ()
14
+ private val Boxed : Key [Type ] = Key ()
14
15
15
16
def retainedElems (tree : Tree )(using Context ): List [Tree ] = tree match
16
17
case Apply (_, Typed (SeqLiteral (elems, _), _) :: Nil ) => elems
@@ -40,6 +41,22 @@ extension (tp: Type)
40
41
if (parent eq p) && (refs eq r) then tp
41
42
else CapturingType (parent, refs, tp.isBoxed)
42
43
44
+ def boxed (using Context ): Type = tp.dealias match
45
+ case tp @ CapturingType (parent, refs) =>
46
+ def boxedTp = CapturingType (parent, refs, boxed = true )
47
+ if tp.isBoxed || refs.isAlwaysEmpty then tp
48
+ else tp.annot match
49
+ case ann : CaptureAnnotation =>
50
+ if ! ann.boxedType.exists then ann.boxedType = boxedTp
51
+ ann.boxedType
52
+ case ann =>
53
+ ann.tree.getAttachment(Boxed ) match
54
+ case None => ann.tree.putAttachment(Boxed , boxedTp)
55
+ case _ =>
56
+ ann.tree.attachment(Boxed )
57
+ case _ =>
58
+ tp
59
+
43
60
/** The boxed capture set of a type */
44
61
def boxedCaptured (using Context ): CaptureSet =
45
62
def getBoxed (tp : Type ): CaptureSet = tp match
@@ -105,3 +122,4 @@ extension (tp: AnnotatedType)
105
122
def isBoxed (using Context ): Boolean = tp.annot match
106
123
case ann : CaptureAnnotation => ann.boxed
107
124
case _ => false
125
+
0 commit comments