Skip to content

Cleanups for capability refactorings #23182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/cc/CCState.scala
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ object CCState:
/** Is `caps.cap` a root capability that is allowed to subsume other capabilities? */
def capIsRoot(using Context): Boolean = ccState.capIsRoot

/** Run `op` under the assumption that all root.Fresh instances are equal.
/** Run `op` under the assumption that all FreshCap instances are equal.
* Needed to make override checking of types containing fresh work.
* Asserted in override checking, tested in maxSubsumes.
* Is this sound? Test case is neg-custom-args/captures/leaked-curried.scala.
Expand All @@ -177,7 +177,7 @@ object CCState:
try op finally ccs.ignoreFreshLevels = saved
else op

/** Should all root.Fresh instances be treated equal? */
/** Should all FreshCap instances be treated equal? */
def ignoreFreshLevels(using Context): Boolean = ccState.ignoreFreshLevels

end CCState
811 changes: 811 additions & 0 deletions compiler/src/dotty/tools/dotc/cc/Capability.scala

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions compiler/src/dotty/tools/dotc/cc/CaptureAnnotation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Decorators.*
import config.Printers.capt
import printing.Printer
import printing.Texts.Text
import cc.Capabilities.{Capability, RootCapability}

/** An annotation representing a capture set and whether it is boxed.
* It simulates a normal @retains annotation except that it is more efficient,
Expand Down Expand Up @@ -39,10 +40,10 @@ case class CaptureAnnotation(refs: CaptureSet, boxed: Boolean)(cls: Symbol) exte
/** Reconstitute annotation tree from capture set */
override def tree(using Context) =
val elems = refs.elems.toList.map {
case cr: TermRef => ref(cr)
case cr: TermParamRef => untpd.Ident(cr.paramName).withType(cr)
case cr: ThisType => This(cr.cls)
case root(_) => ref(root.cap)
case c: TermRef => ref(c)
case c: TermParamRef => untpd.Ident(c.paramName).withType(c)
case c: ThisType => This(c.cls)
case c: RootCapability => ref(defn.captureRoot)
// TODO: Will crash if the type is an annotated type, for example `cap.rd`
}
val arg = repeated(elems, TypeTree(defn.AnyType))
Expand All @@ -63,10 +64,12 @@ case class CaptureAnnotation(refs: CaptureSet, boxed: Boolean)(cls: Symbol) exte

override def mapWith(tm: TypeMap)(using Context) =
val elems = refs.elems.toList
val elems1 = elems.mapConserve(tm)
val elems1 = elems.mapConserve(tm.mapCapability(_))
if elems1 eq elems then this
else if elems1.forall(_.isTrackableRef)
then derivedAnnotation(CaptureSet(elems1.asInstanceOf[List[CaptureRef]]*), boxed)
else if elems1.forall:
case elem1: Capability => elem1.isWellformed
case _ => false
then derivedAnnotation(CaptureSet(elems1.asInstanceOf[List[Capability]]*), boxed)
else EmptyAnnotation

override def refersToParamOf(tl: TermLambda)(using Context): Boolean =
Expand Down
Loading
Loading