Skip to content

Commit e3d7ac6

Browse files
authored
Merge pull request #42 from julienrf/2.13.x
Scala 2.13.0 support
2 parents 8766788 + 17647af commit e3d7ac6

File tree

83 files changed

+4345
-1067
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+4345
-1067
lines changed

build.sbt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import ScalaModulePlugin._
22

33
version in ThisBuild := "0.1.3-SNAPSHOT"
44

5+
resolvers in ThisBuild += "scala-integration" at "https://scala-ci.typesafe.com/artifactory/scala-integration/"
6+
57
scalaVersionsByJvm in ThisBuild := {
6-
val v213 = "2.13.0-M3"
8+
val v213 = "2.13.0-pre-e40c95e"
79
Map(
810
8 -> List(v213 -> true),
911
11 -> List(v213 -> false))
1012
}
1113

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

1416
cancelable in Global := true
1517

@@ -72,7 +74,7 @@ lazy val junit = project.in(file("junit"))
7274
lazy val scalacheck = project.in(file("scalacheck"))
7375
.settings(commonSettings)
7476
.settings(
75-
libraryDependencies += "org.scalacheck" % "scalacheck_2.12" % "1.14.0",
77+
libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.14.0",
7678
fork in Test := true,
7779
testOptions in Test += Tests.Argument(TestFrameworks.ScalaCheck, "-workers", "1", "-minSize", "0", "-maxSize", "4000", "-minSuccessfulTests", "5"),
7880
disablePublishing
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package scala.collection
2+
3+
private[collection] object DebugUtils {
4+
5+
def buildString(closure: (Any => Unit) => Unit): String = {
6+
val output = new collection.mutable.StringBuilder
7+
closure { any =>
8+
output ++= any.toString
9+
output += '\n'
10+
}
11+
12+
output.result()
13+
}
14+
15+
def arrayString[T](array: Array[T], from: Int, until: Int): String = {
16+
array.slice(from, until) map ({
17+
case null => "n/a"
18+
case x => "" + x
19+
}: scala.PartialFunction[T, String]) mkString " | "
20+
}
21+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* __ *\
2+
** ________ ___ / / ___ Scala API **
3+
** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
4+
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
5+
** /____/\___/_/ |_/____/_/ | | **
6+
** |/ **
7+
\* */
8+
9+
package scala
10+
package collection
11+
12+
/** A marker trait for collections which have their operations parallelised.
13+
*
14+
* @since 2.9
15+
* @author Aleksandar Prokopec
16+
*/
17+
trait Parallel

core/src/main/scala/scala/collection/Parallelizable.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import parallel.Combiner
2424
*/
2525
trait Parallelizable[+A, +ParRepr <: Parallel] extends Any {
2626

27-
def seq: TraversableOnce[A]
27+
def seq: IterableOnce[A]
2828

2929
/** Returns a parallel implementation of this collection.
3030
*

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import scala.collection.parallel._
2424
* @tparam To the type of the collection to be created.
2525
* @since 2.8
2626
*/
27-
trait CanCombineFrom[-From, -Elem, +To] extends CanBuildFrom[From, Elem, To] with Parallel {
27+
trait CanCombineFrom[-From, -Elem, +To] extends Parallel {
2828
def apply(from: From): Combiner[Elem, To]
2929
def apply(): Combiner[Elem, To]
3030
}
31-

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

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package generic
1717
import scala.collection.parallel.Combiner
1818
import scala.collection.parallel.ParIterable
1919
import scala.collection.parallel.ParMap
20-
import scala.language.higherKinds
20+
import scala.language.{higherKinds, implicitConversions}
2121

2222
/** A template class for companion objects of parallel collection classes.
2323
* They should be mixed in together with `GenericCompanion` type.
@@ -27,16 +27,82 @@ import scala.language.higherKinds
2727
* @since 2.8
2828
*/
2929
trait GenericParCompanion[+CC[X] <: ParIterable[X]] {
30+
31+
/** An empty collection of type `$Coll[A]`
32+
* @tparam A the type of the ${coll}'s elements
33+
*/
34+
def empty[A]: CC[A] = newBuilder[A].result()
35+
36+
/** Creates a $coll with the specified elements.
37+
* @tparam A the type of the ${coll}'s elements
38+
* @param elems the elements of the created $coll
39+
* @return a new $coll with elements `elems`
40+
*/
41+
def apply[A](elems: A*): CC[A] = {
42+
if (elems.isEmpty) empty[A]
43+
else {
44+
val b = newBuilder[A]
45+
b ++= elems
46+
b.result()
47+
}
48+
}
49+
3050
/** The default builder for $Coll objects.
3151
*/
3252
def newBuilder[A]: Combiner[A, CC[A]]
3353

3454
/** The parallel builder for $Coll objects.
3555
*/
3656
def newCombiner[A]: Combiner[A, CC[A]]
57+
58+
implicit def toFactory[A]: Factory[A, CC[A]] = GenericParCompanion.toFactory(this)
59+
60+
}
61+
62+
63+
// TODO Specialize `Factory` with parallel collection creation methods so that the `xs.to(ParArray)` syntax
64+
// does build the resulting `ParArray` in parallel
65+
object GenericParCompanion {
66+
/**
67+
* Implicit conversion for converting any `ParFactory` into a sequential `Factory`.
68+
* This provides supports for the `to` conversion method (eg, `xs.to(ParArray)`).
69+
*/
70+
implicit def toFactory[A, CC[X] <: ParIterable[X]](parFactory: GenericParCompanion[CC]): Factory[A, CC[A]] =
71+
new ToFactory(parFactory)
72+
73+
@SerialVersionUID(3L)
74+
private class ToFactory[A, CC[X] <: ParIterable[X]](parFactory: GenericParCompanion[CC])
75+
extends Factory[A, CC[A]] with Serializable{
76+
def fromSpecific(it: IterableOnce[A]): CC[A] = (parFactory.newBuilder[A] ++= it).result()
77+
def newBuilder: mutable.Builder[A, CC[A]] = parFactory.newBuilder
78+
}
79+
3780
}
3881

3982
trait GenericParMapCompanion[+CC[P, Q] <: ParMap[P, Q]] {
83+
4084
def newCombiner[P, Q]: Combiner[(P, Q), CC[P, Q]]
85+
86+
implicit def toFactory[K, V]: Factory[(K, V), CC[K, V]] = GenericParMapCompanion.toFactory(this)
87+
4188
}
4289

90+
object GenericParMapCompanion {
91+
/**
92+
* Implicit conversion for converting any `ParFactory` into a sequential `Factory`.
93+
* This provides supports for the `to` conversion method (eg, `xs.to(ParMap)`).
94+
*/
95+
implicit def toFactory[K, V, CC[X, Y] <: ParMap[X, Y]](
96+
parFactory: GenericParMapCompanion[CC]
97+
): Factory[(K, V), CC[K, V]] =
98+
new ToFactory[K, V, CC](parFactory)
99+
100+
@SerialVersionUID(3L)
101+
private class ToFactory[K, V, CC[X, Y] <: ParMap[X, Y]](
102+
parFactory: GenericParMapCompanion[CC]
103+
) extends Factory[(K, V), CC[K, V]] with Serializable {
104+
def fromSpecific(it: IterableOnce[(K, V)]): CC[K, V] = (parFactory.newCombiner[K, V] ++= it).result()
105+
def newBuilder: mutable.Builder[(K, V), CC[K, V]] = parFactory.newCombiner
106+
}
107+
108+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ import scala.language.higherKinds
2929
* @since 2.8
3030
*/
3131
trait GenericParTemplate[+A, +CC[X] <: ParIterable[X]]
32-
extends GenericTraversableTemplate[A, CC]
33-
with HasNewCombiner[A, CC[A] @uncheckedVariance]
32+
extends GenericTraversableTemplate[A, CC]
33+
with HasNewCombiner[A, CC[A] @uncheckedVariance]
3434
{
35-
def companion: GenericCompanion[CC] with GenericParCompanion[CC]
35+
def companion: GenericParCompanion[CC]
3636

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

0 commit comments

Comments
 (0)