Skip to content

Commit 6a2972c

Browse files
committed
wip: replace existentials by adding type parameters
1 parent a978a50 commit 6a2972c

22 files changed

+37
-42
lines changed

core/src/main/scala/scala/collection/generic/ParFactory.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ extends GenericParCompanion[CC] {
225225
* all calls to `apply(from)` to the `genericParBuilder` method of the $coll
226226
* `from`, and calls to `apply()` to this factory.
227227
*/
228-
class GenericCanCombineFrom[A] extends CanCombineFrom[CC[_], A, CC[A]] {
229-
override def apply(from: CC[_]) = from.genericCombiner
230-
override def apply() = newBuilder[A]
228+
class GenericCanCombineFrom[From, To] extends CanCombineFrom[CC[From], To, CC[To]] {
229+
override def apply(from: CC[From]) = from.genericCombiner
230+
override def apply() = newBuilder[To]
231231
}
232232
}

core/src/main/scala/scala/collection/generic/ParMapFactory.scala

+3-7
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ import scala.collection.parallel.Combiner
2727
* @define factoryInfo
2828
* This object provides a set of operations needed to create `$Coll` values.
2929
*/
30-
abstract class ParMapFactory[CC[X, Y] <: ParMap[X, Y] with ParMapLike[X, Y, CC, CC[X, Y], _]]
30+
abstract class ParMapFactory[CC[X, Y] <: ParMap[X, Y] with ParMapLike[X, Y, CC, CC[X, Y], Sequential[X, Y]], Sequential[X, Y] <: collection.Map[X, Y] with collection.MapOps[X, Y, Sequential, Sequential[X, Y]]]
3131
extends GenericParMapCompanion[CC] {
3232

33-
type Coll = MapColl
34-
3533
// `apply` and `empty` methods were previously inherited from `GenMapFactory`, which
3634
// has been removed from the Scala library in 2.13
3735

@@ -45,8 +43,6 @@ extends GenericParMapCompanion[CC] {
4543

4644
def empty[K, V]: CC[K, V]
4745

48-
type MapColl = CC[_, _]
49-
5046
/** The default builder for $Coll objects.
5147
* @tparam K the type of the keys
5248
* @tparam V the type of the associated values
@@ -59,8 +55,8 @@ extends GenericParMapCompanion[CC] {
5955
*/
6056
def newCombiner[K, V]: Combiner[(K, V), CC[K, V]]
6157

62-
class CanCombineFromMap[K, V] extends CanCombineFrom[CC[_, _], (K, V), CC[K, V]] {
63-
def apply(from: MapColl) = from.genericMapCombiner[K, V].asInstanceOf[Combiner[(K, V), CC[K, V]]]
58+
class CanCombineFromMap[FromK, FromV, K, V] extends CanCombineFrom[CC[FromK, FromV], (K, V), CC[K, V]] {
59+
def apply(from: CC[FromK, FromV]) = from.genericMapCombiner[K, V].asInstanceOf[Combiner[(K, V), CC[K, V]]]
6460
def apply() = newCombiner[K, V]
6561
}
6662

core/src/main/scala/scala/collection/generic/ParSetFactory.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ abstract class ParSetFactory[CC[X] <: ParSet[X] with ParSetLike[X, CC, CC[X], _]
2828

2929
def newCombiner[A]: Combiner[A, CC[A]]
3030

31-
class GenericCanCombineFrom[A] extends CanCombineFrom[CC[_], A, CC[A]] {
32-
override def apply(from: CC[_]) = from.genericCombiner[A]
31+
class GenericCanCombineFrom[B, A] extends CanCombineFrom[CC[B], A, CC[A]] {
32+
override def apply(from: CC[B]) = from.genericCombiner[A]
3333
override def apply() = newCombiner[A]
3434
}
3535
}
36-

core/src/main/scala/scala/collection/parallel/ParIterable.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ trait ParIterable[+T]
3535
/** $factoryInfo
3636
*/
3737
object ParIterable extends ParFactory[ParIterable] {
38-
implicit def canBuildFrom[T]: CanCombineFrom[ParIterable[_], T, ParIterable[T]] = new GenericCanCombineFrom[T]
38+
implicit def canBuildFrom[T, S]: CanCombineFrom[ParIterable[S], T, ParIterable[T]] = new GenericCanCombineFrom[S, T]
3939

4040
def newBuilder[T]: Combiner[T, ParIterable[T]] = ParArrayCombiner[T]()
4141

core/src/main/scala/scala/collection/parallel/ParMap.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ self =>
4545

4646

4747

48-
object ParMap extends ParMapFactory[ParMap] {
48+
object ParMap extends ParMapFactory[ParMap, collection.Map] {
4949
def empty[K, V]: ParMap[K, V] = new mutable.ParHashMap[K, V]
5050

5151
def newCombiner[K, V]: Combiner[(K, V), ParMap[K, V]] = mutable.ParHashMapCombiner[K, V]
5252

53-
implicit def canBuildFrom[K, V]: CanCombineFrom[Coll, (K, V), ParMap[K, V]] = new CanCombineFromMap[K, V]
53+
implicit def canBuildFrom[FromK, FromV, K, V]: CanCombineFrom[ParMap[FromK, FromV], (K, V), ParMap[K, V]] = new CanCombineFromMap[FromK, FromV, K, V]
5454

5555
/** An abstract shell used by { mutable, immutable }.Map but not by collection.Map
5656
* because of variance issues.

core/src/main/scala/scala/collection/parallel/ParSeq.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ trait ParSeq[+T] extends ParIterable[T]
4242
}
4343

4444
object ParSeq extends ParFactory[ParSeq] {
45-
implicit def canBuildFrom[T]: CanCombineFrom[ParSeq[_], T, ParSeq[T]] = new GenericCanCombineFrom[T]
45+
implicit def canBuildFrom[S, T]: CanCombineFrom[ParSeq[S], T, ParSeq[T]] = new GenericCanCombineFrom[S, T]
4646

4747
def newBuilder[T]: Combiner[T, ParSeq[T]] = ParArrayCombiner[T]()
4848
def newCombiner[T]: Combiner[T, ParSeq[T]] = ParArrayCombiner[T]()

core/src/main/scala/scala/collection/parallel/ParSet.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ trait ParSet[T]
4040
object ParSet extends ParSetFactory[ParSet] {
4141
def newCombiner[T]: Combiner[T, ParSet[T]] = mutable.ParHashSetCombiner[T]
4242

43-
implicit def canBuildFrom[T]: CanCombineFrom[ParSet[_], T, ParSet[T]] = new GenericCanCombineFrom[T]
43+
implicit def canBuildFrom[S, T]: CanCombineFrom[ParSet[S], T, ParSet[T]] = new GenericCanCombineFrom[S, T]
4444
}

core/src/main/scala/scala/collection/parallel/immutable/ParHashMap.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ self =>
140140
* @define Coll `immutable.ParHashMap`
141141
* @define coll immutable parallel hash map
142142
*/
143-
object ParHashMap extends ParMapFactory[ParHashMap] {
143+
object ParHashMap extends ParMapFactory[ParHashMap, OldHashMap] {
144144
def empty[K, V]: ParHashMap[K, V] = new ParHashMap[K, V]
145145

146146
def newCombiner[K, V]: Combiner[(K, V), ParHashMap[K, V]] = HashMapCombiner[K, V]
147147

148-
implicit def canBuildFrom[K, V]: CanCombineFrom[Coll, (K, V), ParHashMap[K, V]] = {
149-
new CanCombineFromMap[K, V]
148+
implicit def canBuildFrom[FromK, FromV, K, V]: CanCombineFrom[ParHashMap[FromK, FromV], (K, V), ParHashMap[K, V]] = {
149+
new CanCombineFromMap[FromK, FromV, K, V]
150150
}
151151

152152
def fromTrie[K, V](t: OldHashMap[K, V]) = new ParHashMap(t)

core/src/main/scala/scala/collection/parallel/immutable/ParHashSet.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ self =>
125125
object ParHashSet extends ParSetFactory[ParHashSet] {
126126
def newCombiner[T]: Combiner[T, ParHashSet[T]] = HashSetCombiner[T]
127127

128-
implicit def canBuildFrom[T]: CanCombineFrom[ParHashSet[_], T, ParHashSet[T]] =
129-
new GenericCanCombineFrom[T]
128+
implicit def canBuildFrom[S, T]: CanCombineFrom[ParHashSet[S], T, ParHashSet[T]] =
129+
new GenericCanCombineFrom[S, T]
130130

131131
def fromTrie[T](t: OldHashSet[T]) = new ParHashSet(t)
132132
}

core/src/main/scala/scala/collection/parallel/immutable/ParIterable.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ extends scala.collection.parallel.ParIterable[T]
4040
/** $factoryInfo
4141
*/
4242
object ParIterable extends ParFactory[ParIterable] {
43-
implicit def canBuildFrom[T]: CanCombineFrom[ParIterable[_], T, ParIterable[T]] =
44-
new GenericCanCombineFrom[T]
43+
implicit def canBuildFrom[S, T]: CanCombineFrom[ParIterable[S], T, ParIterable[T]] =
44+
new GenericCanCombineFrom[S, T]
4545

4646
def newBuilder[T]: Combiner[T, ParIterable[T]] = ParVector.newBuilder[T]
4747
def newCombiner[T]: Combiner[T, ParIterable[T]] = ParVector.newCombiner[T]

core/src/main/scala/scala/collection/parallel/immutable/ParMap.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ trait ParMapLike[
8888

8989

9090

91-
object ParMap extends ParMapFactory[ParMap] {
91+
object ParMap extends ParMapFactory[ParMap, scala.collection.immutable.Map] {
9292
def empty[K, V]: ParMap[K, V] = new ParHashMap[K, V]
9393

9494
def newCombiner[K, V]: Combiner[(K, V), ParMap[K, V]] = HashMapCombiner[K, V]
9595

96-
implicit def canBuildFrom[K, V]: CanCombineFrom[Coll, (K, V), ParMap[K, V]] = new CanCombineFromMap[K, V]
96+
implicit def canBuildFrom[FromK, FromV, K, V]: CanCombineFrom[ParMap[FromK, FromV], (K, V), ParMap[K, V]] = new CanCombineFromMap[FromK, FromV, K, V]
9797

9898
class WithDefault[K, +V](underlying: ParMap[K, V], d: K => V)
9999
extends scala.collection.parallel.ParMap.WithDefault[K, V](underlying, d) with ParMap[K, V] {

core/src/main/scala/scala/collection/parallel/immutable/ParSeq.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extends scala.collection.parallel.ParSeq[T]
3838
* @define coll mutable parallel sequence
3939
*/
4040
object ParSeq extends ParFactory[ParSeq] {
41-
implicit def canBuildFrom[T]: CanCombineFrom[ParSeq[_], T, ParSeq[T]] = new GenericCanCombineFrom[T]
41+
implicit def canBuildFrom[S, T]: CanCombineFrom[ParSeq[S], T, ParSeq[T]] = new GenericCanCombineFrom[S, T]
4242

4343
def newBuilder[T]: Combiner[T, ParSeq[T]] = ParVector.newBuilder[T]
4444
def newCombiner[T]: Combiner[T, ParSeq[T]] = ParVector.newCombiner[T]

core/src/main/scala/scala/collection/parallel/immutable/ParSet.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ self =>
4747
object ParSet extends ParSetFactory[ParSet] {
4848
def newCombiner[T]: Combiner[T, ParSet[T]] = HashSetCombiner[T]
4949

50-
implicit def canBuildFrom[T]: CanCombineFrom[ParSet[_], T, ParSet[T]] = new GenericCanCombineFrom[T]
50+
implicit def canBuildFrom[S, T]: CanCombineFrom[ParSet[S], T, ParSet[T]] = new GenericCanCombineFrom[S, T]
5151
}

core/src/main/scala/scala/collection/parallel/immutable/ParVector.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ extends ParSeq[T]
9292
* @define coll immutable parallel vector
9393
*/
9494
object ParVector extends ParFactory[ParVector] {
95-
implicit def canBuildFrom[T]: CanCombineFrom[ParVector[_], T, ParVector[T]] =
96-
new GenericCanCombineFrom[T]
95+
implicit def canBuildFrom[S, T]: CanCombineFrom[ParVector[S], T, ParVector[T]] =
96+
new GenericCanCombineFrom[S, T]
9797

9898
def newBuilder[T]: Combiner[T, ParVector[T]] = newCombiner[T]
9999

core/src/main/scala/scala/collection/parallel/mutable/ParArray.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ self =>
689689
* @define coll parallel array
690690
*/
691691
object ParArray extends ParFactory[ParArray] {
692-
implicit def canBuildFrom[T]: CanCombineFrom[ParArray[_], T, ParArray[T]] = new GenericCanCombineFrom[T]
692+
implicit def canBuildFrom[S, T]: CanCombineFrom[ParArray[S], T, ParArray[T]] = new GenericCanCombineFrom[S, T]
693693
def newBuilder[T]: Combiner[T, ParArray[T]] = newCombiner
694694
def newCombiner[T]: Combiner[T, ParArray[T]] = ParArrayCombiner[T]()
695695

core/src/main/scala/scala/collection/parallel/mutable/ParHashMap.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ self =>
150150
* @define Coll `mutable.ParHashMap`
151151
* @define coll parallel hash map
152152
*/
153-
object ParHashMap extends ParMapFactory[ParHashMap] {
153+
object ParHashMap extends ParMapFactory[ParHashMap, scala.collection.mutable.HashMap] {
154154
var iters = 0
155155

156156
def empty[K, V]: ParHashMap[K, V] = new ParHashMap[K, V]
157157

158158
def newCombiner[K, V]: Combiner[(K, V), ParHashMap[K, V]] = ParHashMapCombiner.apply[K, V]
159159

160-
implicit def canBuildFrom[K, V]: CanCombineFrom[Coll, (K, V), ParHashMap[K, V]] = new CanCombineFromMap[K, V]
160+
implicit def canBuildFrom[FromK, FromV, K, V]: CanCombineFrom[ParHashMap[FromK, FromV], (K, V), ParHashMap[K, V]] = new CanCombineFromMap[FromK, FromV, K, V]
161161

162162
final class DefaultEntry[K, V](val key: K, var value: V) extends HashEntry[K, DefaultEntry[K, V]] with Serializable {
163163
override def toString: String = s"DefaultEntry($key -> $value)"

core/src/main/scala/scala/collection/parallel/mutable/ParHashSet.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ extends ParSet[T]
113113
* @define coll parallel hash set
114114
*/
115115
object ParHashSet extends ParSetFactory[ParHashSet] {
116-
implicit def canBuildFrom[T]: CanCombineFrom[ParHashSet[_], T, ParHashSet[T]] = new GenericCanCombineFrom[T]
116+
implicit def canBuildFrom[S, T]: CanCombineFrom[ParHashSet[S], T, ParHashSet[T]] = new GenericCanCombineFrom[S, T]
117117

118118
override def newBuilder[T]: Combiner[T, ParHashSet[T]] = newCombiner
119119

core/src/main/scala/scala/collection/parallel/mutable/ParIterable.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ trait ParIterable[T] extends scala.collection.parallel.ParIterable[T]
4242
/** $factoryInfo
4343
*/
4444
object ParIterable extends ParFactory[ParIterable] {
45-
implicit def canBuildFrom[T]: CanCombineFrom[ParIterable[_], T, ParIterable[T]] = new GenericCanCombineFrom[T]
45+
implicit def canBuildFrom[S, T]: CanCombineFrom[ParIterable[S], T, ParIterable[T]] = new GenericCanCombineFrom[S, T]
4646

4747
def newBuilder[T]: Combiner[T, ParIterable[T]] = ParArrayCombiner[T]()
4848
def newCombiner[T]: Combiner[T, ParIterable[T]] = ParArrayCombiner[T]()

core/src/main/scala/scala/collection/parallel/mutable/ParMap.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ extends parallel.ParMap[K, V]
6060
def withDefaultValue(d: V): scala.collection.parallel.mutable.ParMap[K, V] = new ParMap.WithDefault[K, V](this, x => d)
6161
}
6262

63-
object ParMap extends ParMapFactory[ParMap] {
63+
object ParMap extends ParMapFactory[ParMap, scala.collection.mutable.Map] {
6464
def empty[K, V]: ParMap[K, V] = new ParHashMap[K, V]
6565

6666
def newCombiner[K, V]: Combiner[(K, V), ParMap[K, V]] = ParHashMapCombiner.apply[K, V]
6767

68-
implicit def canBuildFrom[K, V]: CanCombineFrom[Coll, (K, V), ParMap[K, V]] = new CanCombineFromMap[K, V]
68+
implicit def canBuildFrom[FromK, FromV, K, V]: CanCombineFrom[ParMap[FromK, FromV], (K, V), ParMap[K, V]] = new CanCombineFromMap[FromK, FromV, K, V]
6969

7070
class WithDefault[K, V](underlying: ParMap[K, V], d: K => V)
7171
extends scala.collection.parallel.ParMap.WithDefault(underlying, d) with ParMap[K, V] {

core/src/main/scala/scala/collection/parallel/mutable/ParSeq.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ self =>
4646
* @define coll mutable parallel sequence
4747
*/
4848
object ParSeq extends ParFactory[ParSeq] {
49-
implicit def canBuildFrom[T]: CanCombineFrom[ParSeq[_], T, ParSeq[T]] = new GenericCanCombineFrom[T]
49+
implicit def canBuildFrom[S, T]: CanCombineFrom[ParSeq[S], T, ParSeq[T]] = new GenericCanCombineFrom[S, T]
5050

5151
def newBuilder[T]: Combiner[T, ParSeq[T]] = ParArrayCombiner[T]()
5252

core/src/main/scala/scala/collection/parallel/mutable/ParSet.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ self =>
3737
* @define coll mutable parallel set
3838
*/
3939
object ParSet extends ParSetFactory[ParSet] {
40-
implicit def canBuildFrom[T]: CanCombineFrom[ParSet[_], T, ParSet[T]] = new GenericCanCombineFrom[T]
40+
implicit def canBuildFrom[S, T]: CanCombineFrom[ParSet[S], T, ParSet[T]] = new GenericCanCombineFrom[S, T]
4141

4242
override def newBuilder[T]: Combiner[T, ParSet[T]] = ParHashSet.newBuilder
4343

core/src/main/scala/scala/collection/parallel/mutable/ParTrieMap.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ private[mutable] trait ParTrieMapCombiner[K, V] extends Combiner[(K, V), ParTrie
163163
override def canBeShared = true
164164
}
165165

166-
object ParTrieMap extends ParMapFactory[ParTrieMap] {
166+
object ParTrieMap extends ParMapFactory[ParTrieMap, TrieMap] {
167167
def empty[K, V]: ParTrieMap[K, V] = new ParTrieMap[K, V]
168168
def newCombiner[K, V]: Combiner[(K, V), ParTrieMap[K, V]] = new ParTrieMap[K, V]
169169

170-
implicit def canBuildFrom[K, V]: CanCombineFrom[Coll, (K, V), ParTrieMap[K, V]] = new CanCombineFromMap[K, V]
170+
implicit def canBuildFrom[FromK, FromV, K, V]: CanCombineFrom[ParTrieMap[FromK, FromV], (K, V), ParTrieMap[K, V]] = new CanCombineFromMap[FromK, FromV, K, V]
171171
}

0 commit comments

Comments
 (0)