@@ -22,16 +22,12 @@ import reporting.trace
22
22
* By comparison: Constraint handlers are parts of type comparers and can use their functionality.
23
23
* Constraint handlers update the current constraint as a side effect.
24
24
*/
25
- trait ConstraintHandling [ AbstractContext ] {
25
+ trait ConstraintHandling {
26
26
27
27
def constr : config.Printers .Printer = config.Printers .constr
28
28
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
35
31
36
32
protected def constraint : Constraint
37
33
protected def constraint_= (c : Constraint ): Unit
@@ -71,23 +67,23 @@ trait ConstraintHandling[AbstractContext] {
71
67
case tp => tp
72
68
}
73
69
74
- def nonParamBounds (param : TypeParamRef )(implicit actx : AbstractContext ): TypeBounds = constraint.nonParamBounds(param)
70
+ def nonParamBounds (param : TypeParamRef )(using Context ): TypeBounds = constraint.nonParamBounds(param)
75
71
76
- def fullLowerBound (param : TypeParamRef )(implicit actx : AbstractContext ): Type =
72
+ def fullLowerBound (param : TypeParamRef )(using Context ): Type =
77
73
constraint.minLower(param).foldLeft(nonParamBounds(param).lo)(_ | _)
78
74
79
- def fullUpperBound (param : TypeParamRef )(implicit actx : AbstractContext ): Type =
75
+ def fullUpperBound (param : TypeParamRef )(using Context ): Type =
80
76
constraint.minUpper(param).foldLeft(nonParamBounds(param).hi)(_ & _)
81
77
82
78
/** Full bounds of `param`, including other lower/upper params.
83
79
*
84
80
* Note that underlying operations perform subtype checks - for this reason, recursing on `fullBounds`
85
81
* of some param when comparing types might lead to infinite recursion. Consider `bounds` instead.
86
82
*/
87
- def fullBounds (param : TypeParamRef )(implicit actx : AbstractContext ): TypeBounds =
83
+ def fullBounds (param : TypeParamRef )(using Context ): TypeBounds =
88
84
nonParamBounds(param).derivedTypeBounds(fullLowerBound(param), fullUpperBound(param))
89
85
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 =
91
87
if ! constraint.contains(param) then true
92
88
else if ! isUpper && param.occursIn(bound)
93
89
// We don't allow recursive lower bounds when defining a type,
@@ -121,11 +117,11 @@ trait ConstraintHandling[AbstractContext] {
121
117
|| {
122
118
constraint = c1
123
119
val TypeBounds (lo, hi) = constraint.entry(param)
124
- isSubType (lo, hi)
120
+ isSub (lo, hi)
125
121
}
126
122
end addOneBound
127
123
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 =
129
125
130
126
/** Adjust the bound `tp` in the following ways:
131
127
*
@@ -172,7 +168,7 @@ trait ConstraintHandling[AbstractContext] {
172
168
.reporting(i " added $description = $result$location" , constr)
173
169
end addBoundTransitively
174
170
175
- protected def addLess (p1 : TypeParamRef , p2 : TypeParamRef )(implicit actx : AbstractContext ): Boolean = {
171
+ protected def addLess (p1 : TypeParamRef , p2 : TypeParamRef )(using Context ): Boolean = {
176
172
def description = i " ordering $p1 <: $p2 to \n $constraint"
177
173
val res =
178
174
if (constraint.isLess(p2, p1)) unify(p2, p1)
@@ -195,7 +191,7 @@ trait ConstraintHandling[AbstractContext] {
195
191
/** Make p2 = p1, transfer all bounds of p2 to p1
196
192
* @pre less(p1)(p2)
197
193
*/
198
- private def unify (p1 : TypeParamRef , p2 : TypeParamRef )(implicit actx : AbstractContext ): Boolean = {
194
+ private def unify (p1 : TypeParamRef , p2 : TypeParamRef )(using Context ): Boolean = {
199
195
constr.println(s " unifying $p1 $p2" )
200
196
assert(constraint.isLess(p1, p2))
201
197
val down = constraint.exclusiveLower(p2, p1)
@@ -204,16 +200,16 @@ trait ConstraintHandling[AbstractContext] {
204
200
val bounds = constraint.nonParamBounds(p1)
205
201
val lo = bounds.lo
206
202
val hi = bounds.hi
207
- isSubType (lo, hi) &&
203
+ isSub (lo, hi) &&
208
204
down.forall(addOneBound(_, hi, isUpper = true )) &&
209
205
up.forall(addOneBound(_, lo, isUpper = false ))
210
206
}
211
207
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 =
213
209
if (whenFrozen)
214
210
isSubTypeWhenFrozen(tp1, tp2)
215
211
else
216
- isSubType (tp1, tp2)
212
+ isSub (tp1, tp2)
217
213
218
214
inline final def inFrozenConstraint [T ](op : => T ): T = {
219
215
val savedFrozen = frozenConstraint
@@ -227,16 +223,16 @@ trait ConstraintHandling[AbstractContext] {
227
223
}
228
224
}
229
225
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))
232
228
233
229
/** Test whether the lower bounds of all parameters in this
234
230
* constraint are a solution to the constraint.
235
231
*/
236
- protected final def isSatisfiable (implicit actx : AbstractContext ): Boolean =
232
+ protected final def isSatisfiable (using Context ): Boolean =
237
233
constraint.forallParams { param =>
238
234
val TypeBounds (lo, hi) = constraint.entry(param)
239
- isSubType (lo, hi) || {
235
+ isSub (lo, hi) || {
240
236
report.log(i " sub fail $lo <:< $hi" )
241
237
false
242
238
}
@@ -253,7 +249,7 @@ trait ConstraintHandling[AbstractContext] {
253
249
* @return the instantiating type
254
250
* @pre `param` is in the constraint's domain.
255
251
*/
256
- final def approximation (param : TypeParamRef , fromBelow : Boolean )(implicit actx : AbstractContext ): Type = {
252
+ final def approximation (param : TypeParamRef , fromBelow : Boolean )(using Context ): Type = {
257
253
val replaceWildcards = new TypeMap {
258
254
override def stopAtStatic = true
259
255
def apply (tp : Type ) = mapOver {
@@ -317,7 +313,7 @@ trait ConstraintHandling[AbstractContext] {
317
313
* At this point we also drop the @Repeated annotation to avoid inferring type arguments with it,
318
314
* as those could leak the annotation to users (see run/inferred-repeated-result).
319
315
*/
320
- def widenInferred (inst : Type , bound : Type )(implicit actx : AbstractContext ): Type =
316
+ def widenInferred (inst : Type , bound : Type )(using Context ): Type =
321
317
322
318
def dropSuperTraits (tp : Type ): Type =
323
319
var kept : Set [Type ] = Set () // types to keep since otherwise bound would not fit
@@ -380,7 +376,7 @@ trait ConstraintHandling[AbstractContext] {
380
376
* a lower bound instantiation can be a singleton type only if the upper bound
381
377
* is also a singleton type.
382
378
*/
383
- def instanceType (param : TypeParamRef , fromBelow : Boolean )(implicit actx : AbstractContext ): Type = {
379
+ def instanceType (param : TypeParamRef , fromBelow : Boolean )(using Context ): Type = {
384
380
val approx = approximation(param, fromBelow).simplified
385
381
if (fromBelow)
386
382
val widened = widenInferred(approx, param)
@@ -408,7 +404,7 @@ trait ConstraintHandling[AbstractContext] {
408
404
* Both `c1` and `c2` are required to derive from constraint `pre`, without adding
409
405
* any new type variables but possibly narrowing already registered ones with further bounds.
410
406
*/
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 =
412
408
if (c2 eq pre) true
413
409
else if (c1 eq pre) false
414
410
else {
@@ -427,7 +423,7 @@ trait ConstraintHandling[AbstractContext] {
427
423
}
428
424
429
425
/** The current bounds of type parameter `param` */
430
- def bounds (param : TypeParamRef )(implicit actx : AbstractContext ): TypeBounds = {
426
+ def bounds (param : TypeParamRef )(using Context ): TypeBounds = {
431
427
val e = constraint.entry(param)
432
428
if (e.exists) e.bounds
433
429
else {
@@ -441,7 +437,7 @@ trait ConstraintHandling[AbstractContext] {
441
437
* and propagate all bounds.
442
438
* @param tvars See Constraint#add
443
439
*/
444
- def addToConstraint (tl : TypeLambda , tvars : List [TypeVar ])(implicit actx : AbstractContext ): Boolean =
440
+ def addToConstraint (tl : TypeLambda , tvars : List [TypeVar ])(using Context ): Boolean =
445
441
checkPropagated(i " initialized $tl" ) {
446
442
constraint = constraint.add(tl, tvars)
447
443
tl.paramRefs.forall { param =>
@@ -470,7 +466,7 @@ trait ConstraintHandling[AbstractContext] {
470
466
* This holds if `TypeVarsMissContext` is set unless `param` is a part
471
467
* of a MatchType that is currently normalized.
472
468
*/
473
- final def assumedTrue (param : TypeParamRef )(implicit actx : AbstractContext ): Boolean =
469
+ final def assumedTrue (param : TypeParamRef )(using Context ): Boolean =
474
470
ctx.mode.is(Mode .TypevarsMissContext ) && (caseLambda `ne` param.binder)
475
471
476
472
/** Add constraint `param <: bound` if `fromBelow` is false, `param >: bound` otherwise.
@@ -480,7 +476,7 @@ trait ConstraintHandling[AbstractContext] {
480
476
* not be AndTypes and lower bounds may not be OrTypes. This is assured by the
481
477
* way isSubType is organized.
482
478
*/
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 =
484
480
485
481
/** When comparing lambdas we might get constraints such as
486
482
* `A <: X0` or `A = List[X0]` where `A` is a constrained parameter
@@ -514,7 +510,7 @@ trait ConstraintHandling[AbstractContext] {
514
510
case _ : TypeBounds =>
515
511
if (fromBelow) addLess(bound, param) else addLess(param, bound)
516
512
case tp =>
517
- if (fromBelow) isSubType (bound, tp) else isSubType (tp, bound)
513
+ if (fromBelow) isSub (bound, tp) else isSub (tp, bound)
518
514
}
519
515
520
516
def kindCompatible (tp1 : Type , tp2 : Type ): Boolean =
@@ -541,7 +537,7 @@ trait ConstraintHandling[AbstractContext] {
541
537
end addConstraint
542
538
543
539
/** 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 = {
545
541
if (Config .checkConstraintsPropagated && result && addConstraintInvocations == 0 )
546
542
inFrozenConstraint {
547
543
for (p <- constraint.domainParams) {
0 commit comments