Skip to content

Commit d22b699

Browse files
committed
More changes
1 parent a4568ac commit d22b699

File tree

14 files changed

+243
-245
lines changed

14 files changed

+243
-245
lines changed

library/src/scala/collection/Iterator.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
757757
val leading = new Leading
758758

759759
val trailing = new AbstractIterator[A] {
760-
private[this] var myLeading: Leading | Null = leading
760+
private[this] var myLeading = leading
761761
/* Status flag meanings:
762762
* -1 not yet accessed
763763
* 0 single element waiting in leading
@@ -772,14 +772,14 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
772772
case 1 => if (self.hasNext) { status = 2 ; true } else { status = 3 ; false }
773773
case 0 => true
774774
case _ =>
775-
if (myLeading.nn.finish()) { status = 0 ; true } else { status = 1 ; myLeading = null ; hasNext }
775+
if (myLeading.finish()) { status = 0 ; true } else { status = 1 ; myLeading = null.asInstanceOf[Leading]; hasNext }
776776
}
777777
def next() = {
778778
if (hasNext) {
779779
if (status == 0) {
780780
status = 1
781-
val res = myLeading.nn.trailer
782-
myLeading = null
781+
val res = myLeading.trailer
782+
myLeading = null.asInstanceOf[Leading]
783783
res
784784
} else {
785785
status = 1

library/src/scala/collection/View.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ object View extends IterableFactory[View] {
465465
if(pos == maxlen) pos = 0
466466
len += 1
467467
}
468-
underlying = null.asInstanceOf[Iterator[A]^] // allow GC of underlying iterator
468+
underlying = null.asInstanceOf // allow GC of underlying iterator
469469
if(len > maxlen) len = maxlen
470470
pos = pos - len
471471
if(pos < 0) pos += maxlen

library/src/scala/collection/concurrent/TrieMap.scala

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import scala.collection.mutable.GrowableBuilder
2828
import scala.util.Try
2929
import scala.util.hashing.Hashing
3030

31-
private[collection] final class INode[K, V](bn: MainNode[K, V], g: Gen, equiv: Equiv[K]) extends INodeBase[K, V](g) {
31+
private[collection] final class INode[K, V](bn: MainNode[K, V] | Null, g: Gen, equiv: Equiv[K]) extends INodeBase[K, V](g) {
3232
import INodeBase._
3333

3434
WRITE(bn)
@@ -43,14 +43,14 @@ private[collection] final class INode[K, V](bn: MainNode[K, V], g: Gen, equiv: E
4343

4444
def GCAS_READ(ct: TrieMap[K, V]): MainNode[K, V] = {
4545
val m = /*READ*/mainnode
46-
val prevval = /*READ*/m.prev
46+
val prevval: MainNode[K, V] | Null = /*READ*/m.prev
4747
if (prevval eq null) m
4848
else GCAS_Complete(m, ct)
4949
}
5050

