Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,8 @@ trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped]
}
}

/** Under pureFunctions: A builder and extractor for `=> T`, which is an alias for `->{cap} T`.
* Only trees of the form `=> T` are matched; trees written directly as `->{cap} T`
/** Under pureFunctions: A builder and extractor for `=> T`, which is an alias for `->{any} T`.
* Only trees of the form `=> T` are matched; trees written directly as `->{any} T`
* are ignored by the extractor.
*/
object ImpureByNameTypeTree:
Expand All @@ -535,7 +535,7 @@ trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped]

def unapply(tp: Tree)(using Context): Option[Tree] = tp match
case untpd.ByNameTypeTree(
untpd.CapturesAndResult(id @ Select(_, nme.CAPTURE_ROOT) :: Nil, result))
untpd.CapturesAndResult(id @ Select(_, nme.any) :: Nil, result))
if id.span == result.span.startPos => Some(result)
case _ => None
end ImpureByNameTypeTree
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
Select(Select(scalaDot(nme.caps), nme.internal), name)

def captureRoot(using Context): Select =
Select(scalaDot(nme.caps), nme.CAPTURE_ROOT)
Select(scalaDot(nme.caps), nme.any)

def makeRetaining(parent: Tree, refs: List[Tree], annotName: TypeName)(using Context): Annotated =
var annot: Tree = scalaAnnotationDot(annotName)
Expand Down
36 changes: 18 additions & 18 deletions compiler/src/dotty/tools/dotc/cc/CCState.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ class CCState:

private var openExistentialScopes: List[MethodType] = Nil

private var capIsRoot: Boolean = false
private var globalCapIsRoot: Boolean = false

private var collapseFresh: Boolean = false
private var collapseLocalCaps: Boolean = false

private var discardUses: Boolean = false

Expand All @@ -112,37 +112,37 @@ object CCState:
/** The currently opened existential scopes */
def openExistentialScopes(using Context): List[MethodType] = ccState.openExistentialScopes

/** Run `op` under the assumption that `cap` can subsume all other capabilties
/** Run `op` under the assumption that `caps.any` can subsume all other capabilties
* except Result capabilities. Every use of this method should be scrutinized
* for whether it introduces an unsoundness hole.
*/
inline def withCapAsRoot[T](op: => T)(using Context): T =
inline def withGlobalCapAsRoot[T](op: => T)(using Context): T =
if isCaptureCheckingOrSetup then
val ccs = ccState
val saved = ccs.capIsRoot
ccs.capIsRoot = true
try op finally ccs.capIsRoot = saved
val saved = ccs.globalCapIsRoot
ccs.globalCapIsRoot = true
try op finally ccs.globalCapIsRoot = saved
else op

/** Is `caps.cap` a root capability that is allowed to subsume other capabilities? */
def capIsRoot(using Context): Boolean = ccState.capIsRoot
/** Is `caps.any` a root capability that is allowed to subsume other capabilities? */
def globalCapIsRoot(using Context): Boolean = ccState.globalCapIsRoot

/** Run `op` under the assumption that all FreshCap instances are equal
* to each other and to GlobalCap.
* Needed to make override checking of types containing fresh work.
/** Run `op` under the assumption that all LocalCap instances are equal
* to each other and to GlobalAny.
* Needed to make override checking work for types containing LocalCaps.
* Asserted in override checking, tested in maxSubsumes.
* Is this sound? Test case is neg-custom-args/captures/leaked-curried.scala.
*/
inline def withCollapsedFresh[T](op: => T)(using Context): T =
inline def withCollapsedLocalCaps[T](op: => T)(using Context): T =
if isCaptureCheckingOrSetup then
val ccs = ccState
val saved = ccs.collapseFresh
ccs.collapseFresh = true
try op finally ccs.collapseFresh = saved
val saved = ccs.collapseLocalCaps
ccs.collapseLocalCaps = true
try op finally ccs.collapseLocalCaps = saved
else op

/** Should all FreshCap instances be treated as equal to GlobalCap? */
def collapseFresh(using Context): Boolean = ccState.collapseFresh
/** Should all LocalCap instances be treated as equal to GlobalAny? */
def collapseLocalCaps(using Context): Boolean = ccState.collapseLocalCaps

/** Run `op` but suppress all recording of uses in `markFree` */
inline def withDiscardedUses[T](op: => T)(using Context): T =
Expand Down
Loading
Loading