Skip to content

Commit b132fbe

Browse files
committed
Refactoring: use isOK on CompareResult
1 parent 49adb26 commit b132fbe

File tree

5 files changed

+20
-22
lines changed

5 files changed

+20
-22
lines changed

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ sealed abstract class CaptureSet extends Showable:
9393
def accountsFor(x: CaptureRef)(using ctx: Context): Boolean =
9494
reporting.trace(i"$this accountsFor $x, ${x.captureSetOfInfo}?", show = true) {
9595
elems.contains(x)
96-
|| !x.isRootCapability
97-
&& x.captureSetOfInfo.subCaptures(this, frozen = true) == CompareResult.OK
96+
|| !x.isRootCapability && x.captureSetOfInfo.subCaptures(this, frozen = true).isOK
9897
}
9998

10099
/** The subcapturing test */
@@ -105,9 +104,9 @@ sealed abstract class CaptureSet extends Showable:
105104
def recur(elems: List[CaptureRef]): CompareResult = elems match
106105
case elem :: elems1 =>
107106
var result = that.tryInclude(elem, this)
108-
if result != CompareResult.OK && !elem.isRootCapability && summon[VarState] != FrozenState then
107+
if !result.isOK && !elem.isRootCapability && summon[VarState] != FrozenState then
109108
result = elem.captureSetOfInfo.subCaptures(that)
110-
if result == CompareResult.OK then
109+
if result.isOK then
111110
recur(elems1)
112111
else
113112
varState.abort()
@@ -118,15 +117,15 @@ sealed abstract class CaptureSet extends Showable:
118117
.showing(i"subcaptures $this <:< $that = ${result.show}", capt)
119118

120119
def =:= (that: CaptureSet)(using Context): Boolean =
121-
this.subCaptures(that, frozen = true) == CompareResult.OK
122-
&& that.subCaptures(this, frozen = true) == CompareResult.OK
120+
this.subCaptures(that, frozen = true).isOK
121+
&& that.subCaptures(this, frozen = true).isOK
123122

124123
/** The smallest capture set (via <:<) that is a superset of both
125124
* `this` and `that`
126125
*/
127126
def ++ (that: CaptureSet)(using Context): CaptureSet =
128-
if this.subCaptures(that, frozen = true) == CompareResult.OK then that
129-
else if that.subCaptures(this, frozen = true) == CompareResult.OK then this
127+
if this.subCaptures(that, frozen = true).isOK then that
128+
else if that.subCaptures(this, frozen = true).isOK then this
130129
else if this.isConst && that.isConst then Const(this.elems ++ that.elems)
131130
else Var(this.elems ++ that.elems).addSub(this).addSub(that)
132131

@@ -138,8 +137,8 @@ sealed abstract class CaptureSet extends Showable:
138137
/** The largest capture set (via <:<) that is a subset of both `this` and `that`
139138
*/
140139
def **(that: CaptureSet)(using Context): CaptureSet =
141-
if this.subCaptures(that, frozen = true) == CompareResult.OK then this
142-
else if that.subCaptures(this, frozen = true) == CompareResult.OK then that
140+
if this.subCaptures(that, frozen = true).isOK then this
141+
else if that.subCaptures(this, frozen = true).isOK then that
143142
else if this.isConst && that.isConst then Const(elems.intersect(that.elems))
144143
else if that.isConst then Intersected(this.asVar, that)
145144
else Intersected(that.asVar, this)
@@ -273,7 +272,7 @@ object CaptureSet:
273272
val depsIt = deps.iterator
274273
while depsIt.hasNext do
275274
val result = depsIt.next.tryInclude(newElems, this)
276-
if result != CompareResult.OK then return result
275+
if !result.isOK then return result
277276
CompareResult.OK
278277
else
279278
CompareResult.fail(this)
@@ -306,8 +305,7 @@ object CaptureSet:
306305
//println(i"solving var $this $approx ${approx.isConst} deps = ${deps.toList}")
307306
if approx.isConst then
308307
val newElems = approx.elems -- elems
309-
if newElems.isEmpty
310-
|| addNewElems(newElems, empty)(using ctx, VarState()) == CompareResult.OK then
308+
if newElems.isEmpty || addNewElems(newElems, empty)(using ctx, VarState()).isOK then
311309
markSolved()
312310

