Skip to content

Commit 61ca309

Browse files
committed
Revert to previous subsumes scheme
Add the path cases without changing the whole logic
1 parent dc4629a commit 61ca309

File tree

1 file changed

+12
-70
lines changed

1 file changed

+12
-70
lines changed

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

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

96+
/** x subsumes x
97+
* this subsumes this.f
98+
* x subsumes y ==> x* subsumes y, x subsumes y?
99+
* x subsumes y ==> x* subsumes y*, x? subsumes y?
100+
* x: x1.type /\ x1 subsumes y ==> x subsumes y
101+
* TODO: Document path cases
102+
*/
96103
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 =
104104
(this eq y)
105105
|| this.isRootCapability
106106
|| y.match
107107
case y: TermRef =>
108108
y.prefix.match
109109
case ypre: CaptureRef =>
110-
this.subsumesOld(ypre)
110+
this.subsumes(ypre)
111111
|| this.match
112112
case x @ TermRef(xpre: CaptureRef, _) =>
113113
x.symbol == y.symbol && xpre =:= ypre
114114
case _ =>
115115
false
116116
case _ => false
117117
|| y.info.match
118-
case y1: SingletonCaptureRef => this.subsumesOld(y1)
118+
case y1: SingletonCaptureRef => this.subsumes(y1)
119119
case _ => false
120-
case MaybeCapability(y1) => this.stripMaybe.subsumesOld(y1)
120+
case MaybeCapability(y1) => this.stripMaybe.subsumes(y1)
121121
case _ => false
122122
|| this.match
123-
case ReachCapability(x1) => x1.subsumesOld(y.stripReach)
123+
case ReachCapability(x1) => x1.subsumes(y.stripReach)
124124
case x: TermRef =>
125125
x.info match
126-
case x1: SingletonCaptureRef => x1.subsumesOld(y)
126+
case x1: SingletonCaptureRef => x1.subsumes(y)
127127
case _ => false
128128
case x: TermParamRef => subsumesExistentially(x, y)
129129
case x: TypeRef => assumedContainsOf(x).contains(y)
130130
case _ => false
131131

132-
/** x subsumes x
133-
* this subsumes this.f
134-
* x subsumes y ==> x* subsumes y, x subsumes y?
135-
* x subsumes y ==> x* subsumes y*, x? subsumes y?
136-
* x: x1.type /\ x1 subsumes y ==> x subsumes y
137-
*/
138-
final def subsumesNew(y: CaptureRef)(using Context): Boolean =
139-
def compareCaptureRefs(x: Type, y: Type): Boolean =
140-
(x eq y)
141-
|| y.match
142-
case y: CaptureRef => x.match
143-
case x: CaptureRef => x.subsumesNew(y)
144-
case _ => false
145-
case _ => false
146-
147-
def compareUndelying(x: Type): Boolean = x match
148-
case x: SingletonCaptureRef => x.subsumesNew(y)
149-
case x: AndType => compareUndelying(x.tp1) || compareUndelying(x.tp2)
150-
case x: OrType => compareUndelying(x.tp1) && compareUndelying(x.tp2)
151-
case _ => false
152-
153-
if (this eq y) || this.isRootCapability then return true
154-
155-
// similar to compareNamed in TypeComparer
156-
y match
157-
case y: TermRef =>
158-
this match
159-
case x: TermRef =>
160-
val xSym = x.symbol
161-
val ySym = y.symbol
162-
163-
// check x.f and y.f
164-
if (xSym ne NoSymbol)
165-
&& (xSym eq ySym)
166-
&& compareCaptureRefs(x.prefix, y.prefix)
167-
|| (x.name eq y.name)
168-
&& x.isPrefixDependentMemberRef
169-
&& compareCaptureRefs(x.prefix, y.prefix)
170-
&& x.signature == y.signature
171-
&& !(xSym.isClass && ySym.isClass)
172-
then return true
173-
case _ =>
174-
175-
// shorten
176-
if compareCaptureRefs(this, y.prefix) then return true
177-
// underlying
178-
if compareCaptureRefs(this, y.info) then return true
179-
case MaybeCapability(y1) => return this.stripMaybe.subsumesNew(y1)
180-
case _ =>
181-
182-
return this.match
183-
case ReachCapability(x1) => x1.subsumesNew(y.stripReach)
184-
case x: TermRef => compareUndelying(x.info)
185-
case CapturingType(x1, _) => compareUndelying(x1)
186-
case x: TermParamRef => subsumesExistentially(x, y)
187-
case x: TypeRef => assumedContainsOf(x).contains(y)
188-
case _ => false
189-
190132
def assumedContainsOf(x: TypeRef)(using Context): SimpleIdentitySet[CaptureRef] =
191133
CaptureSet.assumedContains.getOrElse(x, SimpleIdentitySet.empty)
192134

0 commit comments

Comments
 (0)