Skip to content

Commit 2770688

Browse files
committed
Simplify
Removes ad-hoc CapSet detection and capture set computation
1 parent 422ae18 commit 2770688

File tree

3 files changed

+5
-35
lines changed

3 files changed

+5
-35
lines changed

Diff for: compiler/src/dotty/tools/dotc/cc/CaptureOps.scala

-26
Original file line numberDiff line numberDiff line change
@@ -170,32 +170,6 @@ extension (tree: Tree)
170170

171171
extension (tp: Type)
172172

173-
/**
174-
* Is the type `tp` a `CapSet` type, i.e., a capture variable?
175-
*
176-
* @param tp The type to check
177-
* @param includeCapSet Whether to include the bare `CapSet` type itself in the check, false at the top level
178-
*/
179-
final def isCapSet(includeCapSet: Boolean = false)(using Context): Boolean = tp match
180-
case tp: TypeRef => (includeCapSet && (tp.symbol eq defn.Caps_CapSet)) || {
181-
tp.underlying match
182-
case TypeBounds(lo, hi) => lo.isCapSet(true) && hi.isCapSet(true)
183-
case TypeAlias(alias) => alias.isCapSet() // TODO: test cases involving type aliases
184-
case _ => false
185-
}
186-
case tp: SingletonType => tp.underlying.isCapSet()
187-
case CapturingType(parent, _) => parent.isCapSet(true)
188-
case _ => false
189-
190-
/**
191-
* The capture set of a capture variable. Assumes that tp.isCapSet() is true.
192-
*/
193-
final def captureSetOfCapSet(using Context): CaptureSet = tp match
194-
case CapturingType(_,c) => c
195-
case tp: TypeRef if tp.symbol eq defn.Caps_CapSet => CaptureSet.empty
196-
case tp: SingletonType => tp.underlying.captureSetOfCapSet
197-
case tp: CaptureRef => CaptureSet(tp)
198-
199173
/** Is this type a CaptureRef that can be tracked?
200174
* This is true for
201175
* - all ThisTypes and all TermParamRef,

Diff for: compiler/src/dotty/tools/dotc/cc/CaptureSet.scala

+3-7
Original file line numberDiff line numberDiff line change
@@ -1073,9 +1073,6 @@ object CaptureSet:
10731073
case ReachCapability(ref1) =>
10741074
ref1.widen.deepCaptureSet(includeTypevars = true)
10751075
.showing(i"Deep capture set of $ref: ${ref1.widen} = ${result}", capt)
1076-
case tp : TypeRef if tp.isCapSet() => tp.underlying match
1077-
case TypeBounds(lo, hi) if hi.isCapSet() => hi.captureSetOfCapSet
1078-
case _ => ofType(ref.underlying, followResult = true)
10791076
case _ =>
10801077
if ref.isMaxCapability then ref.singletonCaptureSet
10811078
else ofType(ref.underlying, followResult = true)
@@ -1088,10 +1085,9 @@ object CaptureSet:
10881085
tp.captureSet
10891086
case tp: TermParamRef =>
10901087
tp.captureSet
1091-
case _: TypeRef =>
1092-
empty
1093-
case _: TypeParamRef =>
1094-
empty
1088+
case tp: (TypeRef | TypeParamRef) =>
1089+
if tp.derivesFrom(defn.Caps_CapSet) then tp.captureSet
1090+
else empty
10951091
case CapturingType(parent, refs) =>
10961092
recur(parent) ++ refs
10971093
case tp @ AnnotatedType(parent, ann) if ann.hasSymbol(defn.ReachCapabilityAnnot) =>

Diff for: compiler/src/dotty/tools/dotc/core/TypeComparer.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
307307
* 0 if both tp1 and tp2 are capture variables but tp1 is not a subcapture of tp2.
308308
*/
309309
inline def tryHandleCaptureVars: Int =
310-
if !(isCaptureCheckingOrSetup && tp1.isCapSet() && tp2.isCapSet()) then -1
311-
else if (subCaptures(tp1.captureSetOfCapSet, tp2.captureSetOfCapSet, frozenConstraint).isOK) then 1
310+
if !(isCaptureCheckingOrSetup && tp1.derivesFrom(defn.Caps_CapSet) && tp1.derivesFrom(defn.Caps_CapSet)) then -1
311+
else if (subCaptures(tp1.captureSet, tp2.captureSet, frozenConstraint).isOK) then 1
312312
else 0
313313

314314
def firstTry: Boolean = tp2 match {

0 commit comments

Comments
 (0)