8000 Small fixes and more tests for jdk Converters by lrytz · Pull Request #7970 · scala/scala · GitHub
[go: up one dir, main page]

Skip to content

Small fixes and more tests for jdk Converters #7970

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

Merged
merged 13 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 22 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,28 @@ import com.typesafe.tools.mima.core._
val mimaPrereleaseHandlingSettings = Seq(
mimaBinaryIssueFilters ++= Seq(
ProblemFilters.exclude[Problem]("scala.reflect.internal.*"),
ProblemFilters.exclude[MissingClassProblem]("scala.collection.convert.StreamExtensions$ShortArrayHasSeqParStream"),
ProblemFilters.exclude[MissingClassProblem]("scala.collection.convert.StreamExtensions$CharArrayHasSeqParStream"),
ProblemFilters.exclude[MissingClassProblem]("scala.collection.convert.StreamExtensions$ByteArrayHasSeqParStream"),
ProblemFilters.exclude[MissingClassProblem]("scala.collection.convert.StreamExtensions$FloatArrayHasSeqParStream"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.StreamExtensions.ShortArrayHasSeqParStream"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.StreamExtensions.CharArrayHasSeqParStream"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.StreamExtensions.ByteArrayHasSeqParStream"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.StreamExtensions.FloatArrayHasSeqParStream"),
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.StepperShape$"),
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.StepperShape$"),
ProblemFilters.exclude[MissingClassProblem]("scala.collection.StepperShapeLowPriority"),
ProblemFilters.exclude[MissingClassProblem]("scala.collection.StepperShapeLowPriority1"),
ProblemFilters.exclude[MissingClassProblem]("scala.collection.StepperShapeLowPriority2"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.StepperShape.anyStepperShapePrototype"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.impl.ChampStepperBase.effectiveRootLevel"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.impl.ChampStepperBase.skipHalf"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.impl.ChampStepperBase.stealCurrentNodesFrom"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.impl.ChampStepperBase.stealNodesFrom"),
ProblemFilters.exclude[Problem]("scala.collection.convert.*"),
ProblemFilters.exclude[Problem]("scala.collection.StepperShape.*"),
ProblemFilters.exclude[Problem]("scala.jdk.*"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.concurrent.impl.FutureConvertersImpl#CF.*"),
),
)

Expand Down
27 changes: 23 additions & 4 deletions src/library/scala/collection/StepperShape.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

package scala.collection

import java.{lang => jl}

import scala.collection.Stepper.EfficientSplit

/** An implicit StepperShape instance is used in the [[IterableOnce.stepper]] to return a possibly
Expand All @@ -30,7 +32,7 @@ sealed trait StepperShape[T, S <: Stepper[_]] {
def parUnbox(st: AnyStepper[T] with EfficientSplit): S with EfficientSplit
}

object StepperShape extends StepperShapeLowPriority {
object StepperShape extends StepperShapeLowPriority1 {
class Shape private[StepperShape] (private val s: Int) extends AnyVal

// reference
Expand All @@ -52,44 +54,61 @@ object StepperShape extends StepperShapeLowPriority {
def seqUnbox(st: AnyStepper[Int]): IntStepper = new Stepper.UnboxingIntStepper(st)
def parUnbox(st: AnyStepper[Int] with EfficientSplit): IntStepper with EfficientSplit = new Stepper.UnboxingIntStepper(st) with EfficientSplit
}
implicit val jIntegerStepperShape: StepperShape[jl.Integer, IntStepper] = intStepperShape.asInstanceOf[StepperShape[jl.Integer, IntStepper]]

implicit val longStepperShape: StepperShape[Long, LongStepper] = new StepperShape[Long, LongStepper] {
def shape = LongShape
def seqUnbox(st: AnyStepper[Long]): LongStepper = new Stepper.UnboxingLongStepper(st)
def parUnbox(st: AnyStepper[Long] with EfficientSplit): LongStepper with EfficientSplit = new Stepper.UnboxingLongStepper(st) with EfficientSplit
}
implicit val jLongStepperShape: StepperShape[jl.Long, LongStepper] = longStepperShape.asInstanceOf[StepperShape[jl.Long, LongStepper]]

implicit val doubleStepperShape: StepperShape[Double, DoubleStepper] = new StepperShape[Double, DoubleStepper] {
def shape = DoubleShape
def seqUnbox(st: AnyStepper[Double]): DoubleStepper = new Stepper.UnboxingDoubleStepper(st)
def parUnbox(st: AnyStepper[Double] with EfficientSplit): DoubleStepper with EfficientSplit = new Stepper.UnboxingDoubleStepper(st) with EfficientSplit
}
implicit val jDoubleStepperShape: StepperShape[jl.Double, DoubleStepper] = doubleStepperShape.asInstanceOf[StepperShape[jl.Double, DoubleStepper]]

implicit val byteStepperShape: StepperShape[Byte, IntStepper] = new StepperShape[Byte, IntStepper] {
def shape = ByteShape
def seqUnbox(st: AnyStepper[Byte]): IntStepper = new Stepper.UnboxingByteStepper(st)
def parUnbox(st: AnyStepper[Byte] with EfficientSplit): IntStepper with EfficientSplit = new Stepper.UnboxingByteStepper(st) with EfficientSplit
}
implicit val jByteStepperShape: StepperShape[jl.Byte, IntStepper] = byteStepperShape.asInstanceOf[StepperShape[jl.Byte, IntStepper]]

implicit val shortStepperShape: StepperShape[Short, IntStepper] = new StepperShape[Short, IntStepper] {
def shape = ShortShape
def seqUnbox(st: AnyStepper[Short]): IntStepper = new Stepper.UnboxingShortStepper(st)
def parUnbox(st: AnyStepper[Short] with EfficientSplit): IntStepper with EfficientSplit = new Stepper.UnboxingShortStepper(st) with EfficientSplit
}
implicit val jShortStepperShape: StepperShape[jl.Short, IntStepper] = shortStepperShape.asInstanceOf[StepperShape[jl.Short, IntStepper]]

implicit val charStepperShape: StepperShape[Char, IntStepper] = new StepperShape[Char, IntStepper] {
def shape = CharShape
def seqUnbox(st: AnyStepper[Char]): IntStepper = new Stepper.UnboxingCharStepper(st)
def parUnbox(st: AnyStepper[Char] with EfficientSplit): IntStepper with EfficientSplit = new Stepper.UnboxingCharStepper(st) with EfficientSplit
}
implicit val jCharacterStepperShape: StepperShape[jl.Character, IntStepper] = charStepperShape.asInstanceOf[StepperShape[jl.Character, IntStepper]]

implicit val floatStepperShape: StepperShape[Float, DoubleStepper] = new StepperShape[Float, DoubleStepper] {
def shape = FloatShape
def seqUnbox(st: AnyStepper[Float]): DoubleStepper = new Stepper.UnboxingFloatStepper(st)
def parUnbox(st: AnyStepper[Float] with EfficientSplit): DoubleStepper with EfficientSplit = new Stepper.UnboxingFloatStepper(st) with EfficientSplit
}
implicit val jFloatStepperShape: StepperShape[jl.Float, DoubleStepper] = floatStepperShape.asInstanceOf[StepperShape[jl.Float, DoubleStepper]]
}

trait StepperShapeLowPriority {
trait StepperShapeLowPriority1 extends StepperShapeLowPriority2 {
implicit def anyStepperShape[T]: StepperShape[T, AnyStepper[T]] = anyStepperShapePrototype.asInstanceOf[StepperShape[T, AnyStepper[T]]]
}

private[this] val anyStepperShapePrototype: StepperShape[AnyRef, AnyStepper[AnyRef]] = new StepperShape[AnyRef, AnyStepper[AnyRef]] {
trait StepperShapeLowPriority2 {
implicit def baseStepperShape[T]: StepperShape[T, Stepper[T]] = anyStepperShapePrototype.asInstanceOf[StepperShape[T, Stepper[T]]]

protected val anyStepperShapePrototype: StepperShape[AnyRef, Stepper[AnyRef]] = new StepperShape[AnyRef, Stepper[AnyRef]] {
def shape = StepperShape.ReferenceShape
def seqUnbox(st: AnyStepper[AnyRef]): AnyStepper[AnyRef] = st
def parUnbox(st: AnyStepper[AnyRef] with EfficientSplit): AnyStepper[AnyRef] with EfficientSplit = st
}
}
}
73 changes: 54 additions & 19 deletions src/library/scala/collection/convert/StreamExtensions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

package scala.collection.convert

import java.util.Spliterator
import java.util.stream._
import java.{lang => jl}

import scala.annotation.implicitNotFound
import scala.collection.Stepper.EfficientSplit
Expand Down Expand Up @@ -173,6 +175,36 @@ trait StreamExtensions {
def asJavaParStream: Stream[A] = asJavaSeqStream.parallel
}

implicit class ByteArrayHasSeqParStream(a: Array[Byte]) {
/** Create a sequential [[java.util.stream.IntStream Java IntStream]] for this array. */
def asJavaSeqStream: IntStream = a.stepper.asJavaSeqStream
/** Create a parallel [[java.util.stream.IntStream Java IntStream]] for this array. */
def asJavaParStream: IntStream = a.stepper.asJavaParStream
}

implicit class ShortArrayHasSeqParStream(a: Array[Short]) {
/** Create a sequential [[java.util.stream.IntStream Java IntStream]] for this array. */
def asJavaSeqStream: IntStream = a.stepper.asJavaSeqStream
/** Create a parallel [[java.util.stream.IntStream Java IntStream]] for this array. */
def asJavaParStream: IntStream = a.stepper.asJavaParStream
}

implicit class CharArrayHasSeqParStream(a: Array[Char]) {
/** Create a sequential [[java.util.stream.IntStream Java IntStream]] for this array. */
def asJavaSeqStream: IntStream = a.stepper.asJavaSeqStream
/** Create a parallel [[java.util.stream.IntStream Java IntStream]] for this array. */
def asJavaParStream: IntStream = a.stepper.asJavaParStream
}

implicit class FloatArrayHasSeqParStream(a: Array[Float]) {
/** Create a sequential [[java.util.stream.DoubleStream Java DoubleStream]] for this array. */
def asJavaSeqStream: DoubleStream = a.stepper.asJavaSeqStream
/** Create a parallel [[java.util.stream.DoubleStream Java DoubleStream]] for this array. */
def asJavaParStream: DoubleStream = a.stepper.asJavaParStream
}



// strings

implicit class StringHasSeqParStream(s: String) {
Expand Down Expand Up @@ -332,42 +364,45 @@ object StreamExtensions {
implicit val intStreamShape : StreamShape[Int , IntStream , IntStepper] = mkIntStreamShape[Int]
implicit val longStreamShape : StreamShape[Long , LongStream , LongStepper] = mkLongStreamShape[Long]
implicit val doubleStreamShape: StreamShape[Double, DoubleStream, DoubleStepper] = mkDoubleStreamShape[Double]
}

trait StreamShapeLowPriority1 extends StreamShapeLowPriority2 {

// widening
implicit val byteStreamShape : StreamShape[Byte , IntStream , IntStepper] = mkIntStreamShape[Byte]
implicit val shortStreamShape: StreamShape[Short, IntStream , IntStepper] = mkIntStreamShape[Short]
implicit val charStreamShape : StreamShape[Char , IntStream , IntStepper] = mkIntStreamShape[Char]
implicit val floatStreamShape: StreamShape[Float, DoubleStream, DoubleStepper] = mkDoubleStreamShape[Float]

implicit val integerStreamShape : StreamShape[java.lang.Integer, IntStream 8000 , IntStepper] = mkIntStreamShape[java.lang.Integer]
// boxed java primitives

implicit val jIntegerStreamShape : StreamShape[jl.Integer , IntStream , IntStepper ] = mkIntStreamShape[jl.Integer]
implicit val jLongStreamShape : StreamShape[jl.Long , LongStream , LongStepper ] = mkLongStreamShape[jl.Long]
implicit val jDoubleStreamShape : StreamShape[jl.Double , DoubleStream, DoubleStepper] = mkDoubleStreamShape[jl.Double]
implicit val jByteStreamShape : StreamShape[jl.Byte , IntStream , IntStepper ] = mkIntStreamShape[jl.Byte]
implicit val jShortStreamShape : StreamShape[jl.Short , IntStream , IntStepper ] = mkIntStreamShape[jl.Short]
implicit val jCharacterStreamShape : StreamShape[jl.Character, IntStream , IntStepper ] = mkIntStreamShape[jl.Character]
implicit val jFloatStreamShape : StreamShape[jl.Float , DoubleStream, DoubleStepper] = mkDoubleStreamShape[jl.Float]

protected def mkIntStreamShape[T]: StreamShape[T, IntStream, IntStepper] = new StreamShape[T, IntStream, IntStepper] {
private def mkIntStreamShape[T]: StreamShape[T, IntStream, IntStepper] = new StreamShape[T, IntStream, IntStepper] {
protected def mkStream(st: IntStepper, par: Boolean): IntStream = StreamSupport.intStream(st.spliterator, par)
}

protected def mkLongStreamShape[T]: StreamShape[T, LongStream, LongStepper] = new StreamShape[T, LongStream, LongStepper] {
private def mkLongStreamShape[T]: StreamShape[T, LongStream, LongStepper] = new StreamShape[T, LongStream, LongStepper] {
protected def mkStream(st: LongStepper, par: Boolean): LongStream = StreamSupport.longStream(st.spliterator, par)
}

protected def mkDoubleStreamShape[T]: StreamShape[T, DoubleStream, DoubleStepper] = new StreamShape[T, DoubleStream, DoubleStepper] {
private def mkDoubleStreamShape[T]: StreamShape[T, DoubleStream, DoubleStepper] = new StreamShape[T, DoubleStream, DoubleStepper] {
protected def mkStream(st: DoubleStepper, par: Boolean): DoubleStream = StreamSupport.doubleStream(st.spliterator, par)
}
}

trait StreamShapeLowPriority2 {
trait StreamShapeLowPriority1 {
// reference
implicit def anyStreamShape[T]: StreamShape[T, Stream[T], AnyStepper[T]] = anyStreamShapePrototype.asInstanceOf[StreamShape[T, Stream[T], AnyStepper[T]]]
implicit def anyStreamShape[T]: StreamShape[T, Stream[T], Stepper[T]] = anyStreamShapePrototype.asInstanceOf[StreamShape[T, Stream[T], Stepper[T]]]

private[this] val anyStreamShapePrototype: StreamShape[AnyRef, Stream[AnyRef], AnyStepper[AnyRef]] = new StreamShape[AnyRef, Stream[AnyRef], AnyStepper[AnyRef]] {
def mkStream(s: AnyStepper[AnyRef], par: Boolean): Stream[AnyRef] = StreamSupport.stream(s.spliterator, par)
private[this] val anyStreamShapePrototype: StreamShape[AnyRef, Stream[AnyRef], Stepper[AnyRef]] = new StreamShape[AnyRef, Stream[AnyRef], Stepper[AnyRef]] {
def mkStream(s: Stepper[AnyRef], par: Boolean): Stream[AnyRef] = StreamSupport.stream(s.spliterator.asInstanceOf[Spliterator[AnyRef]], par)
}
}



/** Connects a stream element type `A` to the corresponding, potentially specialized, Stream type.
* Used in the `stream.asJavaPrimitiveStream` extension method.
*/
Expand All @@ -378,17 +413,17 @@ object StreamExtensions {
implicit val intStreamUnboxer: StreamUnboxer[Int, IntStream] = new StreamUnboxer[Int, IntStream] {
def apply( A348 s: Stream[Int]): IntStream = s.mapToInt(x => x)
}
implicit val javaIntegerStreamUnboxer: StreamUnboxer[java.lang.Integer, IntStream] = intStreamUnboxer.asInstanceOf[StreamUnboxer[java.lang.Integer, IntStream]]
implicit val javaIntegerStreamUnboxer: StreamUnboxer[jl.Integer, IntStream] = intStreamUnboxer.asInstanceOf[StreamUnboxer[jl.Integer, IntStream]]

implicit val longStreamUnboxer: StreamUnboxer[Long, LongStream] = new StreamUnboxer[Long, LongStream] {
def apply(s: Stream[Long]): LongStream = s.mapToLong(x => x)
}
implicit val javaLongStreamUnboxer: StreamUnboxer[java.lang.Long, LongStream] = longStreamUnboxer.asInstanceOf[StreamUnboxer[java.lang.Long, LongStream]]
implicit val javaLongStreamUnboxer: StreamUnboxer[jl.Long, LongStream] = longStreamUnboxer.asInstanceOf[StreamUnboxer[jl.Long, LongStream]]

implicit val doubleStreamUnboxer: StreamUnboxer[Double, DoubleStream] = new StreamUnboxer[Double, DoubleStream] {
def apply(s: Stream[Double]): DoubleStream = s.mapToDouble(x => x)
}
implicit val javaDoubleStreamUnboxer: StreamUnboxer[java.lang.Double, DoubleStream] = doubleStreamUnboxer.asInstanceOf[StreamUnboxer[java.lang.Double, DoubleStream]]
implicit val javaDoubleStreamUnboxer: StreamUnboxer[jl.Double, DoubleStream] = doubleStreamUnboxer.asInstanceOf[StreamUnboxer[jl.Double, DoubleStream]]
}


Expand Down Expand Up @@ -428,8 +463,8 @@ object StreamExtensions {
val companion: AnyRef = DoubleAccumulator
}

implicit val javaIntegerAccumulatorFactoryInfo: AccumulatorFactoryInfo[java.lang.Integer, IntAccumulator] = intAccumulatorFactoryInfo.asInstanceOf[AccumulatorFactoryInfo[java.lang.Integer, IntAccumulator]]
implicit val javaLongAccumulatorFactoryInfo: AccumulatorFactoryInfo[java.lang.Long, IntAccumulator] = longAccumulatorFactoryInfo.asInstanceOf[AccumulatorFactoryInfo[java.lang.Long, IntAccumulator]]
implicit val javaDoubleAccumulatorFactoryInfo: AccumulatorFactoryInfo[java.lang.Double, IntAccumulator] = doubleAccumulatorFactoryInfo.asInstanceOf[AccumulatorFactoryInfo[java.lang.Double, IntAccumulator]]
implicit val jIntegerAccumulatorFactoryInfo: AccumulatorFactoryInfo[jl.Integer, IntAccumulator] = intAccumulatorFactoryInfo.asInstanceOf[AccumulatorFactoryInfo[jl.Integer, IntAccumulator]]
implicit val jLongAccumulatorFactoryInfo: AccumulatorFactoryInfo[jl.Long, IntAccumulator] = longAccumulatorFactoryInfo.asInstanceOf[AccumulatorFactoryInfo[jl.Long, IntAccumulator]]
implicit val jDoubleAccumulatorFactoryInfo: AccumulatorFactoryInfo[jl.Double, IntAccumulator] = doubleAccumulatorFactoryInfo.asInstanceOf[AccumulatorFactoryInfo[jl.Double, IntAccumulator]]
}
}
Loading
0