Skip to content

Commit c6fd3c6

Browse files
committed
Document ConstraintHandling, Constraint methods
1 parent 3cc8914 commit c6fd3c6

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,16 @@ abstract class Constraint extends Showable {
4545
/** The parameters that are known to be greater wrt <: than `param` */
4646
def upper(param: TypeParamRef): List[TypeParamRef]
4747

48-
/** `lower`, except that `minLower.forall(tpr => !minLower.exists(_ <:< tpr))` */
48+
/** The lower dominator set.
49+
*
50+
* This is like `lower`, except that each parameter returned is no smaller than every other returned parameter.
51+
*/
4952
def minLower(param: TypeParamRef): List[TypeParamRef]
5053

51-
/** `upper`, except that `minUpper.forall(tpr => !minUpper.exists(tpr <:< _))` */
54+
/** The upper dominator set.
55+
*
56+
* This is like `upper`, except that each parameter returned is no greater than every other returned parameter.
57+
*/
5258
def minUpper(param: TypeParamRef): List[TypeParamRef]
5359

5460
/** lower(param) \ lower(butNot) */

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ trait ConstraintHandling[AbstractContext] {
3030

3131
protected def isSubType(tp1: Type, tp2: Type)(implicit actx: AbstractContext): Boolean
3232
protected def isSameType(tp1: Type, tp2: Type)(implicit actx: AbstractContext): Boolean
33+
34+
/** LUB of `tp1`, `tp2`.
35+
*
36+
* This should always be used instead of `tp1 | tp2`- it allows subclasses to change how
37+
* type lubs are approximated.
38+
*
39+
* Normally when we take a LUB of two types (as in [[TypeComparer.lub]]), we may approximate it -
40+
* for instance, we can approximate `String("a") | String("b")` as `String`. The way we can do that in
41+
* ConstraintHandling depends on how we can approximate the constraint itself - it's not always sound to,
42+
* for instance, simplify `a >: String("a") | String("b")` to `a >: String`.
43+
*
44+
* For type inference (the Constraint in TyperState), we can approximate a constraint C by a constraint C'
45+
* only if all solutions to C' are also solutions to C (solving C' must be _sufficient_ for solving C).
46+
*
47+
* For GADT constraint inference, we can only do that if all solutions to C are also solutions to C'
48+
* (solving C' is _necessary_ for solving C).
49+
*/
3350
protected def typeLub(tp1: Type, tp2: Type)(implicit actx: AbstractContext): Type
3451

3552
protected def constraint: Constraint

0 commit comments

Comments
 (0)