Skip to content

Commit cd0dbd7

Browse files
committed
Finish core
1 parent abad622 commit cd0dbd7

File tree

3 files changed

+34
-33
lines changed

3 files changed

+34
-33
lines changed

compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotty.tools
22
package dotc
33
package core
44

5-
// import scala.language.{unsafeNulls => _}
5+
import scala.language.{unsafeNulls => _}
66

77
import Types._, Contexts._, Symbols._, Decorators._, TypeApplications._
88
import 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

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotty.tools
22
package dotc
33
package core
44

5-
// import scala.language.{unsafeNulls => _}
5+
import scala.language.{unsafeNulls => _}
66

77
import util.common._
88
import Symbols._
@@ -3919,7 +3919,7 @@ object Types {
39193919
val bs1 = new BinderPairs(this, that, bs)
39203920
// `paramInfos` and `resType` might still be uninstantiated at this point
39213921
// TODO: test remove null check
3922-
paramInfos != null && resType != null &&
3922+
// paramInfos != null && resType != null &&
39233923
paramInfos.equalElements(that.paramInfos, bs1) &&
39243924
resType.equals(that.resType, bs1)
39253925
}
@@ -4528,8 +4528,9 @@ object Types {
45284528

45294529
override def underlying(using Context): Type = {
45304530
val infos = binder.paramInfos
4531-
if (infos == null) NoType // this can happen if the referenced generic type is not initialized yet
4532-
else infos(paramNum)
4531+
// if (infos == null) NoType // this can happen if the referenced generic type is not initialized yet
4532+
// else infos(paramNum)
4533+
infos(paramNum)
45334534
}
45344535

45354536
override def computeHash(bs: Binders | Null): Int = doHash(paramNum, binder.identityHash(bs))
@@ -4739,7 +4740,7 @@ object Types {
47394740
assert(currentEntry.bounds.contains(tp),
47404741
i"$origin is constrained to be $currentEntry but attempted to instantiate it to $tp")
47414742

4742-
if ((ctx.typerState eq owningState.get.uncheckedNN) && !TypeComparer.subtypeCheckInProgress)
4743+
if ((ctx.typerState eq owningState.nn.get.uncheckedNN) && !TypeComparer.subtypeCheckInProgress)
47434744
setInst(tp)
47444745
ctx.typerState.constraint = ctx.typerState.constraint.replace(origin, tp)
47454746
tp

compiler/src/dotty/tools/dotc/transform/MegaPhase.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotty.tools
22
package dotc
33
package transform
44

5-
// import scala.language.{unsafeNulls => _}
5+
import scala.language.{unsafeNulls => _}
66

77
import core._
88
import ast.Trees._
@@ -469,7 +469,7 @@ class MegaPhase(val miniPhases: Array[MiniPhase]) extends Phase {
469469
}
470470

471471
/** Class#getDeclaredMethods is slow, so we cache its output */
472-
private val clsMethodsCache = new java.util.IdentityHashMap[Class[?], Array[java.lang.reflect.Method]]
472+
private val clsMethodsCache = new java.util.IdentityHashMap[Class[?], Array[java.lang.reflect.Method | Null]]
473473

474474
/** Does `phase` contain a redefinition of method `name`?
475475
* (which is a method of MiniPhase)
@@ -483,8 +483,8 @@ class MegaPhase(val miniPhases: Array[MiniPhase]) extends Phase {
483483
clsMethods = cls.getDeclaredMethods
484484
clsMethodsCache.put(cls, clsMethods)
485485
}
486-
clsMethods.exists(_.getName == name) ||
487-
hasRedefinedMethod(cls.getSuperclass)
486+
clsMethods.nn.exists(_.nn.getName == name) ||
487+
hasRedefinedMethod(cls.getSuperclass.nn)
488488
}
489489
hasRedefinedMethod(phase.getClass)
490490
}

0 commit comments

Comments
 (0)