@@ -22,16 +22,12 @@ import reporting.trace
2222 * By comparison: Constraint handlers are parts of type comparers and can use their functionality.
2323 * Constraint handlers update the current constraint as a side effect.
2424 */
25- trait ConstraintHandling [ AbstractContext ] {
25+ trait ConstraintHandling {
2626
2727 def constr : config.Printers .Printer = config.Printers .constr
2828
29- def comparerCtx (using AbstractContext ): Context
30-
31- given (using AbstractContext ) as Context = comparerCtx
32-
33- protected def isSubType (tp1 : Type , tp2 : Type )(implicit actx : AbstractContext ): Boolean
34- protected def isSameType (tp1 : Type , tp2 : Type )(implicit actx : AbstractContext ): Boolean
29+ protected def isSub (tp1 : Type , tp2 : Type )(using Context ): Boolean
30+ protected def isSame (tp1 : Type , tp2 : Type )(using Context ): Boolean
3531
3632 protected def constraint : Constraint
3733 protected def constraint_= (c : Constraint ): Unit
@@ -71,23 +67,23 @@ trait ConstraintHandling[AbstractContext] {
7167 case tp => tp
7268 }
7369
74- def nonParamBounds (param : TypeParamRef )(implicit actx : AbstractContext ): TypeBounds = constraint.nonParamBounds(param)
70+ def nonParamBounds (param : TypeParamRef )(using Context ): TypeBounds = constraint.nonParamBounds(param)
7571
76- def fullLowerBound (param : TypeParamRef )(implicit actx : AbstractContext ): Type =
72+ def fullLowerBound (param : TypeParamRef )(using Context ): Type =
7773 constraint.minLower(param).foldLeft(nonParamBounds(param).lo)(_ | _)
7874
79- def fullUpperBound (param : TypeParamRef )(implicit actx : AbstractContext ): Type =
75+ def fullUpperBound (param : TypeParamRef )(using Context ): Type =
8076 constraint.minUpper(param).foldLeft(nonParamBounds(param).hi)(_ & _)
8177
8278 /** Full bounds of `param`, including other lower/upper params.
8379 *
8480 * Note that underlying operations perform subtype checks - for this reason, recursing on `fullBounds`
8581 * of some param when comparing types might lead to infinite recursion. Consider `bounds` instead.
8682 */
87- def fullBounds (param : TypeParamRef )(implicit actx : AbstractContext ): TypeBounds =
83+ def fullBounds (param : TypeParamRef )(using Context ): TypeBounds =
8884 nonParamBounds(param).derivedTypeBounds(fullLowerBound(param), fullUpperBound(param))
8985
90- protected def addOneBound (param : TypeParamRef , bound : Type , isUpper : Boolean )(using AbstractContext ): Boolean =
86+ protected def addOneBound (param : TypeParamRef , bound : Type , isUpper : Boolean )(using Context ): Boolean =
9187 if ! constraint.contains(param) then true
9288 else if ! isUpper && param.occursIn(bound)
9389 // We don't allow recursive lower bounds when defining a type,
@@ -121,11 +117,11 @@ trait ConstraintHandling[AbstractContext] {
121117 || {
122118 constraint = c1
123119 val TypeBounds (lo, hi) = constraint.entry(param)
124- isSubType (lo, hi)
120+ isSub (lo, hi)
125121 }
126122 end addOneBound
127123
128- protected def addBoundTransitively (param : TypeParamRef , rawBound : Type , isUpper : Boolean )(implicit actx : AbstractContext ): Boolean =
124+ protected def addBoundTransitively (param : TypeParamRef , rawBound : Type , isUpper : Boolean )(using Context ): Boolean =
129125
130126 /** Adjust the bound `tp` in the following ways:
131127 *
@@ -172,7 +168,7 @@ trait ConstraintHandling[AbstractContext] {
172168 .reporting(i " added $description = $result$location" , constr)
173169 end addBoundTransitively
174170
175- protected def addLess (p1 : TypeParamRef , p2 : TypeParamRef )(implicit actx : AbstractContext ): Boolean = {
171+ protected def addLess (p1 : TypeParamRef , p2 : TypeParamRef )(using Context ): Boolean = {
176172 def description = i " ordering $p1 <: $p2 to \n $constraint"
177173 val res =
178174 if (constraint.isLess(p2, p1)) unify(p2, p1)
@@ -195,7 +191,7 @@ trait ConstraintHandling[AbstractContext] {
195191 /** Make p2 = p1, transfer all bounds of p2 to p1
196192 * @pre less(p1)(p2)
197193 */
198- private def unify (p1 : TypeParamRef , p2 : TypeParamRef )(implicit actx : AbstractContext ): Boolean = {
194+ private def unify (p1 : TypeParamRef , p2 : TypeParamRef )(using Context ): Boolean = {
199195 constr.println(s " unifying $p1 $p2" )
200196 assert(constraint.isLess(p1, p2))
201197 val down = constraint.exclusiveLower(p2, p1)
@@ -204,16 +200,16 @@ trait ConstraintHandling[AbstractContext] {
204200 val bounds = constraint.nonParamBounds(p1)
205201 val lo = bounds.lo
206202 val hi = bounds.hi
207- isSubType (lo, hi) &&
203+ isSub (lo, hi) &&
208204 down.forall(addOneBound(_, hi, isUpper = true )) &&
209205 up.forall(addOneBound(_, lo, isUpper = false ))
210206 }
211207
212- protected def isSubType (tp1 : Type , tp2 : Type , whenFrozen : Boolean )(implicit actx : AbstractContext ): Boolean =
208+ protected def isSubType (tp1 : Type , tp2 : Type , whenFrozen : Boolean )(using Context ): Boolean =
213209 if (whenFrozen)
214210 isSubTypeWhenFrozen(tp1, tp2)
215211 else
216- isSubType (tp1, tp2)
212+ isSub (tp1, tp2)
217213
218214 inline final def inFrozenConstraint [T ](op : => T ): T = {
219215 val savedFrozen = frozenConstraint
@@ -227,16 +223,16 @@ trait ConstraintHandling[AbstractContext] {
227223 }
228224 }
229225
230- final def isSubTypeWhenFrozen (tp1 : Type , tp2 : Type )(implicit actx : AbstractContext ): Boolean = inFrozenConstraint(isSubType (tp1, tp2))
231- final def isSameTypeWhenFrozen (tp1 : Type , tp2 : Type )(implicit actx : AbstractContext ): Boolean = inFrozenConstraint(isSameType (tp1, tp2))
226+ final def isSubTypeWhenFrozen (tp1 : Type , tp2 : Type )(using Context ): Boolean = inFrozenConstraint(isSub (tp1, tp2))
227+ final def isSameTypeWhenFrozen (tp1 : Type , tp2 : Type )(using Context ): Boolean = inFrozenConstraint(isSame (tp1, tp2))
232228
233229 /** Test whether the lower bounds of all parameters in this
234230 * constraint are a solution to the constraint.
235231 */
236- protected final def isSatisfiable (implicit actx : AbstractContext ): Boolean =
232+ protected final def isSatisfiable (using Context ): Boolean =
237233 constraint.forallParams { param =>
238234 val TypeBounds (lo, hi) = constraint.entry(param)
239- isSubType (lo, hi) || {
235+ isSub (lo, hi) || {
240236 report.log(i " sub fail $lo <:< $hi" )
241237 false
242238 }
@@ -253,7 +249,7 @@ trait ConstraintHandling[AbstractContext] {
253249 * @return the instantiating type
254250 * @pre `param` is in the constraint's domain.
255251 */
256- final def approximation (param : TypeParamRef , fromBelow : Boolean )(implicit actx : AbstractContext ): Type = {
252+ final def approximation (param : TypeParamRef , fromBelow : Boolean )(using Context ): Type = {
257253 val replaceWildcards = new TypeMap {
258254 override def stopAtStatic = true
259255 def apply (tp : Type ) = mapOver {
@@ -317,7 +313,7 @@ trait ConstraintHandling[AbstractContext] {
317313 * At this point we also drop the @Repeated annotation to avoid inferring type arguments with it,
318314 * as those could leak the annotation to users (see run/inferred-repeated-result).
319315 */
320- def widenInferred (inst : Type , bound : Type )(implicit actx : AbstractContext ): Type =
316+ def widenInferred (inst : Type , bound : Type )(using Context ): Type =
321317
322318 def dropSuperTraits (tp : Type ): Type =
323319 var kept : Set [Type ] = Set () // types to keep since otherwise bound would not fit
@@ -380,7 +376,7 @@ trait ConstraintHandling[AbstractContext] {
380376 * a lower bound instantiation can be a singleton type only if the upper bound
381377 * is also a singleton type.
382378 */
383- def instanceType (param : TypeParamRef , fromBelow : Boolean )(implicit actx : AbstractContext ): Type = {
379+ def instanceType (param : TypeParamRef , fromBelow : Boolean )(using Context ): Type = {
384380 val approx = approximation(param, fromBelow).simplified
385381 if (fromBelow)
386382 val widened = widenInferred(approx, param)
@@ -408,7 +404,7 @@ trait ConstraintHandling[AbstractContext] {
408404 * Both `c1` and `c2` are required to derive from constraint `pre`, without adding
409405 * any new type variables but possibly narrowing already registered ones with further bounds.
410406 */
411- protected final def subsumes (c1 : Constraint , c2 : Constraint , pre : Constraint )(implicit actx : AbstractContext ): Boolean =
407+ protected final def subsumes (c1 : Constraint , c2 : Constraint , pre : Constraint )(using Context ): Boolean =
412408 if (c2 eq pre) true
413409 else if (c1 eq pre) false
414410 else {
@@ -427,7 +423,7 @@ trait ConstraintHandling[AbstractContext] {
427423 }
428424
429425 /** The current bounds of type parameter `param` */
430- def bounds (param : TypeParamRef )(implicit actx : AbstractContext ): TypeBounds = {
426+ def bounds (param : TypeParamRef )(using Context ): TypeBounds = {
431427 val e = constraint.entry(param)
432428 if (e.exists) e.bounds
433429 else {
@@ -441,7 +437,7 @@ trait ConstraintHandling[AbstractContext] {
441437 * and propagate all bounds.
442438 * @param tvars See Constraint#add
443439 */
444- def addToConstraint (tl : TypeLambda , tvars : List [TypeVar ])(implicit actx : AbstractContext ): Boolean =
440+ def addToConstraint (tl : TypeLambda , tvars : List [TypeVar ])(using Context ): Boolean =
445441 checkPropagated(i " initialized $tl" ) {
446442 constraint = constraint.add(tl, tvars)
447443 tl.paramRefs.forall { param =>
@@ -470,7 +466,7 @@ trait ConstraintHandling[AbstractContext] {
470466 * This holds if `TypeVarsMissContext` is set unless `param` is a part
471467 * of a MatchType that is currently normalized.
472468 */
473- final def assumedTrue (param : TypeParamRef )(implicit actx : AbstractContext ): Boolean =
469+ final def assumedTrue (param : TypeParamRef )(using Context ): Boolean =
474470 ctx.mode.is(Mode .TypevarsMissContext ) && (caseLambda `ne` param.binder)
475471
476472 /** Add constraint `param <: bound` if `fromBelow` is false, `param >: bound` otherwise.
@@ -480,7 +476,7 @@ trait ConstraintHandling[AbstractContext] {
480476 * not be AndTypes and lower bounds may not be OrTypes. This is assured by the
481477 * way isSubType is organized.
482478 */
483- protected def addConstraint (param : TypeParamRef , bound : Type , fromBelow : Boolean )(implicit actx : AbstractContext ): Boolean =
479+ protected def addConstraint (param : TypeParamRef , bound : Type , fromBelow : Boolean )(using Context ): Boolean =
484480
485481 /** When comparing lambdas we might get constraints such as
486482 * `A <: X0` or `A = List[X0]` where `A` is a constrained parameter
@@ -514,7 +510,7 @@ trait ConstraintHandling[AbstractContext] {
514510 case _ : TypeBounds =>
515511 if (fromBelow) addLess(bound, param) else addLess(param, bound)
516512 case tp =>
517- if (fromBelow) isSubType (bound, tp) else isSubType (tp, bound)
513+ if (fromBelow) isSub (bound, tp) else isSub (tp, bound)
518514 }
519515
520516 def kindCompatible (tp1 : Type , tp2 : Type ): Boolean =
@@ -541,7 +537,7 @@ trait ConstraintHandling[AbstractContext] {
541537 end addConstraint
542538
543539 /** Check that constraint is fully propagated. See comment in Config.checkConstraintsPropagated */
544- def checkPropagated (msg : => String )(result : Boolean )(implicit actx : AbstractContext ): Boolean = {
540+ def checkPropagated (msg : => String )(result : Boolean )(using Context ): Boolean = {
545541 if (Config .checkConstraintsPropagated && result && addConstraintInvocations == 0 )
546542 inFrozenConstraint {
547543 for (p <- constraint.domainParams) {
0 commit comments