Skip to content

Commit 24ddd74

Browse files
committed
Polishings
Make tests in TypeComparer fit better with the rest
1 parent a587261 commit 24ddd74

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

Diff for: compiler/src/dotty/tools/dotc/cc/CaptureSet.scala

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import TypeComparer.subsumesExistentially
1818
import util.common.alwaysTrue
1919
import scala.collection.{mutable, immutable}
2020
import CCState.*
21-
import dotty.tools.dotc.core.TypeOps.AvoidMap
2221

2322
/** A class for capture sets. Capture sets can be constants or variables.
2423
* Capture sets support inclusion constraints <:< where <:< is subcapturing.

Diff for: compiler/src/dotty/tools/dotc/core/TypeComparer.scala

+13-22
Original file line numberDiff line numberDiff line change
@@ -298,19 +298,6 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
298298
}
299299
}
300300

301-
/** In capture checking, implements the logic to compare type variables which represent
302-
* capture variables.
303-
*
304-
* Note: should only be called in a context where tp1 or tp2 is a type variable representing a capture variable.
305-
*
306-
* @return -1 if tp1 or tp2 is not a capture variables, 1 if both tp1 and tp2 are capture variables and tp1 is a subcapture of tp2,
307-
* 0 if both tp1 and tp2 are capture variables but tp1 is not a subcapture of tp2.
308-
*/
309-
inline def tryHandleCaptureVars: Int =
310-
if !(isCaptureCheckingOrSetup && tp1.derivesFrom(defn.Caps_CapSet) && tp1.derivesFrom(defn.Caps_CapSet)) then -1
311-
else if (subCaptures(tp1.captureSet, tp2.captureSet, frozenConstraint).isOK) then 1
312-
else 0
313-
314301
def firstTry: Boolean = tp2 match {
315302
case tp2: NamedType =>
316303
def compareNamed(tp1: Type, tp2: NamedType): Boolean =
@@ -359,9 +346,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
359346
&& isSubPrefix(tp1.prefix, tp2.prefix)
360347
&& tp1.signature == tp2.signature
361348
&& !(sym1.isClass && sym2.isClass) // class types don't subtype each other
362-
|| {val cv = tryHandleCaptureVars
363-
if (cv < 0) then thirdTryNamed(tp2)
364-
else cv != 0 }
349+
|| thirdTryNamed(tp2)
365350
case _ =>
366351
secondTry
367352
end compareNamed
@@ -449,14 +434,15 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
449434

450435
def secondTry: Boolean = tp1 match {
451436
case tp1: NamedType =>
452-
val cv = tryHandleCaptureVars
453-
if (cv >= 0) then return cv != 0
454437
tp1.info match {
455438
case info1: TypeAlias =>
456439
if (recur(info1.alias, tp2)) return true
457440
if (tp1.prefix.isStable) return tryLiftedToThis1
458441
case _ =>
459-
if (tp1 eq NothingType) || isBottom(tp1) then return true
442+
if isCaptureVarComparison then
443+
return subCaptures(tp1.captureSet, tp2.captureSet, frozenConstraint).isOK
444+
if (tp1 eq NothingType) || isBottom(tp1) then
445+
return true
460446
}
461447
thirdTry
462448
case tp1: TypeParamRef =>
@@ -604,6 +590,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
604590
|| narrowGADTBounds(tp2, tp1, approx, isUpper = false))
605591
&& (isBottom(tp1) || GADTusage(tp2.symbol))
606592

593+
if isCaptureVarComparison then
594+
return subCaptures(tp1.captureSet, tp2.captureSet, frozenConstraint).isOK
595+
607596
isSubApproxHi(tp1, info2.lo) && (trustBounds || isSubApproxHi(tp1, info2.hi))
608597
|| compareGADT
609598
|| tryLiftedToThis2
@@ -878,9 +867,6 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
878867
def compareCapturing: Boolean =
879868
val refs1 = tp1.captureSet
880869
try
881-
if tp1.isInstanceOf[TypeRef] then
882-
val cv = tryHandleCaptureVars
883-
if (cv >= 0) then return (cv != 0)
884870
if refs1.isAlwaysEmpty then recur(tp1, parent2)
885871
else
886872
// The singletonOK branch is because we sometimes have a larger capture set in a singleton
@@ -1600,6 +1586,11 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
16001586
(tp2a ne tp2) && recur(tp1, tp2a) && { opaquesUsed = true; true }
16011587
}
16021588

1589+
def isCaptureVarComparison: Boolean =
1590+
isCaptureCheckingOrSetup
1591+
&& tp1.derivesFrom(defn.Caps_CapSet)
1592+
&& tp2.derivesFrom(defn.Caps_CapSet)
1593+
16031594
// begin recur
16041595
if tp2 eq NoType then false
16051596
else if tp1 eq tp2 then true

0 commit comments

Comments
 (0)