@@ -485,49 +485,25 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
485
485
throw new AssertionError (i " cannot merge $this with $other, mergeEntries( $e1, $e2) failed " )
486
486
}
487
487
488
- /** Ensure that constraint `c` does not associate different TypeVars for the
489
- * same type lambda than this constraint. Do this by renaming type lambdas
490
- * in `c` where necessary.
491
- */
492
- def ensureNotConflicting (c : OrderingConstraint ): OrderingConstraint = {
493
- def hasConflictingTypeVarsFor (tl : TypeLambda ) =
494
- this .typeVarOfParam(tl.paramRefs(0 )) ne c.typeVarOfParam(tl.paramRefs(0 ))
495
- // Note: Since TypeVars are allocated in bulk for each type lambda, we only
496
- // have to check the first one to find out if some of them are different.
497
- val conflicting = c.domainLambdas.find(tl =>
498
- this .contains(tl) && hasConflictingTypeVarsFor(tl))
499
- conflicting match {
500
- case Some (tl) => ensureNotConflicting(c.rename(tl))
501
- case None => c
502
- }
503
- }
504
-
505
- val that = ensureNotConflicting(other.asInstanceOf [OrderingConstraint ])
488
+ val that = other.asInstanceOf [OrderingConstraint ]
506
489
507
490
new OrderingConstraint (
508
491
merge(this .boundsMap, that.boundsMap, mergeEntries),
509
492
merge(this .lowerMap, that.lowerMap, mergeParams),
510
493
merge(this .upperMap, that.upperMap, mergeParams))
511
494
}.showing(i " constraint merge $this with $other = $result" , constr)
512
495
513
- def rename (tl : TypeLambda )(using Context ): OrderingConstraint = {
514
- assert(contains(tl))
515
- val tl1 = ensureFresh(tl)
516
- def swapKey [T ](m : ArrayValuedMap [T ]) = m.remove(tl).updated(tl1, m(tl))
496
+ def subst (from : TypeLambda , to : TypeLambda )(using Context ): OrderingConstraint =
497
+ def swapKey [T ](m : ArrayValuedMap [T ]) = m.remove(from).updated(to, m(from))
517
498
var current = newConstraint(swapKey(boundsMap), swapKey(lowerMap), swapKey(upperMap))
518
- def subst [T <: Type ](x : T ): T = x.subst(tl, tl1 ).asInstanceOf [T ]
499
+ def subst [T <: Type ](x : T ): T = x.subst(from, to ).asInstanceOf [T ]
519
500
current.foreachParam {(p, i) =>
520
501
current = boundsLens.map(this , current, p, i, subst)
521
502
current = lowerLens.map(this , current, p, i, _.map(subst))
522
503
current = upperLens.map(this , current, p, i, _.map(subst))
523
504
}
524
- current.foreachTypeVar { tvar =>
525
- val TypeParamRef (binder, n) = tvar.origin
526
- if (binder eq tl) tvar.setOrigin(tl1.paramRefs(n))
527
- }
528
505
constr.println(i " renamed $this to $current" )
529
506
current.checkNonCyclic()
530
- }
531
507
532
508
def instType (tvar : TypeVar ): Type = entry(tvar.origin) match
533
509
case _ : TypeBounds => NoType
0 commit comments