10000 Remove unnecessary type parameter on `IterableOnce#stepper` · scala/scala@4b00073 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4b00073

Browse files
szeigeradriaanm
authored andcommitted
Remove unnecessary type parameter on IterableOnce#stepper
This also requires a contravariant `StepperShape`. Without this change it is impossible to delegate easily (without casting) from such a `stepper` implementation to one without the extra type parameter (see `StepperTest`). It also makes the signatures less ugly.
1 parent 6ce8a5e commit 4b00073

31 files changed

+73
-61
lines changed

build.sbt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ val mimaPrereleaseHandlingSettings = Seq(
9191
// Drop after 2.13.0 is out, whence src/reflect/mima-filters/ takes over.
9292
ProblemFilters.exclude[Problem]("scala.reflect.internal.*"),
9393

94+
9495
// #8096
9596
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.immutable.HashSet.this"),
9697

@@ -107,6 +108,10 @@ val mimaPrereleaseHandlingSettings = Seq(
107108
ProblemFilters.exclude[IncompatibleResultTypeProblem]("scala.collection.MapView.+"),
108109
ProblemFilters.exclude[IncompatibleMethTypeProblem]("scala.collection.MapView.concat"),
109110

111+
// #8083
112+
ProblemFilters.exclude[FinalMethodProblem]("scala.jdk.Accumulator.stepper"),
113+
114+
110115
),
111116
)
112117

src/library/scala/collection/BitSet.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ trait BitSetOps[+C <: BitSet with BitSetOps[C]]
121121
else Iterator.empty.next()
122122
}
123123

