Skip to content

Commit

Permalink
Prepare for Scala 2.13.0-RC1
Browse files Browse the repository at this point in the history
- Old code from scala.collection.generic package has been imported
  from the 2.12.x branch.
- Make ParIterableLike extend IterableOnce
- Operations that used to take GenIterable collections as parameter
  now have two overloads, one taking a ParIterable and another taking
  an Iterable
- VectorIterator has been deprecated, which is unfortunate because it is
  used for implementing ParVector. As a consequence, we now get a
  deprecation warning when we compile the project
- Inline GenTraversableFactory and GenericCompanion from scala/scala
- Move the contents that was previously in GenericCompanion into the
  GenericParCompanion trait
- Remove ParallelConsistencyTest, which does not make sense anymore
  since sequential collection don’t take “generic” collections as
  parameter.
- Move ExposedArraySeq logic to ParArray.
- Parallel collections are not anymore comparable with sequential
  collections. Tests systematically replace `==` with `sameElements`.
- Add support for the `to` conversion method in both directions
  (sequential to parallel and parallel to sequential).
  `toSeq`, `toIterable`, `toSet` and `toMap` used to be overridden
  to return parallel collections. I’ve kept that choice (although
  that makes it impossible to inherit from `IterableOnceOps`, then).
- Restore usage of DoublingUnrolledBuffer
- Restore FlatHashTable from scala/scala@9008c2f.
  Systematically use `areEqual` in tests with no strict order.
- Implementation of the sequential Set returned by the `seq` member has
  been copied from scala/scala@056e1e9.
  • Loading branch information
julienrf committed Jan 18, 2019
1 parent 8766788 commit 8da0743
Show file tree
Hide file tree
Showing 83 changed files with 4,344 additions and 1,066 deletions.
6 changes: 4 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import ScalaModulePlugin._

version in ThisBuild := "0.1.3-SNAPSHOT"

resolvers in ThisBuild += "scala-integration" at "https://scala-ci.typesafe.com/artifactory/scala-integration/"

scalaVersionsByJvm in ThisBuild := {
val v213 = "2.13.0-M3"
val v213 = "2.13.0-pre-021a9a4"
Map(
8 -> List(v213 -> true),
11 -> List(v213 -> false))
}

scalacOptions in ThisBuild ++= Seq("-deprecation", "-feature", "-Xfatal-warnings")
scalacOptions in ThisBuild ++= Seq("-deprecation", "-feature"/*, "-Xfatal-warnings"*/)

cancelable in Global := true

Expand Down
21 changes: 21 additions & 0 deletions core/src/main/scala/scala/collection/DebugUtils.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package scala.collection

private[collection] object DebugUtils {

def buildString(closure: (Any => Unit) => Unit): String = {
val output = new collection.mutable.StringBuilder
closure { any =>
output ++= any.toString
output += '\n'
}

output.result()
}

def arrayString[T](array: Array[T], from: Int, until: Int): String = {
array.slice(from, until) map ({
case null => "n/a"
case x => "" + x
}: scala.PartialFunction[T, String]) mkString " | "
}
}
17 changes: 17 additions & 0 deletions core/src/main/scala/scala/collection/Parallel.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */

package scala
package collection

