Skip to content

Commit 5a57ae5

Browse files
committed
Simplify adjust
Half of what it does is now handled in constraint itself
1 parent 462279c commit 5a57ae5

File tree

1 file changed

+8
-26
lines changed

1 file changed

+8
-26
lines changed

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

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -90,39 +90,22 @@ trait ConstraintHandling[AbstractContext] {
9090

9191
/** Adjust the bound `tp` in the following ways:
9292
*
93-
* 1. Any toplevel occurrences of the compared parameter `param` are
94-
* replaced by `Nothing` if bound is from below or `Any` otherwise.
95-
* 2. Toplevel occurrences of TypeVars over TypeRefs in the current
96-
* constraint are dereferenced.
97-
* 3. Toplevel occurrences of TypeRefs that are instantiated in the current
93+
* 1. Toplevel occurrences of TypeRefs that are instantiated in the current
9894
* constraint are also dereferenced.
99-
* 4. Toplevel occurrences of ExprTypes lead to a `NoType` return, which
95+
* 2. Toplevel occurrences of ExprTypes lead to a `NoType` return, which
10096
* causes the addOneBound operation to fail.
10197
*
102-
* An occurrence is toplevel if it is the bound itself,
103-
* or the bound is a union or intersection, and the ocurrence is
104-
* toplevel in one of the operands of the `&` or `|`.
98+
* An occurrence is toplevel if it is the bound itself, or a term in some
99+
* combination of `&` or `|` types.
105100
*/
106101
def adjust(tp: Type): Type = tp match
107102
case tp: AndOrType =>
108103
val p1 = adjust(tp.tp1)
109104
val p2 = adjust(tp.tp2)
110105
if p1.exists && p2.exists then tp.derivedAndOrType(p1, p2) else NoType
111-
case tp: TypeParamRef =>
112-
if constraint.contains(tp) then
113-
constr.println(i"${if tp eq param then "stripping" else "keeping"} $tp from $rawBound, upper = $isUpper in $constraint")
114-
if tp eq param then // (1)
115-
if isUpper then defn.AnyType else defn.NothingType
116-
else constraint.entry(tp) match // (3)
117-
case NoType => tp
118-
case TypeBounds(lo, hi) => if lo eq hi then adjust(lo) else tp
119-
case inst => adjust(inst)
120-
case tp: TypeVar => // (2)
121-
val underlying1 = adjust(tp.underlying)
122-
if (underlying1 ne tp.underlying) || constraint.contains(tp.origin)
123-
then underlying1
124-
else tp
125-
case tp: ExprType => // (4)
106+
case tp: TypeVar if constraint.contains(tp.origin) =>
107+
adjust(tp.underlying)
108+
case tp: ExprType =>
126109
// ExprTypes are not value types, so type parameters should not
127110
// be instantiated to ExprTypes. A scenario where such an attempted
128111
// instantiation can happen is if we unify (=> T) => () with A => ()
@@ -468,7 +451,7 @@ trait ConstraintHandling[AbstractContext] {
468451
* missing.
469452
*/
470453
def avoidLambdaParams(tp: Type) =
471-
if (comparedTypeLambdas.nonEmpty) {
454+
if comparedTypeLambdas.nonEmpty then
472455
val approx = new ApproximatingTypeMap {
473456
if (!fromBelow) variance = -1
474457
def apply(t: Type): Type = t match {
@@ -480,7 +463,6 @@ trait ConstraintHandling[AbstractContext] {
480463
}
481464
}
482465
approx(tp)
483-
}
484466
else tp
485467

486468
def addParamBound(bound: TypeParamRef) =

0 commit comments

Comments
 (0)