@@ -183,7 +183,7 @@ sealed abstract class CaptureSet extends Showable:
183183 */
184184 def accountsFor (x : CaptureRef )(using ctx : Context )(using vs : VarState = VarState .Separate ): Boolean =
185185
186- def debugInfo (using Context ) = i " $this accountsFor $x, which has capture set ${x.captureSetOfInfo} "
186+ def debugInfo (using Context ) = i " $this accountsFor $x"
187187
188188 def test (using Context ) = reporting.trace(debugInfo):
189189 elems.exists(_.subsumes(x))
@@ -353,7 +353,14 @@ sealed abstract class CaptureSet extends Showable:
353353
354354 /** Invoke handler if this set has (or later aquires) the root capability `cap` */
355355 def disallowRootCapability (handler : () => Context ?=> Unit )(using Context ): this .type =
356- if containsRootCapability then handler()
356+ val hasRoot =
357+ if ccConfig.newScheme then
358+ elems.exists: elem =>
359+ val elem1 = elem.stripReadOnly
360+ elem1.isCap || elem1.isResultRoot
361+ else
362+ containsRootCapability
363+ if hasRoot then handler()
357364 this
358365
359366 /** Invoke handler on the elements to ensure wellformedness of the capture set.
@@ -499,7 +506,7 @@ object CaptureSet:
499506 ccs.varId += 1
500507 ccs.varId
501508
502- // assert(id != 40 )
509+ // assert(id != 8, this )
503510
504511 /** A variable is solved if it is aproximated to a from-then-on constant set.
505512 * Interpretation:
@@ -529,7 +536,7 @@ object CaptureSet:
529536 /** A handler to be invoked if the root reference `cap` is added to this set */
530537 var rootAddedHandler : () => Context ?=> Unit = () => ()
531538
532- private [CaptureSet ] var noUniversal = false
539+ private [CaptureSet ] var universalOK = true
533540
534541 /** A handler to be invoked when new elems are added to this set */
535542 var newElemAddedHandler : CaptureRef => Context ?=> Unit = _ => ()
@@ -600,33 +607,38 @@ object CaptureSet:
600607 case _ => foldOver(b, t)
601608 find(false , binder)
602609
603- // TODO: Also track allowable TermParamRefs and root.Results in capture sets
604- private def levelOK (elem : CaptureRef )(using Context ): Boolean =
605- if elem.isRootCapability then
606- ! noUniversal
607- else elem match
608- case elem @ root.Result (mt) =>
609- ! noUniversal && isPartOf(mt.resType)
610- case elem : TermRef if level.isDefined =>
611- elem.prefix match
612- case prefix : CaptureRef =>
613- levelOK(prefix)
614- case _ =>
615- ccState.symLevel(elem.symbol) <= level
616- case elem : ThisType if level.isDefined =>
617- ccState.symLevel(elem.cls).nextInner <= level
618- case elem : ParamRef if ! this .isInstanceOf [BiMapped ] =>
619- isPartOf(elem.binder.resType)
620- || {
621- capt.println(
622- i """ LEVEL ERROR $elem for $this
623- |elem binder = ${elem.binder}""" )
610+ private def levelOK (elem : CaptureRef )(using Context ): Boolean = elem match
611+ case elem @ root.Fresh (_) =>
612+ if ccConfig.newScheme then
613+ if ! level.isDefined || ccState.symLevel(elem.ccOwner) <= level then true
614+ else
615+ println(i " LEVEL ERROR $elem cannot be included in $this of $owner" )
624616 false
625- }
626- case QualifiedCapability (elem1) =>
627- levelOK(elem1)
628- case _ =>
629- true
617+ else universalOK
618+ case elem @ root.Result (mt) =>
619+ universalOK && (this .isInstanceOf [BiMapped ] || isPartOf(mt.resType))
620+ case elem : TermRef if elem.isCap =>
621+ universalOK
622+ case elem : TermRef if level.isDefined =>
623+ elem.prefix match
624+ case prefix : CaptureRef =>
625+ levelOK(prefix)
626+ case _ =>
627+ ccState.symLevel(elem.symbol) <= level
628+ case elem : ThisType if level.isDefined =>
629+ ccState.symLevel(elem.cls).nextInner <= level
630+ case elem : ParamRef if ! this .isInstanceOf [BiMapped ] =>
631+ isPartOf(elem.binder.resType)
632+ || {
633+ capt.println(
634+ i """ LEVEL ERROR $elem for $this
635+ |elem binder = ${elem.binder}""" )
636+ false
637+ }
638+ case QualifiedCapability (elem1) =>
639+ levelOK(elem1)
640+ case _ =>
641+ true
630642
631643 def addDependent (cs : CaptureSet )(using Context , VarState ): CompareResult =
632644 if (cs eq this ) || cs.isUniversal || isConst then
@@ -638,7 +650,7 @@ object CaptureSet:
638650 CompareResult .Fail (this :: Nil )
639651
640652 override def disallowRootCapability (handler : () => Context ?=> Unit )(using Context ): this .type =
641- noUniversal = true
653+ universalOK = false
642654 rootAddedHandler = handler
643655 super .disallowRootCapability(handler)
644656
0 commit comments