Skip to content

Commit 5290632

Browse files
committed
Move hardenTypeVars into Constraint, so it can be reused
1 parent 6e256b7 commit 5290632

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ abstract class Constraint extends Showable {
138138
/** The same as this constraint, but with `tv` marked as hard. */
139139
def withHard(tv: TypeVar)(using Context): This
140140

141+
/** Mark toplevel type vars in `tp` as hard. */
142+
def hardenTypeVars(tp: Type)(using Context): This
143+
141144
/** Gives for each instantiated type var that does not yet have its `inst` field
142145
* set, the instance value stored in the constraint. Storing instances in constraints
143146
* is done only in a temporary way for contexts that may be retracted

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,12 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
751751
current.checkWellFormed()
752752
end replace
753753

754+
def hardenTypeVars(tp: Type)(using Context): OrderingConstraint = tp.dealiasKeepRefiningAnnots match
755+
case tp: TypeVar if contains(tp.origin) => withHard(tp)
756+
case tp: TypeParamRef if contains(tp) => hardenTypeVars(typeVarOfParam(tp))
757+
case tp: AndOrType => hardenTypeVars(tp.tp1).hardenTypeVars(tp.tp2)
758+
case _ => this
759+
754760
def remove(pt: TypeLambda)(using Context): This = {
755761
def removeFromOrdering(po: ParamOrdering) = {
756762
def removeFromBoundss(key: TypeLambda, bndss: Array[List[TypeParamRef]]): Array[List[TypeParamRef]] = {

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -501,17 +501,6 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
501501
false
502502
}
503503

504-
/** Mark toplevel type vars in `tp2` as hard in the current constraint */
505-
def hardenTypeVars(tp2: Type): Unit = tp2.dealiasKeepRefiningAnnots match
506-
case tvar: TypeVar if constraint.contains(tvar.origin) =>
507-
constraint = constraint.withHard(tvar)
508-
case tp2: TypeParamRef if constraint.contains(tp2) =>
509-
hardenTypeVars(constraint.typeVarOfParam(tp2))
510-
case tp2: AndOrType =>
511-
hardenTypeVars(tp2.tp1)
512-
hardenTypeVars(tp2.tp2)
513-
case _ =>
514-
515504
val res = widenOK || joinOK
516505
|| recur(tp11, tp2) && recur(tp12, tp2)
517506
|| containsAnd(tp1)
@@ -534,7 +523,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
534523
// is marked so that it converts all soft unions in its lower bound to hard unions
535524
// before it is instantiated. The reason is that the variable's instance type will
536525
// be a supertype of (decomposed and reconstituted) `tp1`.
537-
hardenTypeVars(tp2)
526+
constraint = constraint.hardenTypeVars(tp2)
538527

539528
res
540529

0 commit comments

Comments
 (0)