Skip to content

Cache ResultCaps #23198

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

Merged
merged 10 commits into from
May 21, 2025
Merged
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
17 changes: 9 additions & 8 deletions compiler/src/dotty/tools/dotc/cc/CCState.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class CCState:

private var capIsRoot: Boolean = false

private var ignoreFreshLevels: Boolean = false
private var collapseFresh: Boolean = false

object CCState:

Expand Down Expand Up @@ -164,20 +164,21 @@ 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
* to each other and to GlobalCap.
* 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.
*/
inline def ignoringFreshLevels[T](op: => T)(using Context): T =
inline def withCollapsedFresh[T](op: => T)(using Context): T =
if isCaptureCheckingOrSetup then
val ccs = ccState
val saved = ccs.ignoreFreshLevels
ccs.ignoreFreshLevels = true
try op finally ccs.ignoreFreshLevels = saved
val saved = ccs.collapseFresh
ccs.collapseFresh = true
try op finally ccs.collapseFresh = saved
else op

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

end CCState
Loading
Loading