@@ -67,7 +67,7 @@ sealed abstract class CaptureSet extends Showable:
6767 * - take mutability from the set's sources (for DerivedVars)
6868 * - compute mutability on demand based on mutability of elements (for Consts)
6969 */
70- def associateWithMutable ()(using Context ): Unit
70+ def associateWithMutable ()(using Context ): CaptureSet
7171
7272 /** Is this capture set constant (i.e. not an unsolved capture variable)?
7373 * Solved capture variables count as constant.
@@ -566,9 +566,16 @@ object CaptureSet:
566566 val emptyRefs : Refs = SimpleIdentitySet .empty
567567
568568 /** The empty capture set `{}` */
569- @ sharable // sharable since the set is empty, so setMutable is a no-op
569+ @ sharable // sharable since the set is empty, so mutability won't be set
570570 val empty : CaptureSet .Const = Const (emptyRefs)
571571
572+ /** The empty capture set `{}` of a Mutable type, with Reader status */
573+ @ sharable // sharable since the set is empty, so mutability won't be set
574+ val emptyOfMutable : CaptureSet .Const =
575+ val cs = Const (emptyRefs)
576+ cs.mutability = Mutability .Reader
577+ cs
578+
572579 /** The universal capture set `{cap}` */
573580 def universal (using Context ): Const =
574581 Const (SimpleIdentitySet (GlobalCap ))
@@ -623,9 +630,11 @@ object CaptureSet:
623630
624631 private var isComplete = true
625632
626- def associateWithMutable ()(using Context ): Unit =
627- if ! elems.isEmpty then
633+ def associateWithMutable ()(using Context ): CaptureSet =
634+ if elems.isEmpty then emptyOfMutable
635+ else
628636 isComplete = false // delay computation of Mutability status
637+ this
629638
630639 override def mutability (using Context ): Mutability =
631640 if ! isComplete then
@@ -718,8 +727,9 @@ object CaptureSet:
718727 */
719728 var deps : Deps = SimpleIdentitySet .empty
720729
721- def associateWithMutable ()(using Context ): Unit =
730+ def associateWithMutable ()(using Context ): CaptureSet =
722731 mutability = Mutable
732+ this
723733
724734 def isConst (using Context ) = solved >= ccState.iterationId
725735 def isAlwaysEmpty (using Context ) = isConst && elems.isEmpty
@@ -1036,7 +1046,7 @@ object CaptureSet:
10361046 addAsDependentTo(source)
10371047
10381048 /** Mutability is same as in source, except for readOnly */
1039- override def associateWithMutable ()(using Context ): Unit = ()
1049+ override def associateWithMutable ()(using Context ): CaptureSet = this
10401050
10411051 override def mutableToReader (origin : CaptureSet )(using Context ): Boolean =
10421052 super .mutableToReader(origin)
0 commit comments