@@ -24,17 +24,6 @@ object OrderingConstraint {
24
24
/** The type of `OrderingConstraint#lowerMap`, `OrderingConstraint#upperMap` */
25
25
type ParamOrdering = ArrayValuedMap [List [TypeParamRef ]]
26
26
27
- /** A new constraint with given maps and given set of hard typevars */
28
- private def newConstraint (
29
- boundsMap : ParamBounds , lowerMap : ParamOrdering , upperMap : ParamOrdering ,
30
- hardVars : TypeVars )(using Context ) : OrderingConstraint =
31
- if boundsMap.isEmpty && lowerMap.isEmpty && upperMap.isEmpty then
32
- empty
33
- else
34
- val result = new OrderingConstraint (boundsMap, lowerMap, upperMap, hardVars)
35
- if ctx.run != null then ctx.run.nn.recordConstraintSize(result, result.boundsMap.size)
36
- result
37
-
38
27
/** A lens for updating a single entry array in one of the three constraint maps */
39
28
abstract class ConstraintLens [T <: AnyRef : ClassTag ] {
40
29
def entries (c : OrderingConstraint , poly : TypeLambda ): Array [T ] | Null
@@ -93,23 +82,23 @@ object OrderingConstraint {
93
82
def entries (c : OrderingConstraint , poly : TypeLambda ): Array [Type ] | Null =
94
83
c.boundsMap(poly)
95
84
def updateEntries (c : OrderingConstraint , poly : TypeLambda , entries : Array [Type ])(using Context ): OrderingConstraint =
96
- newConstraint(c.boundsMap.updated(poly, entries), c.lowerMap, c.upperMap, c.hardVars )
85
+ c. newConstraint(boundsMap = c.boundsMap.updated(poly, entries))
97
86
def initial = NoType
98
87
}
99
88
100
89
val lowerLens : ConstraintLens [List [TypeParamRef ]] = new ConstraintLens [List [TypeParamRef ]] {
101
90
def entries (c : OrderingConstraint , poly : TypeLambda ): Array [List [TypeParamRef ]] | Null =
102
91
c.lowerMap(poly)
103
92
def updateEntries (c : OrderingConstraint , poly : TypeLambda , entries : Array [List [TypeParamRef ]])(using Context ): OrderingConstraint =
104
- newConstraint(c.boundsMap, c.lowerMap.updated(poly, entries), c.upperMap, c.hardVars )
93
+ c.newConstraint(lowerMap = c.lowerMap.updated(poly, entries))
105
94
def initial = Nil
106
95
}
107
96
108
97
val upperLens : ConstraintLens [List [TypeParamRef ]] = new ConstraintLens [List [TypeParamRef ]] {
109
98
def entries (c : OrderingConstraint , poly : TypeLambda ): Array [List [TypeParamRef ]] | Null =
110
99
c.upperMap(poly)
111
100
def updateEntries (c : OrderingConstraint , poly : TypeLambda , entries : Array [List [TypeParamRef ]])(using Context ): OrderingConstraint =
112
- newConstraint(c.boundsMap, c.lowerMap, c.upperMap.updated(poly, entries), c.hardVars )
101
+ c.newConstraint(upperMap = c.upperMap.updated(poly, entries))
113
102
def initial = Nil
114
103
}
115
104
@@ -148,6 +137,19 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
148
137
149
138
type This = OrderingConstraint
150
139
140
+ /** A new constraint with given maps and given set of hard typevars */
141
+ def newConstraint ( // !!! Dotty problem: Making newConstraint `private` causes -Ytest-pickler failure.
142
+ boundsMap : ParamBounds = this .boundsMap,
143
+ lowerMap : ParamOrdering = this .lowerMap,
144
+ upperMap : ParamOrdering = this .upperMap,
145
+ hardVars : TypeVars = this .hardVars)(using Context ) : OrderingConstraint =
146
+ if boundsMap.isEmpty && lowerMap.isEmpty && upperMap.isEmpty then
147
+ empty
148
+ else
149
+ val result = new OrderingConstraint (boundsMap, lowerMap, upperMap, hardVars)
150
+ if ctx.run != null then ctx.run.nn.recordConstraintSize(result, result.boundsMap.size)
151
+ result
152
+
151
153
// ----------- Basic indices --------------------------------------------------
152
154
153
155
/** The number of type parameters in the given entry array */
@@ -282,7 +284,8 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
282
284
val entries1 = new Array [Type ](nparams * 2 )
283
285
poly.paramInfos.copyToArray(entries1, 0 )
284
286
tvars.copyToArray(entries1, nparams)
285
- newConstraint(boundsMap.updated(poly, entries1), lowerMap, upperMap, hardVars).init(poly)
287
+ newConstraint(boundsMap = this .boundsMap.updated(poly, entries1))
288
+ .init(poly)
286
289
}
287
290
288
291
/** Split dependent parameters off the bounds for parameters in `poly`.
@@ -511,7 +514,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
511
514
def swapKey [T ](m : ArrayValuedMap [T ]) =
512
515
val info = m(from)
513
516
if info == null then m else m.remove(from).updated(to, info)
514
- var current = newConstraint(swapKey(boundsMap), swapKey(lowerMap), swapKey(upperMap), hardVars )
517
+ var current = newConstraint(swapKey(boundsMap), swapKey(lowerMap), swapKey(upperMap))
515
518
def subst [T <: Type ](x : T ): T = x.subst(from, to).asInstanceOf [T ]
516
519
current.foreachParam {(p, i) =>
517
520
current = boundsLens.map(this , current, p, i, subst)
@@ -524,7 +527,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
524
527
def isHard (tv : TypeVar ) = hardVars.contains(tv)
525
528
526
529
def withHard (tv : TypeVar )(using Context ) =
527
- newConstraint(boundsMap, lowerMap, upperMap, hardVars + tv)
530
+ newConstraint(hardVars = this . hardVars + tv)
528
531
529
532
def instType (tvar : TypeVar ): Type = entry(tvar.origin) match
530
533
case _ : TypeBounds => NoType
0 commit comments