124-
override def stepper[B >: Int, S <: Stepper[_]](implicit shape: StepperShape[B, S]): S with EfficientSplit = {
124+
override def stepper[S <: Stepper[_]](implicit shape: StepperShape[Int, S]): S with EfficientSplit = {
125125
val st = scala.collection.convert.impl.BitSetStepper.from(this)
126126
val r =
127127
if (shape.shape == StepperShape.IntShape) st

src/library/scala/collection/IndexedSeq.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ trait IndexedSeqOps[+A, +CC[_], +C] extends Any with SeqOps[A, CC, C] { self =>
3737

3838
def iterator: Iterator[A] = view.iterator
3939

40-
override def stepper[B >: A, S <: Stepper[_]](implicit shape: StepperShape[B, S]): S with EfficientSplit = {
40+
override def stepper[S <: Stepper[_]](implicit shape: StepperShape[A, S]): S with EfficientSplit = {
4141
import convert.impl._
4242
val s = shape.shape match {
4343
case StepperShape.IntShape => new IntIndexedSeqStepper (this.asInstanceOf[IndexedSeqOps[Int, AnyConstr, _]], 0, length)
4444
case StepperShape.LongShape => new LongIndexedSeqStepper (this.asInstanceOf[IndexedSeqOps[Long, AnyConstr, _]], 0, length)
4545
case StepperShape.DoubleShape => new DoubleIndexedSeqStepper(this.asInstanceOf[IndexedSeqOps[Double, AnyConstr, _]], 0, length)
46-
case _ => shape.parUnbox(new AnyIndexedSeqStepper[B](this, 0, length))
46+
case _ => shape.parUnbox(new AnyIndexedSeqStepper[A](this, 0, length))
4747
}
4848
s.asInstanceOf[S with EfficientSplit]
4949
}

src/library/scala/collection/IterableOnce.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ trait IterableOnce[+A] extends Any {
6363
* allow creating parallel streams, whereas bare Steppers can be converted only to sequential
6464
* streams.
6565
*/
66-
def stepper[B >: A, S <: Stepper[_]](implicit shape: StepperShape[B, S]): S = {
66+
def stepper[S <: Stepper[_]](implicit shape: StepperShape[A, S]): S = {
6767
import convert.impl._
6868
val s = shape.shape match {
6969
case StepperShape.IntShape => new IntIteratorStepper (iterator.asInstanceOf[Iterator[Int]])
7070
case StepperShape.LongShape => new LongIteratorStepper (iterator.asInstanceOf[Iterator[Long]])
7171
case StepperShape.DoubleShape => new DoubleIteratorStepper(iterator.asInstanceOf[Iterator[Double]])
72-
case _ => shape.seqUnbox(new AnyIteratorStepper[B](iterator))
72+
case _ => shape.seqUnbox(new AnyIteratorStepper[A](iterator))
7373
}
7474
s.asInstanceOf[S]
7575
}

src/library/scala/collection/Map.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ trait MapOps[K, +V, +CC[_, _] <: IterableOps[_, AnyConstr, _], +C]
9090
}
9191

9292
/** Returns a [[Stepper]] for the values of this map. See method [[stepper]]. */
93-
def valueStepper[V1 >: V, S <: Stepper[_]](implicit shape: StepperShape[V1, S]): S = {
93+
def valueStepper[S <: Stepper[_]](implicit shape: StepperShape[V, S]): S = {
9494
import convert.impl._
9595
val s = shape.shape match {
9696
case StepperShape.IntShape => new IntIteratorStepper (valuesIterator.asInstanceOf[Iterator[Int]])

src/library/scala/collection/StepperShape.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import scala.collection.Stepper.EfficientSplit
1919
/** An implicit StepperShape instance is used in the [[IterableOnce.stepper]] to return a possibly
2020
* specialized Stepper `S` according to the element type `T`.
2121
*/
22-
sealed trait StepperShape[T, S <: Stepper[_]] {
22+
sealed trait StepperShape[-T, S <: Stepper[_]] {
2323
/** Return the Int constant (as defined in the `StepperShape` companion object) for this `StepperShape`. */
2424
def shape: StepperShape.Shape
2525

src/library/scala/collection/convert/StreamExtensions.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ trait StreamExtensions {
3939
}
4040

4141
protected type IterableOnceWithEfficientStepper[A] = IterableOnce[A] {
42-
def stepper[B >: A, S <: Stepper[_]](implicit shape : StepperShape[B, S]) : S with EfficientSplit
42+
def stepper[S <: Stepper[_]](implicit shape : StepperShape[A, S]) : S with EfficientSplit
4343
}
4444

4545
// Not `CC[X] <: IterableOnce[X]`, but `C` with an extra constraint, to support non-parametric classes like IntAccumulator
@@ -84,8 +84,8 @@ trait StreamExtensions {
8484

8585
implicit class MapHasParKeyValueStream[K, V, CC[X, Y] <: collection.MapOps[X, Y, CC, _]](cc: CC[K, V]) {
8686
private type MapOpsWithEfficientKeyStepper[K, V] = collection.MapOps[K, V, CC, _] { def keyStepper[S <: Stepper[_]](implicit shape : StepperShape[K, S]) : S with EfficientSplit }
87-
private type MapOpsWithEfficientValueStepper[K, V] = collection.MapOps[K, V, CC, _] { def valueStepper[V1 >: V, S <: Stepper[_]](implicit shape : StepperShape[V1, S]) : S with EfficientSplit }
88-
private type MapOpsWithEfficientStepper[K, V] = collection.MapOps[K, V, CC, _] { def stepper[B >: (K, V), S <: Stepper[_]](implicit shape : StepperShape[B, S]) : S with EfficientSplit }
87+
private type MapOpsWithEfficientValueStepper[K, V] = collection.MapOps[K, V, CC, _] { def valueStepper[S <: Stepper[_]](implicit shape : StepperShape[V, S]) : S with EfficientSplit }
88+
private type MapOpsWithEfficientStepper[K, V] = collection.MapOps[K, V, CC, _] { def stepper[S <: Stepper[_]](implicit shape : StepperShape[(K, V), S]) : S with EfficientSplit }
8989

9090
/** Create a parallel [[java.util.stream.Stream Java Stream]] for the keys of this map. If
9191
* the keys are primitive values, a corresponding specialized Stream is returned (e.g.,

src/library/scala/collection/immutable/ArraySeq.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ sealed abstract class ArraySeq[+A]
5555
protected def evidenceIterableFactory: ArraySeq.type = ArraySeq
5656
protected def iterableEvidence: ClassTag[A @uncheckedVariance] = elemTag.asInstanceOf[ClassTag[A]]
5757

58-
override def stepper[B >: A, S <: Stepper[_]](implicit shape: StepperShape[B, S]): S with EfficientSplit = {
58+
override def stepper[S <: Stepper[_]](implicit shape: StepperShape[A, S]): S with EfficientSplit = {
5959
import scala.collection.convert.impl._
6060
val isRefShape = shape.shape == StepperShape.ReferenceShape
6161
val s = if (isRefShape) unsafeArray match {
@@ -70,7 +70,7 @@ sealed abstract class ArraySeq[+A]
7070
case a: Array[AnyRef] => new ObjectArrayStepper(a, 0, a.length)
7171
} else {
7272
unsafeArray match {
73-
case a: Array[AnyRef] => shape.parUnbox(new ObjectArrayStepper(a, 0, a.length).asInstanceOf[AnyStepper[B] with EfficientSplit])
73+
case a: Array[AnyRef] => shape.parUnbox(new ObjectArrayStepper(a, 0, a.length).asInstanceOf[AnyStepper[A] with EfficientSplit])
7474
case a: Array[Int] => new IntArrayStepper(a, 0, a.length)
7575
case a: Array[Long] => new LongArrayStepper(a, 0, a.length)
7676
case a: Array[Double] => new DoubleArrayStepper(a, 0, a.length)

src/library/scala/collection/immutable/HashMap.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ final class HashMap[K, +V] private[immutable] (private[immutable] val rootNode:
9494
else new MapKeyValueTupleReverseIterator[K, V](rootNode)
9595
}
9696

97-
override def stepper[B >: (K, V), S <: Stepper[_]](implicit shape: StepperShape[B, S]): S with EfficientSplit =
97+
override def stepper[S <: Stepper[_]](implicit shape: StepperShape[(K, V), S]): S with EfficientSplit =
9898
shape.
99-
parUnbox(collection.convert.impl.AnyChampStepper.from[B, MapNode[K, V]](size, rootNode, (node, i) => node.getPayload(i)))
99+
parUnbox(collection.convert.impl.AnyChampStepper.from[(K, V), MapNode[K, V]](size, rootNode, (node, i) => node.getPayload(i)))
100100

101101
override def keyStepper[S <: Stepper[_]](implicit shape: StepperShape[K, S]): S with EfficientSplit = {
102102
import collection.convert.impl._
@@ -109,13 +109,13 @@ final class HashMap[K, +V] private[immutable] (private[immutable] val rootNode:
109109
s.asInstanceOf[S with EfficientSplit]
110110
}
111111

112-
override def valueStepper[B >: V, S <: Stepper[_]](implicit shape: StepperShape[B, S]): S with EfficientSplit = {
112+
override def valueStepper[S <: Stepper[_]](implicit shape: StepperShape[V, S]): S with EfficientSplit = {
113113
import collection.convert.impl._
114114
val s = shape.shape match {
115115
case StepperShape.IntShape => IntChampStepper.from[ MapNode[K, V]](size, rootNode, (node, i) => node.getValue(i).asInstanceOf[Int])
116116
case StepperShape.LongShape => LongChampStepper.from[ MapNode[K, V]](size, rootNode, (node, i) => node.getValue(i).asInstanceOf[Long])
117117
case StepperShape.DoubleShape => DoubleChampStepper.from[MapNode[K, V]](size, rootNode, (node, i) => node.getValue(i).asInstanceOf[Double])
118-
case _ => shape.parUnbox(AnyChampStepper.from[B, MapNode[K, V]](size, rootNode, (node, i) => node.getValue(i)))
118+
case _ => shape.parUnbox(AnyChampStepper.from[V, MapNode[K, V]](size, rootNode, (node, i) => node.getValue(i)))
119119
}
120120
s.asInstanceOf[S with EfficientSplit]
121121
}

src/library/scala/collection/immutable/HashSet.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ final class HashSet[A] private[immutable](private[immutable] val rootNode: Bitma
6262

6363
protected[immutable] def reverseIterator: Iterator[A] = new SetReverseIterator[A](rootNode)
6464

65-
override def stepper[B >: A, S <: Stepper[_]](implicit shape: StepperShape[B, S]): S with EfficientSplit = {
65+
override def stepper[S <: Stepper[_]](implicit shape: StepperShape[A, S]): S with EfficientSplit = {
6666
import convert.impl._
6767
val s = shape.shape match {
6868
case StepperShape.IntShape => IntChampStepper.from[ SetNode[A]](size, rootNode, (node, i) => node.getPayload(i).asInstanceOf[Int])
6969
case StepperShape.LongShape => LongChampStepper.from[ SetNode[A]](size, rootNode, (node, i) => node.getPayload(i).asInstanceOf[Long])
7070
case StepperShape.DoubleShape => DoubleChampStepper.from[SetNode[A]](size, rootNode, (node, i) => node.getPayload(i).asInstanceOf[Double])
71-
case _ => shape.parUnbox(AnyChampStepper.from[B, SetNode[A]](size, rootNode, (node, i) => node.getPayload(i)))
71+
case _ => shape.parUnbox(AnyChampStepper.from[A, SetNode[A]](size, rootNode, (node, i) => node.getPayload(i)))
7272
}
7373
s.asInstanceOf[S with EfficientSplit]
7474
}

0 commit comments

Comments
 (0)
0