313311
def markSolved()(using Context): Unit =
@@ -362,7 +360,7 @@ object CaptureSet:
362360
return CompareResult.fail(this)
363361
Const(newElems)
364362
val result = super.addNewElems(added.elems, origin)
365-
if result == CompareResult.OK then
363+
if result.isOK then
366364
if added.isConst then result
367365
else if added.asVar.recordDepsState() then { addSub(added); result }
368366
else CompareResult.fail(this)
@@ -387,7 +385,7 @@ object CaptureSet:
387385
super.addNewElems(newElems.map(bimap.forward), origin)
388386
else
389387
val r = super.addNewElems(newElems, origin)
390-
if r == CompareResult.OK then
388+
if r.isOK then
391389
source.tryInclude(newElems.map(bimap.backward), this)
392390
.showing(i"propagating new elems $newElems backward from $this to $source", capt)
393391
else r
@@ -449,7 +447,7 @@ object CaptureSet:
449447
extension (result: Type)
450448
def isOK: Boolean = result eq OK
451449
def blocking: CaptureSet = result
452-
def show: String = if result == OK then "OK" else result.toString
450+
def show: String = if result.isOK then "OK" else result.toString
453451
inline def andAlso(op: => Type) = if result.isOK then op else result
454452

455453
class VarState:

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
491491
// under -Ycheck. Test case is i7965.scala.
492492

493493
case CapturingType(parent1, refs1, _) =>
494-
if subCaptures(refs1, tp2.captureSet, frozenConstraint) == CaptureSet.CompareResult.OK then
494+
if subCaptures(refs1, tp2.captureSet, frozenConstraint).isOK then
495495
recur(parent1, tp2)
496496
else
497497
thirdTry

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ object TypeOps:
166166
simplify(l, theMap) | simplify(r, theMap)
167167
case CapturingType(parent, refs, _) =>
168168
if !ctx.mode.is(Mode.Type)
169-
&& refs.subCaptures(parent.captureSet, frozen = true) == CompareResult.OK then
169+
&& refs.subCaptures(parent.captureSet, frozen = true).isOK then
170170
simplify(parent, theMap)
171171
else
172172
mapOver

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1849,7 +1849,7 @@ object Types {
18491849
else CapturingType(this, ref.singletonCaptureSet, this.isBoxedCapturing)
18501850

18511851
def capturing(cs: CaptureSet)(using Context): Type =
1852-
if cs.isConst && cs.subCaptures(captureSet, frozen = true) == CompareResult.OK then this
1852+
if cs.isConst && cs.subCaptures(captureSet, frozen = true).isOK then this
18531853
else this match
18541854
case CapturingType(parent, cs1, boxed) => parent.capturing(cs1 ++ cs)
18551855
case _ => CapturingType(this, cs, this.isBoxedCapturing)

compiler/src/dotty/tools/dotc/typer/CheckCaptures.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,16 @@ class CheckCaptures extends Recheck:
264264
checkSubset(targetSet, curEnv.captured, pos)
265265

266266
def assertSub(cs1: CaptureSet, cs2: CaptureSet)(using Context) =
267-
assert(cs1.subCaptures(cs2, frozen = false) == CompareResult.OK, i"$cs1 is not a subset of $cs2")
267+
assert(cs1.subCaptures(cs2, frozen = false).isOK, i"$cs1 is not a subset of $cs2")
268268

269269
def checkElem(elem: CaptureRef, cs: CaptureSet, pos: SrcPos)(using Context) =
270270
val res = elem.singletonCaptureSet.subCaptures(cs, frozen = false)
271-
if res != CompareResult.OK then
271+
if !res.isOK then
272272
report.error(i"$elem cannot be referenced here; it is not included in allowed capture set ${res.blocking}", pos)
273273

274274
def checkSubset(cs1: CaptureSet, cs2: CaptureSet, pos: SrcPos)(using Context) =
275275
val res = cs1.subCaptures(cs2, frozen = false)
276-
if res != CompareResult.OK then
276+
if !res.isOK then
277277
report.error(i"references $cs1 are not all included in allowed capture set ${res.blocking}", pos)
278278

279279
override def recheckClosure(tree: Closure, pt: Type)(using Context): Type =

0 commit comments

Comments
 (0)