Skip to content

Adapt types according to read-only status #23332

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 14 commits into from
Jun 11, 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
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/cc/CCState.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,17 @@ class CCState:

// ------ Iteration count of capture checking run

private var iterCount = 1
private var iterCount = 0

def iterationId = iterCount

def nextIteration[T](op: => T): T =
iterCount += 1
try op finally iterCount -= 1

def start(): Unit =
iterCount = 1

// ------ Global counters -----------------------

/** Next CaptureSet.Var id */
Expand Down
6 changes: 6 additions & 0 deletions compiler/src/dotty/tools/dotc/cc/Capability.scala
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@ object Capabilities:
final def isExclusive(using Context): Boolean =
!isReadOnly && (isTerminalCapability || captureSetOfInfo.isExclusive)

/** Similar to isExlusive, but also includes capabilties with capture
* set variables in their info whose status is still open.
*/
final def maybeExclusive(using Context): Boolean =
!isReadOnly && (isTerminalCapability || captureSetOfInfo.maybeExclusive)

final def isWellformed(using Context): Boolean = this match
case self: CoreCapability => self.isTrackableRef
case _ => true
Expand Down
15 changes: 11 additions & 4 deletions compiler/src/dotty/tools/dotc/cc/CaptureOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ private val Captures: Key[CaptureSet] = Key()
def isCaptureChecking(using Context): Boolean =
ctx.phaseId == Phases.checkCapturesPhase.id

/** Are we at checkCaptures or Setup phase? */
/** Are we in the CheckCaptures or Setup phase? */
def isCaptureCheckingOrSetup(using Context): Boolean =
val ccId = Phases.checkCapturesPhase.id
val ctxId = ctx.phaseId
ctxId == ccId || ctxId == ccId - 1
val ccPhase = Phases.checkCapturesPhase
ccPhase.exists
&& {
val ccId = ccPhase.id
val ctxId = ctx.phaseId
ctxId == ccId
|| ctxId == ccId - 1 && ccState.iterationId > 0
// Note: just checking phase id is not enough since Setup would
// also be the phase after pattern matcher.
}

/** A dependent function type with given arguments and result type
* TODO Move somewhere else where we treat all function type related ops together.
Expand Down
Loading
Loading