Skip to content

Commit cc41d38

Browse files
committed
Drop adaptHkVariance
1 parent 1999206 commit cc41d38

File tree

3 files changed

+9
-97
lines changed

3 files changed

+9
-97
lines changed

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

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -155,26 +155,8 @@ final class ProperGadtConstraint private(
155155
else if (isUpper) addLess(symTvar.origin, boundTvar.origin)
156156
else addLess(boundTvar.origin, symTvar.origin)
157157
case bound =>
158-
val oldUpperBound = bounds(symTvar.origin)
159-
// If we have bounds:
160-
// F >: [t] => List[t] <: [t] => Any
161-
// and we want to record that:
162-
// F <: [+A] => List[A]
163-
// we need to adapt the variance and instead record that:
164-
// F <: [A] => List[A]
165-
// We cannot record the original bound, since it is false that:
166-
// [t] => List[t] <: [+A] => List[A]
167-
//
168-
// Note that the following code is accepted:
169-
// class Foo[F[t] >: List[t]]
170-
// type T = Foo[List]
171-
// precisely because Foo[List] is desugared to Foo[[A] => List[A]].
172-
//
173-
// Ideally we'd adapt the bound in ConstraintHandling#addOneBound,
174-
// but doing it there actually interferes with type inference.
175-
val bound1 = bound.adaptHkVariances(oldUpperBound)
176-
if (isUpper) addUpperBound(symTvar.origin, bound1)
177-
else addLowerBound(symTvar.origin, bound1)
158+
if (isUpper) addUpperBound(symTvar.origin, bound)
159+
else addLowerBound(symTvar.origin, bound)
178160
}
179161
).reporting({
180162
val descr = if (isUpper) "upper" else "lower"

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

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -271,62 +271,6 @@ class TypeApplications(val self: Type) extends AnyVal {
271271
}
272272
}
273273

274-
/** If argument A and type parameter P are higher-kinded, adapt the variances
275-
* of A to those of P, ensuring that the variances of the type lambda A
276-
* agree with the variances of corresponding higher-kinded type parameters of P. Example:
277-
*
278-
* class GenericCompanion[+CC[X]]
279-
* GenericCompanion[List]
280-
*
281-
* with adaptHkVariances, the argument `List` will expand to
282-
*
283-
* [X] => List[X]
284-
*
285-
* instead of
286-
*
287-
* [+X] => List[X]
288-
*
289-
* even though `List` is covariant. This adaptation is necessary to ignore conflicting
290-
* variances in overriding members that have types of hk-type parameters such as
291-
* `GenericCompanion[GenTraversable]` or `GenericCompanion[ListBuffer]`.
292-
* When checking overriding, we need to validate the subtype relationship
293-
*
294-
* GenericCompanion[[X] -> ListBuffer[X]] <: GenericCompanion[[+X] -> GenTraversable[X]]
295-
*
296-
* Without adaptation, this would be false, and hence an overriding error would
297-
* result. But with adaptation, the rhs argument will be adapted to
298-
*
299-
* [X] -> GenTraversable[X]
300-
*
301-
* which makes the subtype test succeed. The crucial point here is that, since
302-
* GenericCompanion only expects a non-variant CC, the fact that GenTraversable
303-
* is covariant is irrelevant, so can be ignored.
304-
*/
305-
def adaptHkVariances(bound: Type)(implicit ctx: Context): Type = self/*{
306-
val hkParams = bound.hkTypeParams
307-
if (hkParams.isEmpty) self
308-
else {
309-
def adaptArg(arg: Type): Type = arg match {
310-
case arg @ HKTypeLambda(tparams, body) if
311-
!tparams.corresponds(hkParams)(_.paramVarianceSign == _.paramVarianceSign) &&
312-
tparams.corresponds(hkParams)(varianceConforms) =>
313-
HKTypeLambda(
314-
tparams.lazyZip(hkParams).map((tparam, hkparam) =>
315-
tparam.paramName.withVariance(hkparam.paramVarianceSign)))(
316-
tl => arg.paramInfos.map(_.subst(arg, tl).bounds),
317-
tl => arg.resultType.subst(arg, tl)
318-
)
319-
case arg: AliasingBounds =>
320-
arg.derivedAlias(adaptArg(arg.alias))
321-
case arg @ TypeBounds(lo, hi) =>
322-
arg.derivedTypeBounds(adaptArg(lo), adaptArg(hi))
323-
case _ =>
324-
arg
325-
}
326-
adaptArg(self)
327-
}
328-
}*/
329-
330274
/** The type representing
331275
*
332276
* T[U1, ..., Un]

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

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,14 +1279,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
12791279
}
12801280
}
12811281

1282-
val arg1 = args1.head
1283-
val arg2 = args2.head
1284-
isSubArg(arg1, arg2) || {
1285-
// last effort: try to adapt variances of higher-kinded types if this is sound.
1286-
// TODO: Move this to eta-expansion?
1287-
val adapted2 = arg2.adaptHkVariances(tparam.paramInfo)
1288-
adapted2.ne(arg2) && isSubArg(arg1, adapted2)
1289-
}
1282+
isSubArg(args1.head, args2.head)
12901283
} && recurArgs(args1.tail, args2.tail, tparams2.tail)
12911284

12921285
recurArgs(args1, args2, tparams2)
@@ -1553,19 +1546,12 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
15531546
* Further, no refinement refers back to the refined type via a refined this.
15541547
* The precondition is established by `skipMatching`.
15551548
*/
1556-
private def isSubRefinements(tp1: RefinedType, tp2: RefinedType, limit: Type): Boolean = {
1557-
def hasSubRefinement(tp1: RefinedType, refine2: Type): Boolean =
1558-
isSubType(tp1.refinedInfo, refine2) || {
1559-
// last effort: try to adapt variances of higher-kinded types if this is sound.
1560-
// TODO: Move this to eta-expansion?
1561-
val adapted2 = refine2.adaptHkVariances(tp1.parent.member(tp1.refinedName).symbol.info)
1562-
adapted2.ne(refine2) && hasSubRefinement(tp1, adapted2)
1563-
}
1564-
hasSubRefinement(tp1, tp2.refinedInfo) && (
1565-
(tp2.parent eq limit) ||
1566-
isSubRefinements(
1567-
tp1.parent.asInstanceOf[RefinedType], tp2.parent.asInstanceOf[RefinedType], limit))
1568-
}
1549+
private def isSubRefinements(tp1: RefinedType, tp2: RefinedType, limit: Type): Boolean =
1550+
isSubType(tp1.refinedInfo, tp2.refinedInfo)
1551+
&& ((tp2.parent eq limit)
1552+
|| isSubRefinements(
1553+
tp1.parent.asInstanceOf[RefinedType],
1554+
tp2.parent.asInstanceOf[RefinedType], limit))
15691555

15701556
/** A type has been covered previously in subtype checking if it
15711557
* is some combination of TypeRefs that point to classes, where the

0 commit comments

Comments
 (0)