@@ -485,49 +485,25 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
485485 throw new AssertionError (i " cannot merge $this with $other, mergeEntries( $e1, $e2) failed " )
486486 }
487487
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 ]
506489
507490 new OrderingConstraint (
508491 merge(this .boundsMap, that.boundsMap, mergeEntries),
509492 merge(this .lowerMap, that.lowerMap, mergeParams),
510493 merge(this .upperMap, that.upperMap, mergeParams))
511494 }.showing(i " constraint merge $this with $other = $result" , constr)
512495
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))
517498 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 ]
519500 current.foreachParam {(p, i) =>
520501 current = boundsLens.map(this , current, p, i, subst)
521502 current = lowerLens.map(this , current, p, i, _.map(subst))
522503 current = upperLens.map(this , current, p, i, _.map(subst))
523504 }
524- current.foreachTypeVar { tvar =>
525- val TypeParamRef (binder, n) = tvar.origin
526- if (binder eq tl) tvar.setOrigin(tl1.paramRefs(n))
527- }
528505 constr.println(i " renamed $this to $current" )
529506 current.checkNonCyclic()
530- }
531507
532508 def instType (tvar : TypeVar ): Type = entry(tvar.origin) match
533509 case _ : TypeBounds => NoType
0 commit comments