Skip to content

Commit

Permalink
use new wildcard syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Jan 24, 2024
1 parent 6df3ffc commit c664f6d
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extends GenericParCompanion[CC] {
def concat[A](xss: Iterable[A]*): CC[A] = {
val b = newBuilder[A]
// At present we're using IndexedSeq as a proxy for "has a cheap size method".
if (xss forall (_.isInstanceOf[IndexedSeq[_]]))
if (xss forall (_.isInstanceOf[IndexedSeq[?]]))
b.sizeHint(xss.map(_.size).sum)

for (xs <- xss) b ++= xs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import scala.collection.parallel.ParSetLike
* @define factoryInfo
* This object provides a set of operations needed to create `$Coll` values.
*/
abstract class ParSetFactory[CC[X] <: ParSet[X] with ParSetLike[X, CC, CC[X], _] with GenericParTemplate[X, CC]]
abstract class ParSetFactory[CC[X] <: ParSet[X] with ParSetLike[X, CC, CC[X], ?] with GenericParTemplate[X, CC]]
extends GenericParCompanion[CC] {
def newBuilder[A]: Combiner[A, CC[A]] = newCombiner[A]

Expand Down
12 changes: 6 additions & 6 deletions core/src/main/scala/scala/collection/immutable/OldHashMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,13 @@ object OldHashMap extends MapFactory[OldHashMap] {
val sizeNew = size - sub.size
// if we have only one child, which is not a HashTrieSet but a self-contained set like
// HashSet1 or HashSetCollision1, return the child instead
if (elemsNew.length == 1 && !elemsNew(0).isInstanceOf[HashTrieMap[_,_]])
if (elemsNew.length == 1 && !elemsNew(0).isInstanceOf[HashTrieMap[?,?]])
elemsNew(0)
else
new HashTrieMap(bitmapNew, elemsNew, sizeNew)
} else
OldHashMap.empty[K,V]
} else if(elems.length == 1 && !subNew.isInstanceOf[HashTrieMap[_,_]]) {
} else if(elems.length == 1 && !subNew.isInstanceOf[HashTrieMap[?,?]]) {
subNew
} else {
val elemsNew = java.util.Arrays.copyOf(elems, elems.length)
Expand Down Expand Up @@ -529,9 +529,9 @@ object OldHashMap extends MapFactory[OldHashMap] {
}

protected def merge0[V1 >: V](that: OldHashMap[K, V1], level: Int, merger: Merger[K, V1]): OldHashMap[K, V1] = that match {
case hm: OldHashMap1[_, _] =>
case hm: OldHashMap1[?, ?] =>
this.updated0(hm.key, hm.hash, level, hm.value.asInstanceOf[V1], hm.kv, merger)
case hm: HashTrieMap[_, _] =>
case hm: HashTrieMap[?, ?] =>
val that = hm.asInstanceOf[HashTrieMap[K, V1]]
val thiselems = this.elems
val thatelems = that.elems
Expand Down Expand Up @@ -582,8 +582,8 @@ object OldHashMap extends MapFactory[OldHashMap] {
}

new HashTrieMap[K, V1](this.bitmap | that.bitmap, merged, totalelems)
case hm: OldHashMapCollision1[_, _] => that.merge0(this, level, merger.invert)
case hm: OldHashMap[_, _] => this
case hm: OldHashMapCollision1[?, ?] => that.merge0(this, level, merger.invert)
case hm: OldHashMap[?, ?] => this
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,13 +579,13 @@ object OldHashSet extends IterableFactory[OldHashSet] {
val sizeNew = size - sub.size
// if we have only one child, which is not a HashTrieSet but a self-contained set like
// OldHashSet1 or OldHashSetCollision1, return the child instead
if (elemsNew.length == 1 && !elemsNew(0).isInstanceOf[HashTrieSet[_]])
if (elemsNew.length == 1 && !elemsNew(0).isInstanceOf[HashTrieSet[?]])
elemsNew(0)
else
new HashTrieSet(bitmapNew, elemsNew, sizeNew)
} else
null
} else if(elems.length == 1 && !subNew.isInstanceOf[HashTrieSet[_]]) {
} else if(elems.length == 1 && !subNew.isInstanceOf[HashTrieSet[?]]) {
subNew
} else {
val elemsNew = java.util.Arrays.copyOf(elems, elems.length)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,23 @@ private[collection] abstract class TrieIterator[+T](elems: Array[Iterable[T]]) e
private[this] var subIter = initSubIter

private[this] def getElems(x: Iterable[T]): Array[Iterable[T]] = ((x: @unchecked) match {
case x: HashTrieMap[_, _] => x.elems
case x: HashTrieSet[_] => x.elems
case x: HashTrieMap[?, ?] => x.elems
case x: HashTrieSet[?] => x.elems
}).asInstanceOf[Array[Iterable[T]]]

private[this] def collisionToArray(x: Iterable[T]): Array[Iterable[T]] = ((x: @unchecked) match {
case x: OldHashMapCollision1[_, _] => x.kvs.map((x: (Any, Any)) => OldHashMap(x)).toArray
case x: OldHashSetCollision1[_] => x.ks.map(x => OldHashSet(x)).toArray
case x: OldHashMapCollision1[?, ?] => x.kvs.map((x: (Any, Any)) => OldHashMap(x)).toArray
case x: OldHashSetCollision1[?] => x.ks.map(x => OldHashSet(x)).toArray
}).asInstanceOf[Array[Iterable[T]]]

private[this] type SplitIterators = ((Iterator[T], Int), Iterator[T])

private def isTrie(x: AnyRef) = x match {
case _: HashTrieMap[_,_] | _: HashTrieSet[_] => true
case _: HashTrieMap[?,?] | _: HashTrieSet[?] => true
case _ => false
}
private def isContainer(x: AnyRef) = x match {
case _: OldHashMap1[_, _] | _: OldHashSet1[_] => true
case _: OldHashMap1[?, ?] | _: OldHashSet1[?] => true
case _ => false
}

Expand All @@ -84,7 +84,7 @@ private[collection] abstract class TrieIterator[+T](elems: Array[Iterable[T]]) e
}

private[this] def iteratorWithSize(arr: Array[Iterable[T]]): (Iterator[T], Int) =
(newIterator(arr), ((arr.map(_.size): Array[Int]): scala.collection.IterableOps[Int, scala.collection.Iterable, _]).sum)
(newIterator(arr), ((arr.map(_.size): Array[Int]): scala.collection.IterableOps[Int, scala.collection.Iterable, ?]).sum)

private[this] def arrayToIterators(arr: Array[Iterable[T]]): SplitIterators = {
val (fst, snd) = arr.splitAt(arr.length / 2)
Expand All @@ -94,7 +94,7 @@ private[collection] abstract class TrieIterator[+T](elems: Array[Iterable[T]]) e
private[this] def splitArray(ad: Array[Iterable[T]]): SplitIterators =
if (ad.length > 1) arrayToIterators(ad)
else ad(0) match {
case _: OldHashMapCollision1[_, _] | _: OldHashSetCollision1[_] =>
case _: OldHashMapCollision1[?, ?] | _: OldHashSetCollision1[?] =>
arrayToIterators(collisionToArray(ad(0)))
case _ =>
splitArray(getElems(ad(0)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object CollectionConverters {
def seq = coll
override def par = coll match {
case coll: sc.Set[A @unchecked] => new SetIsParallelizable(coll).par
case coll: sc.Map[_, _] => new MapIsParallelizable(coll).par.asInstanceOf[ParIterable[A]]
case coll: sc.Map[?, ?] => new MapIsParallelizable(coll).par.asInstanceOf[ParIterable[A]]
case coll: sci.Iterable[A] => new ImmutableIterableIsParallelizable(coll).par
case coll: scm.Iterable[A @unchecked] => new MutableIterableIsParallelizable(coll).par
case _ => ParIterable.newCombiner[A].fromSequential(seq) // builds ParArray, same as for scm.Iterable
Expand All @@ -39,7 +39,7 @@ object CollectionConverters {
override def par = coll match {
case coll: scm.Seq[A] => new MutableSeqIsParallelizable(coll).par
case coll: scm.Set[A] => new MutableSetIsParallelizable(coll).par
case coll: scm.Map[_, _] => new MutableMapIsParallelizable(coll).par.asInstanceOf[mutable.ParIterable[A]]
case coll: scm.Map[?, ?] => new MutableMapIsParallelizable(coll).par.asInstanceOf[mutable.ParIterable[A]]
case _ => mutable.ParIterable.newCombiner[A].fromSequential(seq) // builds ParArray
}
}
Expand All @@ -49,7 +49,7 @@ object CollectionConverters {
override def par = coll match {
case coll: sci.Seq[A] => new ImmutableSeqIsParallelizable(coll).par
case coll: sci.Set[A @unchecked] => new ImmutableSetIsParallelizable(coll).par
case coll: sci.Map[_, _] => new ImmutableMapIsParallelizable(coll).par.asInstanceOf[immutable.ParIterable[A]]
case coll: sci.Map[?, ?] => new ImmutableMapIsParallelizable(coll).par.asInstanceOf[immutable.ParIterable[A]]
case _ => immutable.ParIterable.newCombiner[A].fromSequential(seq) // builds ParVector
}
}
Expand Down Expand Up @@ -85,7 +85,7 @@ object CollectionConverters {
implicit class ImmutableSeqIsParallelizable[A](private val coll: sci.Seq[A]) extends AnyVal with sc.CustomParallelizable[A, immutable.ParSeq[A]] {
def seq = coll
override def par = coll match {
case coll: sci.Vector[_] => new VectorIsParallelizable(coll.asInstanceOf[sci.Vector[A]]).par
case coll: sci.Vector[?] => new VectorIsParallelizable(coll.asInstanceOf[sci.Vector[A]]).par
case coll: sci.Range => new RangeIsParallelizable(coll).par.asInstanceOf[immutable.ParSeq[A]]
case _ => immutable.ParSeq.newCombiner[A].fromSequential(seq)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ extends IterableOnce[T @uncheckedVariance]
if (cb.getClass == t.runtimeClass) isbody(cb.asInstanceOf[Cmb]) else notbody
}
}
def isCombiner = cb.isInstanceOf[Combiner[_, _]]
def isCombiner = cb.isInstanceOf[Combiner[?, ?]]
def asCombiner = cb.asInstanceOf[Combiner[Elem, To]]
}

Expand Down Expand Up @@ -877,7 +877,7 @@ extends IterableOnce[T @uncheckedVariance]

protected[this] trait NonDivisible[R] extends NonDivisibleTask[R, NonDivisible[R]]

protected[this] abstract class Composite[FR, SR, R, First <: StrictSplitterCheckTask[FR, _], Second <: StrictSplitterCheckTask[SR, _]]
protected[this] abstract class Composite[FR, SR, R, First <: StrictSplitterCheckTask[FR, ?], Second <: StrictSplitterCheckTask[SR, ?]]
(val ft: First, val st: Second)
extends NonDivisibleTask[R, Composite[FR, SR, R, First, Second]] {
def combineResults(fr: FR, sr: SR): R
Expand All @@ -894,7 +894,7 @@ extends IterableOnce[T @uncheckedVariance]
}

/** Sequentially performs one task after another. */
protected[this] abstract class SeqComposite[FR, SR, R, First <: StrictSplitterCheckTask[FR, _], Second <: StrictSplitterCheckTask[SR, _]]
protected[this] abstract class SeqComposite[FR, SR, R, First <: StrictSplitterCheckTask[FR, ?], Second <: StrictSplitterCheckTask[SR, ?]]
(f: First, s: Second)
extends Composite[FR, SR, R, First, Second](f, s) {
def leaf(prevr: Option[R]) = {
Expand All @@ -905,7 +905,7 @@ extends IterableOnce[T @uncheckedVariance]
}

/** Performs two tasks in parallel, and waits for both to finish. */
protected[this] abstract class ParComposite[FR, SR, R, First <: StrictSplitterCheckTask[FR, _], Second <: StrictSplitterCheckTask[SR, _]]
protected[this] abstract class ParComposite[FR, SR, R, First <: StrictSplitterCheckTask[FR, ?], Second <: StrictSplitterCheckTask[SR, ?]]
(f: First, s: Second)
extends Composite[FR, SR, R, First, Second](f, s) {
def leaf(prevr: Option[R]) = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ self =>
* same mappings, `false` otherwise.
*/
override def equals(that: Any): Boolean = that match {
case that: ParMap[b, _] =>
case that: ParMap[b, ?] =>
(this eq that) ||
(that canEqual this) &&
(this.size == that.size) && {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ extends ParIterableLike[T, CC, Repr, Sequential]

/* tasks */

protected[this] def down(p: IterableSplitter[_]) = p.asInstanceOf[SeqSplitter[T]]
protected[this] def down(p: IterableSplitter[?]) = p.asInstanceOf[SeqSplitter[T]]

protected trait ParSeqLikeAccessor[R, Tp] extends Accessor[R, Tp] {
protected[this] val pit: SeqSplitter[T]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extends ParIterableLike[T, CC, Repr, Sequential]
* as this set.
*/
override def equals(that: Any): Boolean = that match {
case that: ParSet[_] =>
case that: ParSet[?] =>
(this eq that) ||
(that canEqual this) &&
(this.size == that.size) &&
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/scala/collection/parallel/Tasks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ trait Task[R, +Tp] {
mergeThrowables(that)
}

private[parallel] def mergeThrowables(that: Task[_, _]): Unit =
private[parallel] def mergeThrowables(that: Task[?, ?]): Unit =
if (this.throwable != null) {
if (that.throwable != null && (this.throwable ne that.throwable))
this.throwable.addSuppressed(that.throwable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,10 @@ extends scala.collection.parallel.BucketCombiner[(K, V), ParHashMap[K, V], (K, V
evaluateCombiners(trie).asInstanceOf[OldHashMap[K, Repr]]
}
private def evaluateCombiners(trie: OldHashMap[K, Combiner[V, Repr]]): OldHashMap[K, Repr] = trie match {
case hm1: OldHashMap.OldHashMap1[_, _] =>
case hm1: OldHashMap.OldHashMap1[?, ?] =>
val evaledvalue = hm1.value.result()
new OldHashMap.OldHashMap1[K, Repr](hm1.key, hm1.hash, evaledvalue, null)
case hmc: OldHashMap.OldHashMapCollision1[_, Combiner[_, Repr]] =>
case hmc: OldHashMap.OldHashMapCollision1[?, Combiner[?, Repr]] =>
val evaledkvs = hmc.kvs map { p => (p._1, p._2.result()) }
new OldHashMap.OldHashMapCollision1[K, Repr](hmc.hash, evaledkvs)
case htm: OldHashMap.HashTrieMap[k, v] =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ trait LazyCombiner[Elem, +To, Buff <: Growable[Elem] with Sizing] extends Combin
def result(): To = allocateAndCopy
def clear() = { chain.clear() }
def combine[N <: Elem, NewTo >: To](other: Combiner[N, NewTo]): Combiner[N, NewTo] = if (this ne other) {
if (other.isInstanceOf[LazyCombiner[_, _, _]]) {
if (other.isInstanceOf[LazyCombiner[?, ?, ?]]) {
val that = other.asInstanceOf[LazyCombiner[Elem, To, Buff]]
newLazyCombiner(chain ++= that.chain)
} else throw new UnsupportedOperationException("Cannot combine with combiner of different type.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ extends ParMap[K, V]
val in = ctrie.readRoot()
val r = in.gcasRead(ctrie)
(r: @unchecked) match {
case tn: TNode[_, _] => tn.cachedSize(ctrie)
case ln: LNode[_, _] => ln.cachedSize(ctrie)
case cn: CNode[_, _] =>
case tn: TNode[?, ?] => tn.cachedSize(ctrie)
case ln: LNode[?, ?] => ln.cachedSize(ctrie)
case cn: CNode[?, ?] =>
tasksupport.executeAndWaitResult(new Size(0, cn.array.length, cn.array))
cn.cachedSize(ctrie)
}
Expand All @@ -103,7 +103,7 @@ extends ParMap[K, V]
val until = offset + howmany
while (i < until) {
(array(i): @unchecked) match {
case sn: SNode[_, _] => sz += 1
case sn: SNode[?, ?] => sz += 1
case in: INode[K @unchecked, V @unchecked] => sz += in.cachedSize(ctrie)
}
i += 1
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/scala/scala/collection/parallel/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ package object parallel {

def setTaskSupport[Coll](c: Coll, t: TaskSupport): Coll = {
c match {
case pc: ParIterableLike[_, _, _, _] => pc.tasksupport = t
case pc: ParIterableLike[?, ?, ?, ?] => pc.tasksupport = t
case _ => // do nothing
}
c
Expand All @@ -50,7 +50,7 @@ package object parallel {
implicit class CollectionsHaveToParArray[C, T](c: C)(implicit asGto: C => scala.collection.IterableOnce[T]) {
def toParArray = {
val t = asGto(c)
if (t.isInstanceOf[ParArray[_]]) t.asInstanceOf[ParArray[T]]
if (t.isInstanceOf[ParArray[?]]) t.asInstanceOf[ParArray[T]]
else {
val it = t.iterator
val cb = mutable.ParArrayCombiner[T]()
Expand All @@ -67,9 +67,9 @@ package parallel {
private[collection] object ParallelCollectionImplicits {
implicit def traversable2ops[T](t: scala.collection.IterableOnce[T]): TraversableOps[T] = new TraversableOps[T] {
def isParallel = t.isInstanceOf[Parallel]
def isParIterable = t.isInstanceOf[ParIterable[_]]
def isParIterable = t.isInstanceOf[ParIterable[?]]
def asParIterable = t.asInstanceOf[ParIterable[T]]
def isParSeq = t.isInstanceOf[ParSeq[_]]
def isParSeq = t.isInstanceOf[ParSeq[?]]
def asParSeq = t.asInstanceOf[ParSeq[T]]
def ifParSeq[R](isbody: ParSeq[T] => R) = new Otherwise[R] {
def otherwise(notbody: => R) = if (isParallel) isbody(asParSeq) else notbody
Expand Down Expand Up @@ -184,7 +184,7 @@ package parallel {
def combine[N <: Elem, NewTo >: To](other: Combiner[N, NewTo]): Combiner[N, NewTo] = {
if (this eq other) this
else other match {
case _: BucketCombiner[_, _, _, _] =>
case _: BucketCombiner[?, ?, ?, ?] =>
beforeCombine(other)
val that = other.asInstanceOf[BucketCombiner[Elem, To, Buck, CombinerType]]

Expand Down
6 changes: 3 additions & 3 deletions junit/src/test/scala/MiscTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MiscTest {
}
}

def foo(arg: ParSeq[_]): String = arg.map(x => x).mkString(",")
def foo(arg: ParSeq[?]): String = arg.map(x => x).mkString(",")

@Test
def si4608: Unit = {
Expand Down Expand Up @@ -113,9 +113,9 @@ class MiscTest {
@Test
def si6510: Unit = {
val x = collection.parallel.mutable.ParArray.range(1,10) groupBy { _ % 2 } mapValues { _.size }
assertTrue(x.isInstanceOf[parallel.ParMap[_, _]])
assertTrue(x.isInstanceOf[parallel.ParMap[?, ?]])
val y = collection.parallel.immutable.ParVector.range(1,10) groupBy { _ % 2 } mapValues { _.size }
assertTrue(y.isInstanceOf[parallel.ParMap[_, _]])
assertTrue(y.isInstanceOf[parallel.ParMap[?, ?]])
}

@Test
Expand Down

0 comments on commit c664f6d

Please sign in to comment.