Skip to content

Commit 316bdc3

Browse files
committed
Generalize isAlwaysEmpty and streamline isBoxedCaptured
- isBoxedCaptured no longer requires the construction of intermediate capture sets. - isAlwaysEmpty is also true for solved variables that have no elements
1 parent 073fe4c commit 316bdc3

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,15 @@ extension (tp: Type)
197197
getBoxed(tp)
198198

199199
/** Is the boxedCaptureSet of this type nonempty? */
200-
def isBoxedCapturing(using Context) = !tp.boxedCaptureSet.isAlwaysEmpty
200+
def isBoxedCapturing(using Context): Boolean =
201+
tp match
202+
case tp @ CapturingType(parent, refs) =>
203+
tp.isBoxed && !refs.isAlwaysEmpty || parent.isBoxedCapturing
204+
case tp: TypeRef if tp.symbol.isAbstractOrParamType => false
205+
case tp: TypeProxy => tp.superType.isBoxedCapturing
206+
case tp: AndType => tp.tp1.isBoxedCapturing && tp.tp2.isBoxedCapturing
207+
case tp: OrType => tp.tp1.isBoxedCapturing || tp.tp2.isBoxedCapturing
208+
case _ => false
201209

202210
/** If this type is a capturing type, the version with boxed statues as given by `boxed`.
203211
* If it is a TermRef of a capturing type, and the box status flips, widen to a capturing

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ object CaptureSet:
459459
var deps: Deps = emptySet
460460

461461
def isConst = isSolved
462-
def isAlwaysEmpty = false
462+
def isAlwaysEmpty = isSolved && elems.isEmpty
463463

464464
def isMaybeSet = false // overridden in BiMapped
465465

0 commit comments

Comments
 (0)