@@ -226,6 +226,10 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
226
226
227
227
var coDeps, contraDeps : ReverseDeps = SimpleIdentityMap .empty
228
228
229
+ extension (deps : ReverseDeps ) def at (param : TypeParamRef ): SimpleIdentitySet [TypeParamRef ] =
230
+ val result = deps(param)
231
+ if null == result then SimpleIdentitySet .empty else result
232
+
229
233
def dependsOn (tv : TypeVar , except : TypeVars , co : Boolean )(using Context ): Boolean =
230
234
def origin (tv : TypeVar ) =
231
235
assert(! tv.isInstantiated)
@@ -234,8 +238,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
234
238
val excluded = except.map(origin)
235
239
val qualifies : TypeParamRef => Boolean = ! excluded.contains(_)
236
240
def test (deps : ReverseDeps , lens : ConstraintLens [List [TypeParamRef ]]) =
237
- val depending = deps(param)
238
- null != depending && depending.exists(qualifies)
241
+ deps.at(param).exists(qualifies)
239
242
|| lens(this , tv.origin.binder, tv.origin.paramNum).exists(qualifies)
240
243
// .showing(i"outer depends on $tv with ${tvdeps.toList}%, % = $result")
241
244
if co then test(coDeps, upperLens) else test(contraDeps, lowerLens)
@@ -244,10 +247,8 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
244
247
var add : Boolean = compiletime.uninitialized
245
248
246
249
def update (deps : ReverseDeps , referenced : TypeParamRef ): ReverseDeps =
247
- val entry = deps(referenced)
248
- val prev = if null == entry then SimpleIdentitySet .empty else entry
249
- val now = if add then prev + srcParam else prev - srcParam
250
- deps.updated(referenced, now)
250
+ val prev = deps.at(referenced)
251
+ deps.updated(referenced, if add then prev + srcParam else prev - srcParam)
251
252
252
253
def traverse (t : Type ) = t match
253
254
case param : TypeParamRef =>
@@ -335,9 +336,9 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
335
336
/** A string representing the two depenecy maps */
336
337
def depsToString (using Context ): String =
337
338
def depsStr (deps : ReverseDeps ): String =
338
- def depStr (param : TypeParamRef ) = i " $param --> ${deps(param).nn .toList}%, % "
339
- if deps.isEmpty then " " else i " \n ${deps.toList.map((k, v) => depStr(k))}% \n % "
340
- i " co-deps: ${depsStr(coDeps)}\n contra -deps: ${depsStr(contraDeps)}\n "
339
+ def depStr (param : TypeParamRef ) = i " $param --> ${deps.at (param).toList}%, % "
340
+ if deps.isEmpty then " " else i " \n ${deps.toList.map((k, v) => depStr(k))}% \n %"
341
+ i " co-deps: ${depsStr(coDeps)}\n contra -deps: ${depsStr(contraDeps)}\n "
341
342
342
343
// ---------- Adding TypeLambdas --------------------------------------------------
343
344
@@ -550,11 +551,14 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
550
551
case _ =>
551
552
Nil
552
553
553
- private def updateEntry (current : This , param : TypeParamRef , tp : Type )(using Context ): This = {
554
- if Config .checkNoWildcardsInConstraint then assert(! tp.containsWildcardTypes)
555
- var current1 = boundsLens.update(this , current, param, tp)
556
- current1.adjustDeps(tp, current.entry(param), param)
557
- tp match {
554
+ private def updateEntryNoOrdering (current : This , param : TypeParamRef , newEntry : Type , oldEntry : Type )(using Context ): This =
555
+ boundsLens.update(this , current, param, newEntry).adjustDeps(newEntry, oldEntry, param)
556
+
557
+ private def updateEntry (current : This , param : TypeParamRef , newEntry : Type )(using Context ): This = {
558
+ // println(i"update $param to $tp in $current")
559
+ if Config .checkNoWildcardsInConstraint then assert(! newEntry.containsWildcardTypes)
560
+ var current1 = updateEntryNoOrdering(current, param, newEntry, current.entry(param))
561
+ newEntry match {
558
562
case TypeBounds (lo, hi) =>
559
563
for p <- dependentParams(lo, isUpper = false ) do
560
564
current1 = order(current1, p, param)
@@ -758,6 +762,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
758
762
checkDeps(coDeps)
759
763
checkDeps(contraDeps)
760
764
this
765
+ end checkWellFormed
761
766
762
767
def occursAtToplevel (param : TypeParamRef , inst : Type )(using Context ): Boolean =
763
768
0 commit comments