Skip to content

Commit

Permalink
prepare for Dotty: replace existentials with explicit type parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
SethTisue committed Oct 15, 2020
1 parent d1b977f commit dac0f8c
Show file tree
Hide file tree
Showing 22 changed files with 37 additions and 42 deletions.
6 changes: 3 additions & 3 deletions core/src/main/scala/scala/collection/generic/ParFactory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ extends GenericParCompanion[CC] {
* all calls to `apply(from)` to the `genericParBuilder` method of the $coll
* `from`, and calls to `apply()` to this factory.
*/
class GenericCanCombineFrom[A] extends CanCombineFrom[CC[_], A, CC[A]] {
override def apply(from: CC[_]) = from.genericCombiner
override def apply() = newBuilder[A]
class GenericCanCombineFrom[From, To] extends CanCombineFrom[CC[From], To, CC[To]] {
override def apply(from: CC[From]) = from.genericCombiner
override def apply() = newBuilder[To]
}
}
10 changes: 3 additions & 7 deletions core/src/main/scala/scala/collection/generic/ParMapFactory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ import scala.collection.parallel.Combiner
* @define factoryInfo
* This object provides a set of operations needed to create `$Coll` values.
*/
abstract class ParMapFactory[CC[X, Y] <: ParMap[X, Y] with ParMapLike[X, Y, CC, CC[X, Y], _]]
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]]]
extends GenericParMapCompanion[CC] {

type Coll = MapColl

// `apply` and `empty` methods were previously inherited from `GenMapFactory`, which
// has been removed from the Scala library in 2.13

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

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

type MapColl = CC[_, _]

/** The default builder for $Coll objects.
* @tparam K the type of the keys
* @tparam V the type of the associated values
Expand All @@ -59,8 +55,8 @@ extends GenericParMapCompanion[CC] {
*/
def newCombiner[K, V]: Combiner[(K, V), CC[K, V]]

class CanCombineFromMap[K, V] extends CanCombineFrom[CC[_, _], (K, V), CC[K, V]] {
def apply(from: MapColl) = from.genericMapCombiner[K, V].asInstanceOf[Combiner[(K, V), CC[K, V]]]
class CanCombineFromMap[FromK, FromV, K, V] extends CanCombineFrom[CC[FromK, FromV], (K, V), CC[K, V]] {
def apply(from: CC[FromK, FromV]) = from.genericMapCombiner[K, V].asInstanceOf[Combiner[(K, V), CC[K, V]]]
def apply() = newCombiner[K, V]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ abstract class ParSetFactory[CC[X] <: ParSet[X] with ParSetLike[X, CC, CC[X], _]

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

class GenericCanCombineFrom[A] extends CanCombineFrom[CC[_], A, CC[A]] {
override def apply(from: CC[_]) = from.genericCombiner[A]
class GenericCanCombineFrom[B, A] extends CanCombineFrom[CC[B], A, CC[A]] {
override def apply(from: CC[B]) = from.genericCombiner[A]
override def apply() = newCombiner[A]
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ trait ParIterable[+T]
/** $factoryInfo
*/
object ParIterable extends ParFactory[ParIterable] {
implicit def canBuildFrom[T]: CanCombineFrom[ParIterable[_], T, ParIterable[T]] = new GenericCanCombineFrom[T]
implicit def canBuildFrom[T, S]: CanCombineFrom[ParIterable[S], T, ParIterable[T]] = new GenericCanCombineFrom[S, T]

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

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/scala/collection/parallel/ParMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ self =>



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

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

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

/** An abstract shell used by { mutable, immutable }.Map but not by collection.Map
* because of variance issues.
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/scala/collection/parallel/ParSeq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ trait ParSeq[+T] extends ParIterable[T]
}

object ParSeq extends ParFactory[ParSeq] {
implicit def canBuildFrom[T]: CanCombineFrom[ParSeq[_], T, ParSeq[T]] = new GenericCanCombineFrom[T]
implicit def canBuildFrom[S, T]: CanCombineFrom[ParSeq[S], T, ParSeq[T]] = new GenericCanCombineFrom[S, T]

def newBuilder[T]: Combiner[T, ParSeq[T]] = ParArrayCombiner[T]()
def newCombiner[T]: Combiner[T, ParSeq[T]] = ParArrayCombiner[T]()
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/scala/collection/parallel/ParSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ trait ParSet[T]
object ParSet extends ParSetFactory[ParSet] {
def newCombiner[T]: Combiner[T, ParSet[T]] = mutable.ParHashSetCombiner[T]

implicit def canBuildFrom[T]: CanCombineFrom[ParSet[_], T, ParSet[T]] = new GenericCanCombineFrom[T]
implicit def canBuildFrom[S, T]: CanCombineFrom[ParSet[S], T, ParSet[T]] = new GenericCanCombineFrom[S, T]
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ self =>
* @define Coll `immutable.ParHashMap`
* @define coll immutable parallel hash map
*/
object ParHashMap extends ParMapFactory[ParHashMap] {
object ParHashMap extends ParMapFactory[ParHashMap, OldHashMap] {
def empty[K, V]: ParHashMap[K, V] = new ParHashMap[K, V]

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

implicit def canBuildFrom[K, V]: CanCombineFrom[Coll, (K, V), ParHashMap[K, V]] = {
new CanCombineFromMap[K, V]
implicit def canBuildFrom[FromK, FromV, K, V]: CanCombineFrom[ParHashMap[FromK, FromV], (K, V), ParHashMap[K, V]] = {
new CanCombineFromMap[FromK, FromV, K, V]
}

def fromTrie[K, V](t: OldHashMap[K, V]) = new ParHashMap(t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ self =>
object ParHashSet extends ParSetFactory[ParHashSet] {
def newCombiner[T]: Combiner[T, ParHashSet[T]] = HashSetCombiner[T]

implicit def canBuildFrom[T]: CanCombineFrom[ParHashSet[_], T, ParHashSet[T]] =
new GenericCanCombineFrom[T]
implicit def canBuildFrom[S, T]: CanCombineFrom[ParHashSet[S], T, ParHashSet[T]] =
new GenericCanCombineFrom[S, T]

def fromTrie[T](t: OldHashSet[T]) = new ParHashSet(t)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ extends scala.collection.parallel.ParIterable[T]
/** $factoryInfo
*/
object ParIterable extends ParFactory[ParIterable] {
implicit def canBuildFrom[T]: CanCombineFrom[ParIterable[_], T, ParIterable[T]] =
new GenericCanCombineFrom[T]
implicit def canBuildFrom[S, T]: CanCombineFrom[ParIterable[S], T, ParIterable[T]] =
new GenericCanCombineFrom[S, T]

def newBuilder[T]: Combiner[T, ParIterable[T]] = ParVector.newBuilder[T]
def newCombiner[T]: Combiner[T, ParIterable[T]] = ParVector.newCombiner[T]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ trait ParMapLike[



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

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

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

class WithDefault[K, +V](underlying: ParMap[K, V], d: K => V)
extends scala.collection.parallel.ParMap.WithDefault[K, V](underlying, d) with ParMap[K, V] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extends scala.collection.parallel.ParSeq[T]
* @define coll mutable parallel sequence
*/
object ParSeq extends ParFactory[ParSeq] {
implicit def canBuildFrom[T]: CanCombineFrom[ParSeq[_], T, ParSeq[T]] = new GenericCanCombineFrom[T]
implicit def canBuildFrom[S, T]: CanCombineFrom[ParSeq[S], T, ParSeq[T]] = new GenericCanCombineFrom[S, T]

def newBuilder[T]: Combiner[T, ParSeq[T]] = ParVector.newBuilder[T]
def newCombiner[T]: Combiner[T, ParSeq[T]] = ParVector.newCombiner[T]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ self =>
object ParSet extends ParSetFactory[ParSet] {
def newCombiner[T]: Combiner[T, ParSet[T]] = HashSetCombiner[T]

implicit def canBuildFrom[T]: CanCombineFrom[ParSet[_], T, ParSet[T]] = new GenericCanCombineFrom[T]
implicit def canBuildFrom[S, T]: CanCombineFrom[ParSet[S], T, ParSet[T]] = new GenericCanCombineFrom[S, T]
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ extends ParSeq[T]
* @define coll immutable parallel vector
*/
object ParVector extends ParFactory[ParVector] {
implicit def canBuildFrom[T]: CanCombineFrom[ParVector[_], T, ParVector[T]] =
new GenericCanCombineFrom[T]
implicit def canBuildFrom[S, T]: CanCombineFrom[ParVector[S], T, ParVector[T]] =
new GenericCanCombineFrom[S, T]

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ self =>
* @define coll parallel array
*/
object ParArray extends ParFactory[ParArray] {
implicit def canBuildFrom[T]: CanCombineFrom[ParArray[_], T, ParArray[T]] = new GenericCanCombineFrom[T]
implicit def canBuildFrom[S, T]: CanCombineFrom[ParArray[S], T, ParArray[T]] = new GenericCanCombineFrom[S, T]
def newBuilder[T]: Combiner[T, ParArray[T]] = newCombiner
def newCombiner[T]: Combiner[T, ParArray[T]] = ParArrayCombiner[T]()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ self =>
* @define Coll `mutable.ParHashMap`
* @define coll parallel hash map
*/
object ParHashMap extends ParMapFactory[ParHashMap] {
object ParHashMap extends ParMapFactory[ParHashMap, scala.collection.mutable.HashMap] {
var iters = 0

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

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

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

final class DefaultEntry[K, V](val key: K, var value: V) extends HashEntry[K, DefaultEntry[K, V]] with Serializable {
override def toString: String = s"DefaultEntry($key -> $value)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ extends ParSet[T]
* @define coll parallel hash set
*/
object ParHashSet extends ParSetFactory[ParHashSet] {
implicit def canBuildFrom[T]: CanCombineFrom[ParHashSet[_], T, ParHashSet[T]] = new GenericCanCombineFrom[T]
implicit def canBuildFrom[S, T]: CanCombineFrom[ParHashSet[S], T, ParHashSet[T]] = new GenericCanCombineFrom[S, T]

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ trait ParIterable[T] extends scala.collection.parallel.ParIterable[T]
/** $factoryInfo
*/
object ParIterable extends ParFactory[ParIterable] {
implicit def canBuildFrom[T]: CanCombineFrom[ParIterable[_], T, ParIterable[T]] = new GenericCanCombineFrom[T]
implicit def canBuildFrom[S, T]: CanCombineFrom[ParIterable[S], T, ParIterable[T]] = new GenericCanCombineFrom[S, T]

def newBuilder[T]: Combiner[T, ParIterable[T]] = ParArrayCombiner[T]()
def newCombiner[T]: Combiner[T, ParIterable[T]] = ParArrayCombiner[T]()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ extends parallel.ParMap[K, V]
def withDefaultValue(d: V): scala.collection.parallel.mutable.ParMap[K, V] = new ParMap.WithDefault[K, V](this, x => d)
}

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

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

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

class WithDefault[K, V](underlying: ParMap[K, V], d: K => V)
extends scala.collection.parallel.ParMap.WithDefault(underlying, d) with ParMap[K, V] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ self =>
* @define coll mutable parallel sequence
*/
object ParSeq extends ParFactory[ParSeq] {
implicit def canBuildFrom[T]: CanCombineFrom[ParSeq[_], T, ParSeq[T]] = new GenericCanCombineFrom[T]
implicit def canBuildFrom[S, T]: CanCombineFrom[ParSeq[S], T, ParSeq[T]] = new GenericCanCombineFrom[S, T]

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ self =>
* @define coll mutable parallel set
*/
object ParSet extends ParSetFactory[ParSet] {
implicit def canBuildFrom[T]: CanCombineFrom[ParSet[_], T, ParSet[T]] = new GenericCanCombineFrom[T]
implicit def canBuildFrom[S, T]: CanCombineFrom[ParSet[S], T, ParSet[T]] = new GenericCanCombineFrom[S, T]

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ private[mutable] trait ParTrieMapCombiner[K, V] extends Combiner[(K, V), ParTrie
override def canBeShared = true
}

object ParTrieMap extends ParMapFactory[ParTrieMap] {
object ParTrieMap extends ParMapFactory[ParTrieMap, TrieMap] {
def empty[K, V]: ParTrieMap[K, V] = new ParTrieMap[K, V]
def newCombiner[K, V]: Combiner[(K, V), ParTrieMap[K, V]] = new ParTrieMap[K, V]

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

0 comments on commit dac0f8c

Please sign in to comment.