Skip to content

Go back towards a pure capability system #21764

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
wants to merge 17 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add alternative subsumes implementations
This is done for comparing old with new
  • Loading branch information
odersky committed Sep 25, 2024
commit 440c053213ae75f6fb68581cf9a3ecb4e30785e7
46 changes: 41 additions & 5 deletions compiler/src/dotty/tools/dotc/cc/CaptureRef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,59 @@ trait CaptureRef extends TypeProxy, ValueType:
final def invalidateCaches() =
myCaptureSetRunId = NoRunId

final def subsumes(y: CaptureRef)(using Context): Boolean =
val was = subsumesOld(y)
val now = subsumesNew(y)
if was != now then
println(i"diff for $this subsumes $y, now: $now, ${this.getClass}, ${y.getClass}")
was

final def subsumesOld(y: CaptureRef)(using Context): Boolean =
(this eq y)
|| this.isRootCapability
|| y.match
case y: TermRef =>
y.prefix.match
case ypre: CaptureRef =>
this.subsumesOld(ypre)
|| this.match
case x @ TermRef(xpre: CaptureRef, _) =>
x.symbol == y.symbol && xpre =:= ypre
case _ =>
false
case _ => false
|| y.info.match
case y1: SingletonCaptureRef => this.subsumesOld(y1)
case _ => false
case MaybeCapability(y1) => this.stripMaybe.subsumesOld(y1)
case _ => false
|| this.match
case ReachCapability(x1) => x1.subsumesOld(y.stripReach)
case x: TermRef =>
x.info match
case x1: SingletonCaptureRef => x1.subsumesOld(y)
case _ => false
case x: TermParamRef => subsumesExistentially(x, y)
case x: TypeRef => assumedContainsOf(x).contains(y)
case _ => false

/** x subsumes x
* this subsumes this.f
* x subsumes y ==> x* subsumes y, x subsumes y?
* x subsumes y ==> x* subsumes y*, x? subsumes y?
* x: x1.type /\ x1 subsumes y ==> x subsumes y
*/
final def subsumes(y: CaptureRef)(using Context): Boolean =
final def subsumesNew(y: CaptureRef)(using Context): Boolean =
def compareCaptureRefs(x: Type, y: Type): Boolean =
(x eq y)
|| y.match
case y: CaptureRef => x.match
case x: CaptureRef => x.subsumes(y)
case x: CaptureRef => x.subsumesNew(y)
case _ => false
case _ => false

def compareUndelying(x: Type): Boolean = x match
case x: SingletonCaptureRef => x.subsumes(y)
case x: SingletonCaptureRef => x.subsumesNew(y)
case x: AndType => compareUndelying(x.tp1) || compareUndelying(x.tp2)
case x: OrType => compareUndelying(x.tp1) && compareUndelying(x.tp2)
case _ => false
Expand Down Expand Up @@ -140,11 +176,11 @@ trait CaptureRef extends TypeProxy, ValueType:
if compareCaptureRefs(this, y.prefix) then return true
// underlying
if compareCaptureRefs(this, y.info) then return true
case MaybeCapability(y1) => return this.stripMaybe.subsumes(y1)
case MaybeCapability(y1) => return this.stripMaybe.subsumesNew(y1)
case _ =>

return this.match
case ReachCapability(x1) => x1.subsumes(y.stripReach)
case ReachCapability(x1) => x1.subsumesNew(y.stripReach)
case x: TermRef => compareUndelying(x.info)
case CapturingType(x1, _) => compareUndelying(x1)
case x: TermParamRef => subsumesExistentially(x, y)
Expand Down