5151
@tailrec private def GCAS_Complete(m: MainNode[K, V], ct: TrieMap[K, V]): MainNode[K, V] = if (m eq null) null else {
5252
// complete the GCAS
53-
val prev = /*READ*/m.prev
53+
val prev: MainNode[K, V] | Null = /*READ*/m.prev
5454
val ctr = ct.readRoot(abort = true)
5555

5656
prev match {
@@ -700,7 +700,7 @@ final class TrieMap[K, V] private (r: AnyRef, rtupd: AtomicReferenceFieldUpdater
700700
private[this] var hashingobj = if (hashf.isInstanceOf[Hashing.Default[_]]) new TrieMap.MangledHashing[K] else hashf
701701
private[this] var equalityobj = ef
702702
@transient
703-
private[this] var rootupdater = rtupd
703+
private[this] var rootupdater: AtomicReferenceFieldUpdater[TrieMap[K, V], AnyRef] | Null = rtupd
704704
def hashing = hashingobj
705705
def equality = equalityobj
706706
@volatile private var root = r
@@ -750,7 +750,7 @@ final class TrieMap[K, V] private (r: AnyRef, rtupd: AtomicReferenceFieldUpdater
750750
}
751751
}
752752

753-
private def CAS_ROOT(ov: AnyRef, nv: AnyRef) = rootupdater.compareAndSet(this, ov, nv)
753+
private def CAS_ROOT(ov: AnyRef, nv: AnyRef) = rootupdater.nn.compareAndSet(this, ov, nv)
754754

755755
private[collection] def readRoot(abort: Boolean = false): INode[K, V] = RDCSS_READ_ROOT(abort)
756756

@@ -859,7 +859,7 @@ final class TrieMap[K, V] private (r: AnyRef, rtupd: AtomicReferenceFieldUpdater
859859
@tailrec def snapshot(): TrieMap[K, V] = {
860860
val r = RDCSS_READ_ROOT()
861861
val expmain = r.gcasRead(this)
862-
if (RDCSS_ROOT(r, expmain, r.copyToGen(new Gen, this))) new TrieMap(r.copyToGen(new Gen, this), rootupdater, hashing, equality)
862+
if (RDCSS_ROOT(r, expmain, r.copyToGen(new Gen, this))) new TrieMap(r.copyToGen(new Gen, this), rootupdater.nn, hashing, equality)
863863
else snapshot()
864864
}
865865

@@ -1075,23 +1075,23 @@ private[collection] class TrieMapIterator[K, V](var level: Int, private var ct:
10751075
private val stack = new Array[Array[BasicNode]](7)
10761076
private val stackpos = new Array[Int](7)
10771077
private var depth = -1
1078-
private var subiter: Iterator[(K, V)] = null
1079-
private var current: KVNode[K, V] = null
1078+
@annotation.stableNull private var subiter: Iterator[(K, V)] | Null = null
1079+
@annotation.stableNull private var current: KVNode[K, V] | Null = null
10801080

10811081
if (mustInit) initialize()
10821082

10831083
def hasNext = (current ne null) || (subiter ne null)
10841084

10851085
def next() = if (hasNext) {
1086-
var r: (K, V) = null
1086+
var r: (K, V) | Null = null
10871087
if (subiter ne null) {
1088-
r = subiter.next()
1088+
r = subiter.nn.next()
10891089
checkSubiter()
10901090
} else {
1091-
r = current.kvPair
1091+
r = current.nn.kvPair
10921092
advance()
10931093
}
1094-
r
1094+
r.nn
10951095
} else Iterator.empty.next()
10961096

10971097
private def readin(in: INode[K, V]) = in.gcasRead(ct) match {
@@ -1110,7 +1110,7 @@ private[collection] class TrieMapIterator[K, V](var level: Int, private var ct:
11101110
case mainNode => throw new MatchError(mainNode)
11111111
}
11121112

1113-
private def checkSubiter() = if (!subiter.hasNext) {
1113+
private def checkSubiter() = if (!subiter.nn.hasNext) {
11141114
subiter = null
11151115
advance()
11161116
}
@@ -1153,7 +1153,7 @@ private[collection] class TrieMapIterator[K, V](var level: Int, private var ct:
11531153
// this one needs to be evaluated
11541154
if (this.subiter == null) it.subiter = null
11551155
else {
1156-
val lst = this.subiter.to(immutable.List)
1156+
val lst = this.subiter.nn.to(immutable.List)
11571157
this.subiter = lst.iterator
11581158
it.subiter = lst.iterator
11591159
}

library/src/scala/collection/convert/impl/BinaryTreeStepper.scala

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ package scala.collection.convert
1414
package impl
1515

1616
import scala.language.`2.13`
17-
import scala.language.unsafeNulls
1817

1918
import java.util.Spliterator
2019

@@ -90,7 +89,7 @@ extends EfficientSplit {
9089
*
9190
* Right now overwrites everything so could allow reuse, but isn't used for it.
9291
*/
93-
private[impl] final def initialize(root: T, size: Int): Unit =
92+
private[impl] final def initialize(root: T | Null, size: Int): Unit =
9493
if (root eq null) {
9594
maxLength = 0
9695
myCurrent = null
@@ -158,11 +157,11 @@ with AnyStepper[A] {
158157
}
159158
else Stepper.throwNSEE()
160159

161-
def semiclone(maxL: Int, myC: T, stk: Array[AnyRef | Null], ix: Int): AnyBinaryTreeStepper[A, T] =
160+
def semiclone(maxL: Int, myC: T | Null, stk: Array[AnyRef | Null], ix: Int): AnyBinaryTreeStepper[A, T] =
162161
new AnyBinaryTreeStepper[A, T](maxL, myC, stk, ix, left, right, extract)
163162
}
164163
private[collection] object AnyBinaryTreeStepper {
165-
def from[A, T <: AnyRef](maxLength: Int, root: T, left: T => T, right: T => T, extract: T => A): AnyBinaryTreeStepper[A, T] = {
164+
def from[A, T <: AnyRef](maxLength: Int, root: T | Null, left: T => T, right: T => T, extract: T => A): AnyBinaryTreeStepper[A, T] = {
166165
val ans = new AnyBinaryTreeStepper(0, null, BinaryTreeStepper.emptyStack, -1, left, right, extract)
167166
ans.initialize(root, maxLength)
168167
ans
@@ -184,11 +183,11 @@ with DoubleStepper {
184183
}
185184
else Stepper.throwNSEE()
186185

187-
def semiclone(maxL: Int, myC: T, stk: Array[AnyRef | Null], ix: Int): DoubleBinaryTreeStepper[T] =
186+
def semiclone(maxL: Int, myC: T | Null, stk: Array[AnyRef | Null], ix: Int): DoubleBinaryTreeStepper[T] =
188187
new DoubleBinaryTreeStepper[T](maxL, myC, stk, ix, left, right, extract)
189188
}
190189
private [collection] object DoubleBinaryTreeStepper {
191-
def from[T <: AnyRef](maxLength: Int, root: T, left: T => T, right: T => T, extract: T => Double): DoubleBinaryTreeStepper[T] = {
190+
def from[T <: AnyRef](maxLength: Int, root: T | Null, left: T => T, right: T => T, extract: T => Double): DoubleBinaryTreeStepper[T] = {
192191
val ans = new DoubleBinaryTreeStepper(0, null, BinaryTreeStepper.emptyStack, -1, left, right, extract)
193192
ans.initialize(root, maxLength)
194193
ans
@@ -210,11 +209,11 @@ with IntStepper {
210209
}
211210
else Stepper.throwNSEE()
212211

213-
def semiclone(maxL: Int, myC: T, stk: Array[AnyRef | Null], ix: Int): IntBinaryTreeStepper[T] =
212+
def semiclone(maxL: Int, myC: T | Null, stk: Array[AnyRef | Null], ix: Int): IntBinaryTreeStepper[T] =
214213
new IntBinaryTreeStepper[T](maxL, myC, stk, ix, left, right, extract)
215214
}
216215
private [collection] object IntBinaryTreeStepper {
217-
def from[T <: AnyRef](maxLength: Int, root: T, left: T => T, right: T => T, extract: T => Int): IntBinaryTreeStepper[T] = {
216+
def from[T <: AnyRef](maxLength: Int, root: T | Null, left: T => T, right: T => T, extract: T => Int): IntBinaryTreeStepper[T] = {
218217
val ans = new IntBinaryTreeStepper(0, null, BinaryTreeStepper.emptyStack, -1, left, right, extract)
219218
ans.initialize(root, maxLength)
220219
ans
@@ -237,11 +236,11 @@ with LongStepper {
237236
}
238237
else Stepper.throwNSEE()
239238

240-
def semiclone(maxL: Int, myC: T, stk: Array[AnyRef | Null], ix: Int): LongBinaryTreeStepper[T] =
239+
def semiclone(maxL: Int, myC: T | Null, stk: Array[AnyRef | Null], ix: Int): LongBinaryTreeStepper[T] =
241240
new LongBinaryTreeStepper[T](maxL, myC, stk, ix, left, right, extract)
242241
}
243242
private [collection] object LongBinaryTreeStepper {
244-
def from[T <: AnyRef](maxLength: Int, root: T, left: T => T, right: T => T, extract: T => Long): LongBinaryTreeStepper[T] = {
243+
def from[T <: AnyRef](maxLength: Int, root: T | Null, left: T => T, right: T => T, extract: T => Long): LongBinaryTreeStepper[T] = {
245244
val ans = new LongBinaryTreeStepper(0, null, BinaryTreeStepper.emptyStack, -1, left, right, extract)
246245
ans.initialize(root, maxLength)
247246
ans

library/src/scala/collection/convert/impl/TableStepper.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import scala.collection.Stepper.EfficientSplit
1818
import scala.collection._
1919

2020
private[collection] abstract class TableStepperBase[A, I <: AnyRef, Sub, Semi <: Sub with TableStepperBase[A, I, _, _]](
21-
protected var maxLength: Int, protected val table: Array[I], protected var i0: Int, protected val iN: Int
21+
protected var maxLength: Int, protected val table: Array[I | Null], protected var i0: Int, protected val iN: Int
2222
)
2323
extends EfficientSplit {
2424
// Always holds table(i0); if `null` it is time to switch to the next element
@@ -71,7 +71,7 @@ extends EfficientSplit {
7171

7272

7373
private[collection] final class AnyTableStepper[A, I <: AnyRef](
74-
_maxLength: Int, _table: Array[I], iterate: I => I, extract: I => A, _i0: Int, _iN: Int
74+
_maxLength: Int, _table: Array[I | Null], iterate: I => I, extract: I => A, _i0: Int, _iN: Int
7575
)
7676
extends TableStepperBase[A, I, AnyStepper[A], AnyTableStepper[A, I]](_maxLength, _table, _i0, _iN)
7777
with AnyStepper[A] {
@@ -88,7 +88,7 @@ with AnyStepper[A] {
8888

8989

9090
private[collection] final class DoubleTableStepper[I <: AnyRef](
91-
_maxLength: Int, _table: Array[I], iterate: I => I, extract: I => Double, _i0: Int, _iN: Int
91+
_maxLength: Int, _table: Array[I | Null], iterate: I => I, extract: I => Double, _i0: Int, _iN: Int
9292
)
9393
extends TableStepperBase[Double, I, DoubleStepper, DoubleTableStepper[I]](_maxLength, _table, _i0, _iN)
9494
with DoubleStepper {
@@ -105,7 +105,7 @@ with DoubleStepper {
105105

106106

107107
private[collection] final class IntTableStepper[I <: AnyRef](
108-
_maxLength: Int, _table: Array[I], iterate: I => I, extract: I => Int, _i0: Int, _iN: Int
108+
_maxLength: Int, _table: Array[I | Null], iterate: I => I, extract: I => Int, _i0: Int, _iN: Int
109109
)
110110
extends TableStepperBase[Int, I, IntStepper, IntTableStepper[I]](_maxLength, _table, _i0, _iN)
111111
with IntStepper {
@@ -122,7 +122,7 @@ with IntStepper {
122122

123123

124124
private[collection] final class LongTableStepper[I <: AnyRef](
125-
_maxLength: Int, _table: Array[I], iterate: I => I, extract: I => Long, _i0: Int, _iN: Int
125+
_maxLength: Int, _table: Array[I | Null], iterate: I => I, extract: I => Long, _i0: Int, _iN: Int
126126
)
127127
extends TableStepperBase[Long, I, LongStepper, LongTableStepper[I]](_maxLength, _table, _i0, _iN)
128128
with LongStepper {

library/src/scala/collection/immutable/HashMap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ private final class BitmapIndexedMapNode[K, +V](
863863
}
864864
}
865865

866-
def removed[V1 >: V](key: K, originalHash: Int, keyHash: Int, shift: Int): BitmapIndexedMapNode[K, V1] | Null = {
866+
def removed[V1 >: V](key: K, originalHash: Int, keyHash: Int, shift: Int): BitmapIndexedMapNode[K, V1] = {
867867
val mask = maskFrom(keyHash, shift)
868868
val bitpos = bitposFrom(mask)
869869

0 commit comments

Comments
 (0)