Skip to content

Commit f67c6fb

Browse files
committed
Add some more doc comments
1 parent 77f60a1 commit f67c6fb

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,10 @@ object Capabilities:
553553
*/
554554
def hiddenSet(using Context): Refs = computeHiddenSet(identity)
555555

556-
/** Compute hidden set of this capability.
556+
/** Compute result based on hidden set of this capability.
557557
* Restrictions and read-only status transfer from the capability to its
558558
* hidden set.
559+
* @param f a function that gets applied to all detected hidden sets
559560
*/
560561
def computeHiddenSet(f: Refs => Refs)(using Context): Refs = this match
561562
case self: FreshCap => f(self.hiddenSet.elems)

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,24 +151,37 @@ extension (tp: Type)
151151
case tp: ObjectCapability => tp.captureSetOfInfo
152152
case _ => CaptureSet.ofType(tp, followResult = false)
153153

154-
/** The deep capture set of a type. This is by default the union of all
154+
/** Compute a captureset by traversing parts of this type. This is by default the union of all
155155
* covariant capture sets embedded in the widened type, as computed by
156156
* `CaptureSet.ofTypeDeeply`. If that set is nonempty, and the type is
157157
* a singleton capability `x` or a reach capability `x*`, the deep capture
158158
* set can be narrowed to`{x*}`.
159+
* @param includeTypevars if true, return a new FreshCap for every type parameter
160+
* or abstract type with an Any upper bound. Types with
161+
* defined upper bound are always mapped to the dcs of their bound
162+
* @param includeBoxed if true, include capture sets found in boxed parts of this type
159163
*/
160-
def deepCaptureSet(includeTypevars: Boolean, includeBoxed: Boolean = true)(using Context): CaptureSet =
164+
def computeDeepCaptureSet(includeTypevars: Boolean, includeBoxed: Boolean = true)(using Context): CaptureSet =
161165
val dcs = CaptureSet.ofTypeDeeply(tp.widen.stripCapturing, includeTypevars, includeBoxed)
162166
if dcs.isAlwaysEmpty then tp.captureSet
163167
else tp match
164168
case tp: ObjectCapability if tp.isTrackableRef => tp.reach.singletonCaptureSet
165169
case _ => tp.captureSet ++ dcs
166170

171+
/** The deep capture set of a type. This is by default the union of all
172+
* covariant capture sets embedded in the widened type, as computed by
173+
* `CaptureSet.ofTypeDeeply`. If that set is nonempty, and the type is
174+
* a singleton capability `x` or a reach capability `x*`, the deep capture
175+
* set can be narrowed to`{x*}`.
176+
*/
167177
def deepCaptureSet(using Context): CaptureSet =
168-
deepCaptureSet(includeTypevars = false)
178+
computeDeepCaptureSet(includeTypevars = false)
169179

180+
/** The span capture set of a type. This is analogous to deepCaptureSet but ignoring
181+
* capture sets in boxed parts.
182+
*/
170183
def spanCaptureSet(using Context): CaptureSet =
171-
deepCaptureSet(includeTypevars = false, includeBoxed = false)
184+
computeDeepCaptureSet(includeTypevars = false, includeBoxed = false)
172185

173186
/** A type capturing `ref` */
174187
def capturing(ref: Capability)(using Context): Type =

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -950,8 +950,6 @@ object CaptureSet:
950950
override def toString = s"Var$id$elems"
951951
end Var
952952

953-
inline val strictFreshLevels = true
954-
955953
/** Variables created in types of inferred type trees */
956954
class ProperVar(override val owner: Symbol, initialElems: Refs = emptyRefs, nestedOK: Boolean = true, isRefining: Boolean)(using /*@constructorOnly*/ ictx: Context)
957955
extends Var(owner, initialElems, nestedOK):
@@ -971,7 +969,7 @@ object CaptureSet:
971969
def fail = i"attempting to add $elem to $this"
972970
def hideIn(fc: FreshCap): Unit =
973971
assert(elem.tryClassifyAs(fc.hiddenSet.classifier), fail)
974-
if strictFreshLevels && !isRefining then
972+
if !isRefining then
975973
// If a variable is added by addCaptureRefinements in a synthetic
976974
// refinement of a class type, don't do level checking. The problem is
977975
// that the variable might be matched against a type that does not have
@@ -1560,7 +1558,7 @@ object CaptureSet:
15601558
/** The capture set of the type underlying the capability `c` */
15611559
def ofInfo(c: Capability)(using Context): CaptureSet = c match
15621560
case Reach(c1) =>
1563-
c1.widen.deepCaptureSet(includeTypevars = true)
1561+
c1.widen.computeDeepCaptureSet(includeTypevars = true)
15641562
.showing(i"Deep capture set of $c: ${c1.widen} = ${result}", capt)
15651563
case Restricted(c1, cls) =>
15661564
if cls == defn.NothingClass then CaptureSet.empty

0 commit comments

Comments
 (0)