Skip to content

Commit 9ecfbc1

Browse files
committed
Polish and comment CaptureSet
1 parent a158840 commit 9ecfbc1

File tree

4 files changed

+303
-127
lines changed

4 files changed

+303
-127
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ extension (tp: Type)
7373
then tp
7474
else tp.boxed
7575

76-
/** The capture set of `tp` consisting of all top-level captures under a box.
76+
/** The capture set consisting of all top-level captures of `tp` that appear under a box.
7777
* Unlike for `boxed` this also considers parents of capture types, unions and
7878
* intersections, and type proxies other than abstract types.
7979
*/
@@ -89,8 +89,12 @@ extension (tp: Type)
8989
case _ => CaptureSet.empty
9090
getBoxed(tp)
9191

92+
/** Is the boxedCaptureSet of this type nonempty? */
9293
def isBoxedCapturing(using Context) = !tp.boxedCaptureSet.isAlwaysEmpty
9394

95+
/** Map capturing type to their parents. Capturing types accessible
96+
* via dealising are also stripped.
97+
*/
9498
def stripCapturing(using Context): Type = tp.dealiasKeepAnnots match
9599
case CapturingType(parent, _) =>
96100
parent.stripCapturing
@@ -138,11 +142,15 @@ extension (sym: Symbol)
138142
&& !sym.allowsRootCapture
139143

140144
extension (tp: AnnotatedType)
145+
/** Is this a boxed capturing type? */
141146
def isBoxed(using Context): Boolean = tp.annot match
142147
case ann: CaptureAnnotation => ann.boxed
143148
case _ => false
144149

145150
extension (ts: List[Type])
151+
/** Equivalent to ts.mapconserve(_.boxedUnlessFun(tycon)) but more efficient where
152+
* it is the identity.
153+
*/
146154
def boxedUnlessFun(tycon: Type)(using Context) =
147155
if ctx.phase != Phases.checkCapturesPhase || defn.isFunctionClass(tycon.typeSymbol)
148156
then ts

0 commit comments

Comments
 (0)