@@ -2,7 +2,7 @@ package dotty.tools
22package dotc
33package core
44
5- // import scala.language.{unsafeNulls => _}
5+ import scala .language .{unsafeNulls => _ }
66
77import Types ._ , Contexts ._ , Symbols ._ , Decorators ._ , TypeApplications ._
88import util .SimpleIdentityMap
@@ -36,7 +36,7 @@ object OrderingConstraint {
3636
3737 /** A lens for updating a single entry array in one of the three constraint maps */
3838 abstract class ConstraintLens [T <: AnyRef : ClassTag ] {
39- def entries (c : OrderingConstraint , poly : TypeLambda ): Array [T ]
39+ def entries (c : OrderingConstraint , poly : TypeLambda ): Array [T ] | Null
4040 def updateEntries (c : OrderingConstraint , poly : TypeLambda , entries : Array [T ])(using Context ): OrderingConstraint
4141 def initial : T
4242
@@ -53,20 +53,23 @@ object OrderingConstraint {
5353 def update (prev : OrderingConstraint , current : OrderingConstraint ,
5454 poly : TypeLambda , idx : Int , entry : T )(using Context ): OrderingConstraint = {
5555 var es = entries(current, poly)
56- if (es != null && (es(idx) eq entry)) current
56+ if (es != null && (es.nn (idx) eq entry)) current
5757 else {
5858 val result =
5959 if (es == null ) {
6060 es = Array .fill(poly.paramNames.length)(initial)
61- updateEntries(current, poly, es)
61+ updateEntries(current, poly, es.nn )
6262 }
63- else if (es ne entries(prev, poly))
64- current // can re-use existing entries array.
6563 else {
66- es = es.clone
67- updateEntries(current, poly, es)
64+ val prev_es = entries(prev, poly)
65+ if (prev_es == null || (es.nn ne prev_es.nn))
66+ current // can re-use existing entries array.
67+ else {
68+ es = es.nn.clone
69+ updateEntries(current, poly, es.nn)
70+ }
6871 }
69- es(idx) = entry
72+ es.nn (idx) = entry
7073 result
7174 }
7275 }
@@ -85,23 +88,23 @@ object OrderingConstraint {
8588 }
8689
8790 val boundsLens : ConstraintLens [Type ] = new ConstraintLens [Type ] {
88- def entries (c : OrderingConstraint , poly : TypeLambda ): Array [Type ] =
91+ def entries (c : OrderingConstraint , poly : TypeLambda ): Array [Type ] | Null =
8992 c.boundsMap(poly)
9093 def updateEntries (c : OrderingConstraint , poly : TypeLambda , entries : Array [Type ])(using Context ): OrderingConstraint =
9194 newConstraint(c.boundsMap.updated(poly, entries), c.lowerMap, c.upperMap)
9295 def initial = NoType
9396 }
9497
9598 val lowerLens : ConstraintLens [List [TypeParamRef ]] = new ConstraintLens [List [TypeParamRef ]] {
96- def entries (c : OrderingConstraint , poly : TypeLambda ): Array [List [TypeParamRef ]] =
99+ def entries (c : OrderingConstraint , poly : TypeLambda ): Array [List [TypeParamRef ]] | Null =
97100 c.lowerMap(poly)
98101 def updateEntries (c : OrderingConstraint , poly : TypeLambda , entries : Array [List [TypeParamRef ]])(using Context ): OrderingConstraint =
99102 newConstraint(c.boundsMap, c.lowerMap.updated(poly, entries), c.upperMap)
100103 def initial = Nil
101104 }
102105
103106 val upperLens : ConstraintLens [List [TypeParamRef ]] = new ConstraintLens [List [TypeParamRef ]] {
104- def entries (c : OrderingConstraint , poly : TypeLambda ): Array [List [TypeParamRef ]] =
107+ def entries (c : OrderingConstraint , poly : TypeLambda ): Array [List [TypeParamRef ]] | Null =
105108 c.upperMap(poly)
106109 def updateEntries (c : OrderingConstraint , poly : TypeLambda , entries : Array [List [TypeParamRef ]])(using Context ): OrderingConstraint =
107110 newConstraint(c.boundsMap, c.lowerMap, c.upperMap.updated(poly, entries))
@@ -203,11 +206,8 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
203206
204207 def typeVarOfParam (param : TypeParamRef ): Type = {
205208 val entries = boundsMap(param.binder)
206- if (entries == null ) NoType
207- else {
208- val tvar = typeVar(entries, param.paramNum)
209- if (tvar != null ) tvar else NoType
210- }
209+ if entries == null then NoType
210+ else typeVar(entries, param.paramNum)
211211 }
212212
213213// ---------- Adding TypeLambdas --------------------------------------------------
@@ -472,7 +472,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
472472 }
473473
474474 def isRemovable (pt : TypeLambda ): Boolean = {
475- val entries = boundsMap(pt)
475+ val entries = boundsMap(pt).nn
476476 @ tailrec def allRemovable (last : Int ): Boolean =
477477 if (last < 0 ) true
478478 else typeVar(entries, last) match {
@@ -491,7 +491,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
491491 (this .typeVarOfParam(tl.paramRefs(0 )) ne that.typeVarOfParam(tl.paramRefs(0 )))
492492
493493 def subst (from : TypeLambda , to : TypeLambda )(using Context ): OrderingConstraint =
494- def swapKey [T ](m : ArrayValuedMap [T ]) = m.remove(from).updated(to, m(from))
494+ def swapKey [T ](m : ArrayValuedMap [T ]) = m.remove(from).updated(to, m(from).nn )
495495 var current = newConstraint(swapKey(boundsMap), swapKey(lowerMap), swapKey(upperMap))
496496 def subst [T <: Type ](x : T ): T = x.subst(from, to).asInstanceOf [T ]
497497 current.foreachParam {(p, i) =>
@@ -560,21 +560,21 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
560560 i += 1
561561 }
562562
563- private var myUninstVars : mutable.ArrayBuffer [TypeVar ] = _
563+ private var myUninstVars : mutable.ArrayBuffer [TypeVar ] | Null = _
564564
565565 /** The uninstantiated typevars of this constraint */
566566 def uninstVars : collection.Seq [TypeVar ] = {
567- if (myUninstVars == null || myUninstVars.exists(_.inst.exists)) {
567+ if (myUninstVars == null || myUninstVars.uncheckedNN. exists(_.inst.exists)) {
568568 myUninstVars = new mutable.ArrayBuffer [TypeVar ]
569569 boundsMap.foreachBinding { (poly, entries) =>
570570 for (i <- 0 until paramCount(entries))
571571 typeVar(entries, i) match {
572- case tv : TypeVar if ! tv.inst.exists && isBounds(entries(i)) => myUninstVars += tv
572+ case tv : TypeVar if ! tv.inst.exists && isBounds(entries(i)) => myUninstVars.nn += tv
573573 case _ =>
574574 }
575575 }
576576 }
577- myUninstVars
577+ myUninstVars.nn
578578 }
579579
580580// ---------- Checking -----------------------------------------------
@@ -617,7 +617,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
617617 case TypeParamRef (binder : TypeLambda , _) => ! contains(binder)
618618 case _ => false
619619
620- def checkClosedType (tp : Type , where : String ) =
620+ def checkClosedType (tp : Type | Null , where : String ) =
621621 if tp != null then
622622 assert(! tp.existsPart(isFreeTypeParamRef), i " unclosed constraint: $this refers to $tp in $where" )
623623
0 commit comments