@@ -277,16 +277,28 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
277
277
case _ =>
278
278
traverseChildren(t)
279
279
280
+ /** Adjust dependencies to account for the delta of previous entry `prevEntry`
281
+ * and new bound `entry` for the type variable `tvar`.
282
+ */
280
283
def adjustDeps (entry : Type | Null , prevEntry : Type | Null , tvar : Type | Null )(using Context ): this .type =
281
284
tvar match
282
285
case tvar : TypeVar =>
283
286
val adjuster = new Adjuster (tvar)
284
287
288
+ /** Adjust reverse depemdencies of all type variables referenced by `bound`
289
+ * @param isLower `bound` is a lower bound
290
+ * @param add if true, add referenced variables to dependencoes, otherwise drop them.
291
+ */
285
292
def adjustReferenced (bound : Type , isLower : Boolean , add : Boolean ) =
286
293
adjuster.variance = if isLower then 1 else - 1
287
294
adjuster.add = add
288
295
adjuster.traverse(bound)
289
296
297
+ /** Use an optimized strategy to adjust dependencies to account for the delta
298
+ * of previous bound `prevBound` and new bound `bound`: If `prevBound` is some
299
+ * and/or prefix of `bound`, just add the new parts of `bound`.
300
+ * @param isLower `bound` and `prevBound` are lower bounds
301
+ */
290
302
def adjustDelta (bound : Type , prevBound : Type , isLower : Boolean ): Boolean =
291
303
if bound eq prevBound then true
292
304
else bound match
@@ -297,6 +309,10 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
297
309
}
298
310
case _ => false
299
311
312
+ /** Adjust dependencies to account for the delta of previous bound `prevBound`
313
+ * and new bound `bound`.
314
+ * @param isLower `bound` and `prevBound` are lower bounds
315
+ */
300
316
def adjustBounds (bound : Type , prevBound : Type , isLower : Boolean ) =
301
317
if ! adjustDelta(bound, prevBound, isLower) then
302
318
adjustReferenced(prevBound, isLower, add = false )
@@ -322,19 +338,25 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
322
338
this
323
339
end adjustDeps
324
340
341
+ /** Adjust dependencies to account for adding or dropping `entries` to the
342
+ * constraint.
343
+ * @param add if true, entries is added, otherwise it is dropped
344
+ */
325
345
def adjustDeps (entries : Array [Type ], add : Boolean )(using Context ): this .type =
326
346
for n <- 0 until paramCount(entries) do
327
347
if add
328
348
then adjustDeps(entries(n), NoType , typeVar(entries, n))
329
349
else adjustDeps(NoType , entries(n), typeVar(entries, n))
330
350
this
331
351
352
+ /** If `tp` is a type variable, remove all its reverse dependencies */
332
353
def dropDeps (tp : Type )(using Context ): Unit = tp match
333
354
case tv : TypeVar =>
334
355
coDeps = coDeps.remove(tv)
335
356
contraDeps = contraDeps.remove(tv)
336
357
case _ =>
337
358
359
+ /** A string representing the two depenecy maps */
338
360
def depsToString (using Context ): String =
339
361
def depsStr (deps : SimpleIdentityMap [TypeVar , TypeVars ]): String =
340
362
def depStr (tv : TypeVar ) = i " $tv --> ${deps(tv).nn.toList}%, % "
0 commit comments