Skip to content

Commit a493791

Browse files
committed
Fixups taking into account reviewer's comments.
1 parent eb4d808 commit a493791

File tree

7 files changed

+27
-22
lines changed

7 files changed

+27
-22
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ abstract class Constraint extends Showable {
9292
*/
9393
def updateEntry(param: PolyParam, tp: Type)(implicit ctx: Context): This
9494

95-
/** A constraint that includes the relationship `p1 <: p2`
95+
/** A constraint that includes the relationship `p1 <: p2`.
96+
* `<:` relationships between parameters ("edges") are propagated, but
97+
* non-parameter bounds are left alone.
9698
*/
9799
def addLess(p1: PolyParam, p2: PolyParam)(implicit ctx: Context): This
98100

99-
/** A constraint resulting by adding p2 = p1 to this constraint, and at the same
101+
/** A constraint resulting from adding p2 = p1 to this constraint, and at the same
100102
* time transferring all bounds of p2 to p1
101103
*/
102104
def unify(p1: PolyParam, p2: PolyParam)(implicit ctx: Context): This

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ trait ConstraintHandling {
218218
* `bound` is assumed to be in normalized form, as specified in `firstTry` and
219219
* `secondTry` of `TypeComparer`. In particular, it should not be an alias type,
220220
* lazy ref, typevar, wildcard type, error type. In addition, upper bounds may
221-
* not be AndTypes and lower bounds may not be OrTypes.
221+
* not be AndTypes and lower bounds may not be OrTypes. This is assured by the
222+
* way isSubType is organized.
222223
*/
223224
protected def addConstraint(param: PolyParam, bound: Type, fromBelow: Boolean): Boolean = {
224225
def description = i"constr $param ${if (fromBelow) ">:" else "<:"} $bound:\n$constraint"

src/dotty/tools/dotc/core/OrderingConstraint.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import reflect.ClassTag
1414

1515
object OrderingConstraint {
1616

17-
/** The type of `Constraint#boundsMap` */
17+
/** The type of `OrderingConstraint#boundsMap` */
1818
type ParamBounds = SimpleMap[PolyType, Array[Type]]
1919

20-
/** The type of `Constraint#lowerMap`, `Constraint#upperMap` */
20+
/** The type of `OrderingConstraint#lowerMap`, `OrderingConstraint#upperMap` */
2121
type ParamOrdering = SimpleMap[PolyType, Array[List[PolyParam]]]
2222

2323
/** A new constraint with given maps */
@@ -117,10 +117,10 @@ import OrderingConstraint._
117117
*
118118
* @param lowerMap a map from PolyTypes to arrays. Each array entry corresponds
119119
* to a parameter P of the polytype; it contains all constrained parameters
120-
* Q that are known to be smaller than P, i.e. P <: Q.
120+
* Q that are known to be smaller than P, i.e. Q <: P.
121121
* @param upperMap a map from PolyTypes to arrays. Each array entry corresponds
122122
* to a parameter P of the polytype; it contains all constrained parameters
123-
* Q that are known to be greater than P, i.e. Q <: P.
123+
* Q that are known to be greater than P, i.e. P <: Q.
124124
*/
125125
class OrderingConstraint(private val boundsMap: ParamBounds,
126126
private val lowerMap : ParamOrdering,
@@ -272,8 +272,8 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
272272

273273
// ---------- Updates ------------------------------------------------------------
274274

275-
/** An updated partial order matrix that incorporates `less` and also reflects that `param` relates
276-
* to `p2` wrt <:< if `inOrder` is true, `>:>` otherwise.
275+
/** Add the fact `param1 <: param2` to the constraint `current` and propagate
276+
* `<:<` relationships between parameters ("edges") but not bounds.
277277
*/
278278
private def order(current: This, param1: PolyParam, param2: PolyParam)(implicit ctx: Context): This =
279279
if (param1 == param2 || current.isLess(param1, param2)) this

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling wi
299299
val gbounds2 = ctx.gadt.bounds(tp2.symbol)
300300
(gbounds2 != null) &&
301301
(isSubTypeWhenFrozen(tp1, gbounds2.lo) ||
302-
narrowGADTBounds(tp2, tp1, isLowerBound = true))
302+
narrowGADTBounds(tp2, tp1, isUpper = false))
303303
}
304304
((frozenConstraint || !isCappable(tp1)) && isSubType(tp1, lo2) ||
305305
compareGADT ||
@@ -414,7 +414,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling wi
414414
val gbounds1 = ctx.gadt.bounds(tp1.symbol)
415415
(gbounds1 != null) &&
416416
(isSubTypeWhenFrozen(gbounds1.hi, tp2) ||
417-
narrowGADTBounds(tp1, tp2, isLowerBound = false))
417+
narrowGADTBounds(tp1, tp2, isUpper = true))
418418
}
419419
isSubType(hi1, tp2) || compareGADT
420420
case _ =>
@@ -616,16 +616,20 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling wi
616616
//})
617617
}
618618

619-
private def narrowGADTBounds(tr: NamedType, bound: Type, isLowerBound: Boolean): Boolean =
619+
/** Narrow gadt.bounds for the type parameter referenced by `tr` to include
620+
* `bound` as an upper or lower bound (which depends on `isUpper`).
621+
* Test that the resulting bounds are still satisfiable.
622+
*/
623+
private def narrowGADTBounds(tr: NamedType, bound: Type, isUpper: Boolean): Boolean =
620624
ctx.mode.is(Mode.GADTflexible) && {
621625
val tparam = tr.symbol
622-
val bound1 = deSkolemize(bound, toSuper = isLowerBound)
623-
typr.println(s"narrow gadt bound of $tparam: ${tparam.info} from ${if (isLowerBound) "below" else "above"} to $bound1 ${bound1.isRef(tparam)}")
626+
val bound1 = deSkolemize(bound, toSuper = !isUpper)
627+
typr.println(s"narrow gadt bound of $tparam: ${tparam.info} from ${if (isUpper) "above" else "below"} to $bound1 ${bound1.isRef(tparam)}")
624628
!bound1.isRef(tparam) && {
625629
val oldBounds = ctx.gadt.bounds(tparam)
626630
val newBounds =
627-
if (isLowerBound) TypeBounds(oldBounds.lo | bound1, oldBounds.hi)
628-
else TypeBounds(oldBounds.lo, oldBounds.hi & bound1)
631+
if (isUpper) TypeBounds(oldBounds.lo, oldBounds.hi & bound1)
632+
else TypeBounds(oldBounds.lo | bound1, oldBounds.hi)
629633
isSubType(newBounds.lo, newBounds.hi) &&
630634
{ ctx.gadt.setBounds(tparam, newBounds); true }
631635
}

src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ object Types {
761761
* a reference to the "this" of the current refined type. But does follow
762762
* aliases in order to avoid such references. Example:
763763
*
764-
* Lambda$I { type $hk$Arg0 = String, type Apply = this<0>.$hk$Arg0 } # Apply
764+
* Lambda$I { type $hk$Arg0 = String, type Apply = Lambda$I{...}.$hk$Arg0 } # Apply
765765
*
766766
* Here, the refinement for `Apply` has a refined this node, yet dereferencing ones more
767767
* yields `String` as the result of lookupRefined.

src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,8 @@ trait Implicits { self: Typer =>
450450
private def nestedContext = ctx.fresh.setMode(ctx.mode &~ Mode.ImplicitsEnabled)
451451

452452
private def implicitProto(resultType: Type, f: Type => Type) =
453-
if (argument.isEmpty) f(resultType) else ViewProto(f(argument.tpe/*.widen*/), f(resultType))
454-
// !!! TODO: check performance implications
455-
// If we do the widen, SyntheticMethods, line 66 fails to compile
456-
// val synthetic = sym.copy(...)
453+
if (argument.isEmpty) f(resultType) else ViewProto(f(argument.tpe.widen), f(resultType))
454+
// Not clear whether we need to drop the `.widen` here. All tests pass with it in place, though.
457455

458456
assert(argument.isEmpty || argument.tpe.isValueType || argument.tpe.isInstanceOf[ExprType],
459457
d"found: ${argument.tpe}, expected: $pt")

src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ object ProtoTypes {
376376
tp.derivedRefinedType(wildApprox(tp.parent, theMap), tp.refinedName, wildApprox(tp.refinedInfo, theMap))
377377
case tp: TypeAlias => // default case, inlined for speed
378378
tp.derivedTypeAlias(wildApprox(tp.alias, theMap))
379-
case tp @ PolyParam(poly, pnum) => // !!! todo adapt to TrackingConstraint
379+
case tp @ PolyParam(poly, pnum) =>
380380
ctx.typerState.constraint.entry(tp) match {
381381
case bounds: TypeBounds => wildApprox(WildcardType(bounds))
382382
case NoType => WildcardType(wildApprox(poly.paramBounds(pnum)).bounds)

0 commit comments

Comments
 (0)