Skip to content

Commit dc4629a

Browse files
committed
Add alternative subsumes implementations
This is done for comparing old with new
1 parent f04d285 commit dc4629a

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureRef.scala

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,59 @@ trait CaptureRef extends TypeProxy, ValueType:
9393
final def invalidateCaches() =
9494
myCaptureSetRunId = NoRunId
9595

96+
final def subsumes(y: CaptureRef)(using Context): Boolean =
97+
val was = subsumesOld(y)
98+
val now = subsumesNew(y)
99+
if was != now then
100+
println(i"diff for $this subsumes $y, now: $now, ${this.getClass}, ${y.getClass}")
101+
was
102+
103+
final def subsumesOld(y: CaptureRef)(using Context): Boolean =
104+
(this eq y)
105+
|| this.isRootCapability
106+
|| y.match
107+
case y: TermRef =>
108+
y.prefix.match
109+
case ypre: CaptureRef =>
110+
this.subsumesOld(ypre)
111+
|| this.match
112+
case x @ TermRef(xpre: CaptureRef, _) =>
113+
x.symbol == y.symbol && xpre =:= ypre
114+
case _ =>
115+
false
116+
case _ => false
117+
|| y.info.match
118+
case y1: SingletonCaptureRef => this.subsumesOld(y1)
119+
case _ => false
120+
case MaybeCapability(y1) => this.stripMaybe.subsumesOld(y1)
121+
case _ => false
122+
|| this.match
123+
case ReachCapability(x1) => x1.subsumesOld(y.stripReach)
124+
case x: TermRef =>
125+
x.info match
126+
case x1: SingletonCaptureRef => x1.subsumesOld(y)
127+
case _ => false
128+
case x: TermParamRef => subsumesExistentially(x, y)
129+
case x: TypeRef => assumedContainsOf(x).contains(y)
130+
case _ => false
131+
96132
/** x subsumes x
97133
* this subsumes this.f
98134
* x subsumes y ==> x* subsumes y, x subsumes y?
99135
* x subsumes y ==> x* subsumes y*, x? subsumes y?
100136
* x: x1.type /\ x1 subsumes y ==> x subsumes y
101137
*/
102-
final def subsumes(y: CaptureRef)(using Context): Boolean =
138+
final def subsumesNew(y: CaptureRef)(using Context): Boolean =
103139
def compareCaptureRefs(x: Type, y: Type): Boolean =
104140
(x eq y)
105141
|| y.match
106142
case y: CaptureRef => x.match
107-
case x: CaptureRef => x.subsumes(y)
143+
case x: CaptureRef => x.subsumesNew(y)
108144
case _ => false
109145
case _ => false
110146

111147
def compareUndelying(x: Type): Boolean = x match
112-
case x: SingletonCaptureRef => x.subsumes(y)
148+
case x: SingletonCaptureRef => x.subsumesNew(y)
113149
case x: AndType => compareUndelying(x.tp1) || compareUndelying(x.tp2)
114150
case x: OrType => compareUndelying(x.tp1) && compareUndelying(x.tp2)
115151
case _ => false
@@ -140,11 +176,11 @@ trait CaptureRef extends TypeProxy, ValueType:
140176
if compareCaptureRefs(this, y.prefix) then return true
141177
// underlying
142178
if compareCaptureRefs(this, y.info) then return true
143-
case MaybeCapability(y1) => return this.stripMaybe.subsumes(y1)
179+
case MaybeCapability(y1) => return this.stripMaybe.subsumesNew(y1)
144180
case _ =>
145181

146182
return this.match
147-
case ReachCapability(x1) => x1.subsumes(y.stripReach)
183+
case ReachCapability(x1) => x1.subsumesNew(y.stripReach)
148184
case x: TermRef => compareUndelying(x.info)
149185
case CapturingType(x1, _) => compareUndelying(x1)
150186
case x: TermParamRef => subsumesExistentially(x, y)

0 commit comments

Comments
 (0)