Skip to content

Commit c3a6bb3

Browse files
Rename disjoint to provablyDisjoint
The new name is explicit about the function output in case of uncertainty.
1 parent be54633 commit c3a6bb3

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,7 +2144,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
21442144
def provablyEmpty(tp: Type): Boolean =
21452145
tp.dealias match {
21462146
case tp if tp.isBottomType => true
2147-
case AndType(tp1, tp2) => disjoint(tp1, tp2)
2147+
case AndType(tp1, tp2) => provablyDisjoint(tp1, tp2)
21482148
case OrType(tp1, tp2) => provablyEmpty(tp1) && provablyEmpty(tp2)
21492149
case at @ AppliedType(tycon, args) =>
21502150
args.lazyZip(tycon.typeParams).exists { (arg, tparam) =>
@@ -2163,7 +2163,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
21632163
}
21642164

21652165

2166-
/** Are `tp1` and `tp2` disjoint types?
2166+
/** Are `tp1` and `tp2` provablyDisjoint types?
21672167
*
21682168
* `true` implies that we found a proof; uncertainty default to `false`.
21692169
*
@@ -2178,8 +2178,8 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
21782178
* property that in all possible contexts, a same match type expression
21792179
* is either stuck or reduces to the same case.
21802180
*/
2181-
def disjoint(tp1: Type, tp2: Type)(implicit ctx: Context): Boolean = {
2182-
// println(s"disjoint(${tp1.show}, ${tp2.show})")
2181+
def provablyDisjoint(tp1: Type, tp2: Type)(implicit ctx: Context): Boolean = {
2182+
// println(s"provablyDisjoint(${tp1.show}, ${tp2.show})")
21832183
/** Can we enumerate all instantiations of this type? */
21842184
def isClosedSum(tp: Symbol): Boolean =
21852185
tp.is(Sealed) && tp.isOneOf(AbstractOrTrait) && !tp.hasAnonymousChild
@@ -2212,9 +2212,9 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
22122212
// of classes.
22132213
true
22142214
else if (isClosedSum(cls1))
2215-
decompose(cls1, tp1).forall(x => disjoint(x, tp2))
2215+
decompose(cls1, tp1).forall(x => provablyDisjoint(x, tp2))
22162216
else if (isClosedSum(cls2))
2217-
decompose(cls2, tp2).forall(x => disjoint(x, tp1))
2217+
decompose(cls2, tp2).forall(x => provablyDisjoint(x, tp1))
22182218
else
22192219
false
22202220
case (AppliedType(tycon1, args1), AppliedType(tycon2, args2)) if tycon1 == tycon2 =>
@@ -2224,7 +2224,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
22242224
// (Type parameter disjointness is not enought by itself as it could
22252225
// lead to incorrect conclusions for phantom type parameters).
22262226
def covariantDisjoint(tp1: Type, tp2: Type, tparam: TypeParamInfo): Boolean =
2227-
disjoint(tp1, tp2) && productSelectorTypes(tycon1, null).exists {
2227+
provablyDisjoint(tp1, tp2) && productSelectorTypes(tycon1, null).exists {
22282228
case tp: TypeRef =>
22292229
(tp.designator: Any) == tparam // Bingo!
22302230
case _ =>
@@ -2258,29 +2258,29 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
22582258
}
22592259
}
22602260
case (tp1: HKLambda, tp2: HKLambda) =>
2261-
disjoint(tp1.resType, tp2.resType)
2261+
provablyDisjoint(tp1.resType, tp2.resType)
22622262
case (_: HKLambda, _) =>
2263-
// The intersection of these two types would be ill kinded, they are therefore disjoint.
2263+
// The intersection of these two types would be ill kinded, they are therefore provablyDisjoint.
22642264
true
22652265
case (_, _: HKLambda) =>
22662266
true
22672267
case (tp1: OrType, _) =>
2268-
disjoint(tp1.tp1, tp2) && disjoint(tp1.tp2, tp2)
2268+
provablyDisjoint(tp1.tp1, tp2) && provablyDisjoint(tp1.tp2, tp2)
22692269
case (_, tp2: OrType) =>
2270-
disjoint(tp1, tp2.tp1) && disjoint(tp1, tp2.tp2)
2270+
provablyDisjoint(tp1, tp2.tp1) && provablyDisjoint(tp1, tp2.tp2)
22712271
case (tp1: AndType, tp2: AndType) =>
2272-
(disjoint(tp1.tp1, tp2.tp1) || disjoint(tp1.tp2, tp2.tp2)) &&
2273-
(disjoint(tp1.tp1, tp2.tp2) || disjoint(tp1.tp2, tp2.tp1))
2272+
(provablyDisjoint(tp1.tp1, tp2.tp1) || provablyDisjoint(tp1.tp2, tp2.tp2)) &&
2273+
(provablyDisjoint(tp1.tp1, tp2.tp2) || provablyDisjoint(tp1.tp2, tp2.tp1))
22742274
case (tp1: AndType, _) =>
2275-
disjoint(tp1.tp2, tp2) || disjoint(tp1.tp1, tp2)
2275+
provablyDisjoint(tp1.tp2, tp2) || provablyDisjoint(tp1.tp1, tp2)
22762276
case (_, tp2: AndType) =>
2277-
disjoint(tp1, tp2.tp2) || disjoint(tp1, tp2.tp1)
2277+
provablyDisjoint(tp1, tp2.tp2) || provablyDisjoint(tp1, tp2.tp1)
22782278
case (tp1: TypeProxy, tp2: TypeProxy) =>
2279-
disjoint(tp1.underlying, tp2) || disjoint(tp1, tp2.underlying)
2279+
provablyDisjoint(tp1.underlying, tp2) || provablyDisjoint(tp1, tp2.underlying)
22802280
case (tp1: TypeProxy, _) =>
2281-
disjoint(tp1.underlying, tp2)
2281+
provablyDisjoint(tp1.underlying, tp2)
22822282
case (_, tp2: TypeProxy) =>
2283-
disjoint(tp1, tp2.underlying)
2283+
provablyDisjoint(tp1, tp2.underlying)
22842284
case _ =>
22852285
false
22862286
}
@@ -2455,7 +2455,7 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
24552455
}
24562456
else if (isSubType(widenAbstractTypes(scrut), widenAbstractTypes(pat)))
24572457
Some(NoType)
2458-
else if (disjoint(scrut, pat))
2458+
else if (provablyDisjoint(scrut, pat))
24592459
// We found a proof that `scrut` and `pat` are incompatible.
24602460
// The search continues.
24612461
None
@@ -2481,7 +2481,7 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
24812481
// `!provablyNonEmpty` instead of `provablyEmpty`, that would be
24822482
// obviously sound, but quite restrictive. With the current formulation,
24832483
// we need to be careful that `provablyEmpty` covers all the conditions
2484-
// used to conclude disjointness in `disjoint`.
2484+
// used to conclude disjointness in `provablyDisjoint`.
24852485
if (provablyEmpty(scrut))
24862486
NoType
24872487
else

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
302302
// Since projections of types don't include null, intersection with null is empty.
303303
if (tp1 == nullType || tp2 == nullType) Empty
304304
else {
305-
val res = ctx.typeComparer.disjoint(tp1, tp2)
305+
val res = ctx.typeComparer.provablyDisjoint(tp1, tp2)
306306

307307
if (res) Empty
308308
else if (tp1.isSingleton) Typ(tp1, true)
@@ -529,7 +529,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
529529

530530
def inhabited(tp: Type): Boolean =
531531
tp.dealias match {
532-
case AndType(tp1, tp2) => !ctx.typeComparer.disjoint(tp1, tp2)
532+
case AndType(tp1, tp2) => !ctx.typeComparer.provablyDisjoint(tp1, tp2)
533533
case OrType(tp1, tp2) => inhabited(tp1) || inhabited(tp2)
534534
case tp: RefinedType => inhabited(tp.parent)
535535
case tp: TypeRef => inhabited(tp.prefix)

0 commit comments

Comments
 (0)