Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala 2.13.0 support #42

Merged
merged 4 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 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-b9306a2"
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 Expand Up @@ -72,7 +74,7 @@ lazy val junit = project.in(file("junit"))
lazy val scalacheck = project.in(file("scalacheck"))
.settings(commonSettings)
.settings(
libraryDependencies += "org.scalacheck" % "scalacheck_2.12" % "1.14.0",
libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.14.0",
fork in Test := true,
testOptions in Test += Tests.Argument(TestFrameworks.ScalaCheck, "-workers", "1", "-minSize", "0", "-maxSize", "4000", "-minSuccessfulTests", "5"),
disablePublishing
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()
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods (empty and apply) were previously inherited from GenericCompanion, which has been removed from the standard library.


/** 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
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These conversions towards scala.collection.Factory provide interoperability with the standard collections. It makes it possible to write List(1, 2, 3).to(ParArray).


}

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
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with maps, to support Map(1 -> 0, 2 -> 0).to(ParMap).


}
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