Skip to content

Commit 609d29f

Browse files
committed
Remove unnecessary uses of uncheckedNN
1 parent baabe16 commit 609d29f

File tree

13 files changed

+35
-49
lines changed

13 files changed

+35
-49
lines changed

compiler/src/dotty/tools/backend/jvm/BCodeSyncAndTry.scala

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ trait BCodeSyncAndTry extends BCodeBodyBuilder {
213213
val acquiredStack = if needStackStash then stack.acquireFullStack() else null
214214
val stashLocals =
215215
if acquiredStack == null then null
216-
else acquiredStack.uncheckedNN.filter(_ != UNIT).map(btpe => locals.makeTempLocal(btpe))
216+
else acquiredStack.filter(_ != UNIT).map(btpe => locals.makeTempLocal(btpe))
217217

218218
val hasFinally = (finalizer != tpd.EmptyTree)
219219

@@ -240,9 +240,8 @@ trait BCodeSyncAndTry extends BCodeBodyBuilder {
240240
*/
241241

242242
if stashLocals != null then
243-
val stashLocalsNN = stashLocals.uncheckedNN // why is this necessary?
244-
for i <- (stashLocalsNN.length - 1) to 0 by -1 do
245-
val local = stashLocalsNN(i)
243+
for i <- (stashLocals.length - 1) to 0 by -1 do
244+
val local = stashLocals(i)
246245
bc.store(local.idx, local.tk)
247246

248247
/* ------ (1) try-block, protected by:
@@ -398,17 +397,15 @@ trait BCodeSyncAndTry extends BCodeBodyBuilder {
398397
*/
399398

400399
if stashLocals != null then
401-
val stashLocalsNN = stashLocals.uncheckedNN // why is this necessary?
402-
403400
val resultLoc =
404401
if kind == UNIT then null
405402
else if tmp != null then locals(tmp) // reuse the same local
406403
else locals.makeTempLocal(kind)
407404
if resultLoc != null then
408405
bc.store(resultLoc.idx, kind)
409406

410-
for i <- 0 until stashLocalsNN.size do
411-
val local = stashLocalsNN(i)
407+
for i <- 0 until stashLocals.size do
408+
val local = stashLocals(i)
412409
bc.load(local.idx, local.tk)
413410
if local.tk.isRef then
414411
bc.emit(asm.Opcodes.ACONST_NULL)

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
276276
val previousParamRefs: ListBuffer[TermRef] =
277277
// It is ok to assign `null` here.
278278
// If `isParamDependent == false`, the value of `previousParamRefs` is not used.
279-
if isParamDependent then mutable.ListBuffer[TermRef]() else (null: ListBuffer[TermRef] | Null).uncheckedNN
279+
if isParamDependent then mutable.ListBuffer[TermRef]() else null.asInstanceOf[ListBuffer[TermRef]]
280280

281281
def valueParam(name: TermName, origInfo: Type, isErased: Boolean): TermSymbol =
282282
val maybeImplicit =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ object Contexts {
870870
finally ctx.base.comparersInUse = saved
871871
end comparing
872872

873-
@sharable val NoContext: Context = new FreshContext((null: ContextBase | Null).uncheckedNN) {
873+
@sharable val NoContext: Context = new FreshContext(null.asInstanceOf[ContextBase]) {
874874
override val implicits: ContextualImplicits = new ContextualImplicits(Nil, null, false)(this: @unchecked)
875875
setSource(NoSource)
876876
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5046,7 +5046,7 @@ object Types extends TypeUtils {
50465046
assert(currentEntry.bounds.contains(tp),
50475047
i"$origin is constrained to be $currentEntry but attempted to instantiate it to $tp")
50485048

5049-
if ((ctx.typerState eq owningState.nn.get.uncheckedNN) && !TypeComparer.subtypeCheckInProgress)
5049+
if ((ctx.typerState eq owningState.nn.get) && !TypeComparer.subtypeCheckInProgress)
50505050
setPermanentInst(tp)
50515051
ctx.typerState.constraint = ctx.typerState.constraint.replace(origin, tp)
50525052
tp

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class TreePickler(pickler: TastyPickler, attributes: Attributes) {
118118
else if label == NoAddr then
119119
pickleForwardSymRef(sym)
120120
else
121-
writeRef(label.uncheckedNN) // !!! Dotty problem: Not clear why nn or uncheckedNN is needed here
121+
writeRef(label)
122122

123123
private def pickleForwardSymRef(sym: Symbol)(using Context) = {
124124
val ref = reserveRef(relative = false)
@@ -184,7 +184,7 @@ class TreePickler(pickler: TastyPickler, attributes: Attributes) {
184184
}
185185
else {
186186
writeByte(SHAREDtype)
187-
writeRef(prev.uncheckedNN)
187+
writeRef(prev)
188188
}
189189
}
190190
catch {
@@ -260,7 +260,7 @@ class TreePickler(pickler: TastyPickler, attributes: Attributes) {
260260
writeByte(RECthis)
261261
val binderAddr: Addr | Null = pickledTypes.lookup(tpe.binder)
262262
assert(binderAddr != null, tpe.binder)
263-
writeRef(binderAddr.uncheckedNN)
263+
writeRef(binderAddr)
264264
case tpe: SkolemType =>
265265
pickleType(tpe.info)
266266
case tpe: RefinedType =>

compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,6 @@ class DependencyRecorder {
548548
* This is backed by a cache which is invalidated when `ctx.owner` changes.
549549
*/
550550
private def resolveDependencyFromClass(using Context): Symbol = {
551-
import dotty.tools.uncheckedNN
552551
if (lastOwner != ctx.owner) {
553552
lastOwner = ctx.owner
554553
val source = nonLocalEnclosingClass

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,12 +2151,10 @@ sealed class TermRefSet(using Context):
21512151
if !that.isEmpty then that.foreach(+=)
21522152

21532153
def foreach[U](f: TermRef => U): Unit =
2154-
def handle(sym: TermSymbol | Null, prefixes: Type | List[Type] | Null): Unit =
2155-
// We cannot use `.nn` here due to inference issue.
2156-
val prefixes0: Type | List[Type] = prefixes.uncheckedNN
2157-
prefixes0 match
2158-
case prefix: Type => f(TermRef(prefix, sym.uncheckedNN))
2159-
case prefixes: List[Type] => prefixes.foreach(pre => f(TermRef(pre, sym.uncheckedNN)))
2154+
def handle(sym: TermSymbol, prefixes: Type | List[Type]): Unit =
2155+
prefixes match
2156+
case prefix: Type => f(TermRef(prefix, sym))
2157+
case prefixes: List[Type] => prefixes.foreach(pre => f(TermRef(pre, sym)))
21602158
elems.forEach(handle)
21612159

21622160
// used only for debugging

compiler/src/dotty/tools/dotc/util/EqHashSet.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package dotty.tools.dotc.util
22

3-
import dotty.tools.uncheckedNN
4-
53
object EqHashSet:
64

75
def from[T](xs: IterableOnce[T]): EqHashSet[T] =
@@ -47,7 +45,7 @@ class EqHashSet[T](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends
4745
var idx = firstIndex(x)
4846
var e: T | Null = entryAt(idx)
4947
while e != null do
50-
if isEqual(e.uncheckedNN, x) then return e
48+
if isEqual(e, x) then return e
5149
idx = nextIndex(idx)
5250
e = entryAt(idx)
5351
null
@@ -66,7 +64,7 @@ class EqHashSet[T](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends
6664
var idx = firstIndex(x)
6765
var e: T | Null = entryAt(idx)
6866
while e != null do
69-
if isEqual(e.uncheckedNN, x) then return false // already entered
67+
if isEqual(e, x) then return false // already entered
7068
idx = nextIndex(idx)
7169
e = entryAt(idx)
7270
addEntryAt(idx, x)
@@ -77,8 +75,7 @@ class EqHashSet[T](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends
7775
var idx = firstIndex(x)
7876
var e: T | Null = entryAt(idx)
7977
while e != null do
80-
// TODO: remove uncheckedNN when explicit-nulls is enabled for regule compiling
81-
if isEqual(e.uncheckedNN, x) then return e.uncheckedNN
78+
if isEqual(e, x) then return e
8279
idx = nextIndex(idx)
8380
e = entryAt(idx)
8481
addEntryAt(idx, x)
@@ -101,6 +98,6 @@ class EqHashSet[T](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends
10198
var idx = 0
10299
while idx < oldTable.length do
103100
val e: T | Null = oldTable(idx).asInstanceOf[T | Null]
104-
if e != null then addOld(e.uncheckedNN)
101+
if e != null then addOld(e)
105102
idx += 1
106103
}

compiler/src/dotty/tools/dotc/util/GenericHashSet.scala

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ abstract class GenericHashSet[T](initialCapacity: Int = 8, capacityMultiple: Int
7474
var idx = firstIndex(x)
7575
var e: T | Null = entryAt(idx)
7676
while e != null do
77-
if isEqual(e.uncheckedNN, x) then return e
77+
if isEqual(e, x) then return e
7878
idx = nextIndex(idx)
7979
e = entryAt(idx)
8080
null
@@ -93,7 +93,7 @@ abstract class GenericHashSet[T](initialCapacity: Int = 8, capacityMultiple: Int
9393
var idx = firstIndex(x)
9494
var e: T | Null = entryAt(idx)
9595
while e != null do
96-
if isEqual(e.uncheckedNN, x) then return false // already entered
96+
if isEqual(e, x) then return false // already entered
9797
idx = nextIndex(idx)
9898
e = entryAt(idx)
9999
addEntryAt(idx, x)
@@ -104,8 +104,7 @@ abstract class GenericHashSet[T](initialCapacity: Int = 8, capacityMultiple: Int
104104
var idx = firstIndex(x)
105105
var e: T | Null = entryAt(idx)
106106
while e != null do
107-
// TODO: remove uncheckedNN when explicit-nulls is enabled for regule compiling
108-
if isEqual(e.uncheckedNN, x) then return e.uncheckedNN
107+
if isEqual(e, x) then return e
109108
idx = nextIndex(idx)
110109
e = entryAt(idx)
111110
addEntryAt(idx, x)
@@ -117,20 +116,20 @@ abstract class GenericHashSet[T](initialCapacity: Int = 8, capacityMultiple: Int
117116
var idx = firstIndex(x)
118117
var e: T | Null = entryAt(idx)
119118
while e != null do
120-
if isEqual(e.uncheckedNN, x) then
119+
if isEqual(e, x) then
121120
var hole = idx
122121
while
123122
idx = nextIndex(idx)
124123
e = entryAt(idx)
125124
e != null
126125
do
127-
val eidx = index(hash(e.uncheckedNN))
126+
val eidx = index(hash(e))
128127
if isDense
129128
|| index(eidx - (hole + 1)) > index(idx - (hole + 1))
130129
// entry `e` at `idx` can move unless `index(hash(e))` is in
131130
// the (ring-)interval [hole + 1 .. idx]
132131
then
133-
setEntry(hole, e.uncheckedNN)
132+
setEntry(hole, e)
134133
hole = idx
135134
table(hole) = null
136135
used -= 1
@@ -158,7 +157,7 @@ abstract class GenericHashSet[T](initialCapacity: Int = 8, capacityMultiple: Int
158157
var idx = 0
159158
while idx < oldTable.length do
160159
val e: T | Null = oldTable(idx).asInstanceOf[T | Null]
161-
if e != null then addOld(e.uncheckedNN)
160+
if e != null then addOld(e)
162161
idx += 1
163162

164163
protected def growTable(): Unit =

compiler/src/dotty/tools/dotc/util/HashSet.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package dotty.tools.dotc.util
22

3-
import dotty.tools.uncheckedNN
4-
53
object HashSet:
64

75
def from[T](xs: IterableOnce[T]): HashSet[T] =
@@ -51,7 +49,7 @@ class HashSet[T](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends Ge
5149
var idx = firstIndex(x)
5250
var e: T | Null = entryAt(idx)
5351
while e != null do
54-
if isEqual(e.uncheckedNN, x) then return e
52+
if isEqual(e, x) then return e
5553
idx = nextIndex(idx)
5654
e = entryAt(idx)
5755
null
@@ -69,7 +67,7 @@ class HashSet[T](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends Ge
6967
var idx = firstIndex(x)
7068
var e: T | Null = entryAt(idx)
7169
while e != null do
72-
if isEqual(e.uncheckedNN, x) then return false // already entered
70+
if isEqual(e, x) then return false // already entered
7371
idx = nextIndex(idx)
7472
e = entryAt(idx)
7573
addEntryAt(idx, x)
@@ -80,8 +78,7 @@ class HashSet[T](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends Ge
8078
var idx = firstIndex(x)
8179
var e: T | Null = entryAt(idx)
8280
while e != null do
83-
// TODO: remove uncheckedNN when explicit-nulls is enabled for regule compiling
84-
if isEqual(e.uncheckedNN, x) then return e.uncheckedNN
81+
if isEqual(e, x) then return e
8582
idx = nextIndex(idx)
8683
e = entryAt(idx)
8784
addEntryAt(idx, x)
@@ -104,6 +101,6 @@ class HashSet[T](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends Ge
104101
var idx = 0
105102
while idx < oldTable.length do
106103
val e: T | Null = oldTable(idx).asInstanceOf[T | Null]
107-
if e != null then addOld(e.uncheckedNN)
104+
if e != null then addOld(e)
108105
idx += 1
109106
}

0 commit comments

Comments
 (0)