Skip to content

Commit

Permalink
Add alternative subsumes implementations
Browse files Browse the repository at this point in the history
This is done for comparing old with new
  • Loading branch information
odersky committed Sep 24, 2024
1 parent f04d285 commit dc4629a
Showing 1 changed file with 41 additions and 5 deletions.
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

0 comments on commit dc4629a

Please sign in to comment.