/** A marker trait for collections which have their operations parallelised.
*
* @since 2.9
* @author Aleksandar Prokopec
*/
trait Parallel
2 changes: 1 addition & 1 deletion core/src/main/scala/scala/collection/Parallelizable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import parallel.Combiner
*/
trait Parallelizable[+A, +ParRepr <: Parallel] extends Any {

def seq: TraversableOnce[A]
def seq: IterableOnce[A]

/** Returns a parallel implementation of this collection.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import scala.collection.parallel._
* @tparam To the type of the collection to be created.
* @since 2.8
*/
trait CanCombineFrom[-From, -Elem, +To] extends CanBuildFrom[From, Elem, To] with Parallel {
trait CanCombineFrom[-From, -Elem, +To] extends Parallel {
def apply(from: From): Combiner[Elem, To]
def apply(): Combiner[Elem, To]
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package generic
import scala.collection.parallel.Combiner
import scala.collection.parallel.ParIterable
import scala.collection.parallel.ParMap
import scala.language.higherKinds
import scala.language.{higherKinds, implicitConversions}

/** A template class for companion objects of parallel collection classes.
* They should be mixed in together with `GenericCompanion` type.
Expand All @@ -27,16 +27,82 @@ import scala.language.higherKinds
* @since 2.8
*/
trait GenericParCompanion[+CC[X] <: ParIterable[X]] {

/** An empty collection of type `$Coll[A]`
* @tparam A the type of the ${coll}'s elements
*/
def empty[A]: CC[A] = newBuilder[A].result()

/** Creates a $coll with the specified elements.
* @tparam A the type of the ${coll}'s elements
* @param elems the elements of the created $coll
* @return a new $coll with elements `elems`
*/
def apply[A](elems: A*): CC[A] = {
if (elems.isEmpty) empty[A]
else {
val b = newBuilder[A]
b ++= elems
b.result()
}
}

/** The default builder for $Coll objects.
*/
def newBuilder[A]: Combiner[A, CC[A]]

/** The parallel builder for $Coll objects.
*/
def newCombiner[A]: Combiner[A, CC[A]]

implicit def toFactory[A]: Factory[A, CC[A]] = GenericParCompanion.toFactory(this)

}


// TODO Specialize `Factory` with parallel collection creation methods so that the `xs.to(ParArray)` syntax
// does build the resulting `ParArray` in parallel
object GenericParCompanion {
/**
* Implicit conversion for converting any `ParFactory` into a sequential `Factory`.
* This provides supports for the `to` conversion method (eg, `xs.to(ParArray)`).
*/
implicit def toFactory[A, CC[X] <: ParIterable[X]](parFactory: GenericParCompanion[CC]): Factory[A, CC[A]] =
new ToFactory(parFactory)

@SerialVersionUID(3L)
private class ToFactory[A, CC[X] <: ParIterable[X]](parFactory: GenericParCompanion[CC])
extends Factory[A, CC[A]] with Serializable{
def fromSpecific(it: IterableOnce[A]): CC[A] = (parFactory.newBuilder[A] ++= it).result()
def newBuilder: mutable.Builder[A, CC[A]] = parFactory.newBuilder
}

}

trait GenericParMapCompanion[+CC[P, Q] <: ParMap[P, Q]] {

def newCombiner[P, Q]: Combiner[(P, Q), CC[P, Q]]

implicit def toFactory[K, V]: Factory[(K, V), CC[K, V]] = GenericParMapCompanion.toFactory(this)

}

object GenericParMapCompanion {
/**
* Implicit conversion for converting any `ParFactory` into a sequential `Factory`.
* This provides supports for the `to` conversion method (eg, `xs.to(ParMap)`).
*/
implicit def toFactory[K, V, CC[X, Y] <: ParMap[X, Y]](
parFactory: GenericParMapCompanion[CC]
): Factory[(K, V), CC[K, V]] =
new ToFactory[K, V, CC](parFactory)

@SerialVersionUID(3L)
private class ToFactory[K, V, CC[X, Y] <: ParMap[X, Y]](
parFactory: GenericParMapCompanion[CC]
) extends Factory[(K, V), CC[K, V]] with Serializable {
def fromSpecific(it: IterableOnce[(K, V)]): CC[K, V] = (parFactory.newCombiner[K, V] ++= it).result()
def newBuilder: mutable.Builder[(K, V), CC[K, V]] = parFactory.newCombiner
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import scala.language.higherKinds
* @since 2.8
*/
trait GenericParTemplate[+A, +CC[X] <: ParIterable[X]]
extends GenericTraversableTemplate[A, CC]
with HasNewCombiner[A, CC[A] @uncheckedVariance]
extends GenericTraversableTemplate[A, CC]
with HasNewCombiner[A, CC[A] @uncheckedVariance]
{
def companion: GenericCompanion[CC] with GenericParCompanion[CC]
def companion: GenericParCompanion[CC]

protected[this] override def newBuilder: scala.collection.mutable.Builder[A, CC[A]] = newCombiner

Expand Down
Loading

0 comments on commit 8da0743

Please sign in to comment.