Skip to content

Commit fcc77a0

Browse files
committed
Update scala2-library-cc to make use of inference fixes
Most hacks using `asInstanceOf` or `???` are no longer necessary.
1 parent 910762f commit fcc77a0

File tree

6 files changed

+20
-24
lines changed

6 files changed

+20
-24
lines changed

scala2-library-cc/src/scala/collection/Factory.scala

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ trait IterableFactory[+CC[_]] extends Serializable, Pure {
161161
* @return A $coll that contains the results of `n1 x n2` evaluations of `elem`.
162162
*/
163163
def fill[A](n1: Int, n2: Int)(elem: => A): CC[(CC[A]^{elem}) @uncheckedVariance]^{elem} =
164-
fill[CC[A]^{elem}](n1)(fill(n2)(elem)) // !!! explicit type argument required under cc
164+
fill(n1)(fill(n2)(elem))
165165

166166
/** Produces a three-dimensional $coll containing the results of some element computation a number of times.
167167
* @param n1 the number of elements in the 1st dimension
@@ -170,8 +170,8 @@ trait IterableFactory[+CC[_]] extends Serializable, Pure {
170170
* @param elem the element computation
171171
* @return A $coll that contains the results of `n1 x n2 x n3` evaluations of `elem`.
172172
*/
173-
def fill[A](n1: Int, n2: Int, n3: Int)(elem: => A): CC[(CC[CC[A]^{elem}]^{elem}) @uncheckedVariance]^{elem} = // !!! problem with checking rhs under cc
174-
fill[CC[CC[A]^{elem}]^{elem}](n1)(fill(n2, n3)(elem)) // !!! explicit type argument required under cc
173+
def fill[A](n1: Int, n2: Int, n3: Int)(elem: => A): CC[(CC[CC[A]^{elem}]^{elem}) @uncheckedVariance]^{elem} =
174+
fill(n1)(fill(n2, n3)(elem))
175175

176176
/** Produces a four-dimensional $coll containing the results of some element computation a number of times.
177177
* @param n1 the number of elements in the 1st dimension
@@ -181,8 +181,8 @@ trait IterableFactory[+CC[_]] extends Serializable, Pure {
181181
* @param elem the element computation
182182
* @return A $coll that contains the results of `n1 x n2 x n3 x n4` evaluations of `elem`.
183183
*/
184-
def fill[A](n1: Int, n2: Int, n3: Int, n4: Int)(elem: => A): CC[(CC[CC[CC[A]^{elem}]^{elem}]^{elem}) @uncheckedVariance]^{elem} = // !!! problem with checking rhs under cc
185-
fill[CC[CC[CC[A]^{elem}]^{elem}]^{elem}](n1)(fill(n2, n3, n4)(elem)) // !!! explicit type argument required under cc
184+
def fill[A](n1: Int, n2: Int, n3: Int, n4: Int)(elem: => A): CC[(CC[CC[CC[A]^{elem}]^{elem}]^{elem}) @uncheckedVariance]^{elem} =
185+
fill(n1)(fill(n2, n3, n4)(elem))
186186

187187
/** Produces a five-dimensional $coll containing the results of some element computation a number of times.
188188
* @param n1 the number of elements in the 1st dimension
@@ -193,9 +193,8 @@ trait IterableFactory[+CC[_]] extends Serializable, Pure {
193193
* @param elem the element computation
194194
* @return A $coll that contains the results of `n1 x n2 x n3 x n4 x n5` evaluations of `elem`.
195195
*/
196-
def fill[A](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(elem: => A): CC[(CC[CC[CC[CC[A]^{elem}]^{elem}]^{elem}]^{elem}) @uncheckedVariance]^{elem} = // !!! problem with checking rhs under cc
197-
fill[CC[CC[CC[CC[A]^{elem}]^{elem}]^{elem}]^{elem}](n1)(fill(n2, n3, n4, n5)(elem)) // !!! explicit type argument required under cc
198-
196+
def fill[A](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(elem: => A): CC[(CC[CC[CC[CC[A]^{elem}]^{elem}]^{elem}]^{elem}) @uncheckedVariance]^{elem} =
197+
fill(n1)(fill(n2, n3, n4, n5)(elem))
199198

200199
/** Produces a $coll containing values of a given function over a range of integer values starting from 0.
201200
* @param n The number of elements in the $coll
@@ -211,8 +210,8 @@ trait IterableFactory[+CC[_]] extends Serializable, Pure {
211210
* @return A $coll consisting of elements `f(i1, i2)`
212211
* for `0 <= i1 < n1` and `0 <= i2 < n2`.
213212
*/
214-
def tabulate[A](n1: Int, n2: Int)(f: (Int, Int) => A): CC[CC[A] @uncheckedVariance]^{f} = // !!! problem with checking rhs under cc
215-
??? // tabulate(n1)(i1 => tabulate(n2)(f(i1, _)))
213+
def tabulate[A](n1: Int, n2: Int)(f: (Int, Int) => A): CC[(CC[A]^{f}) @uncheckedVariance]^{f} =
214+
tabulate(n1)(i1 => tabulate(n2)(f(i1, _)))
216215

217216
/** Produces a three-dimensional $coll containing values of a given function over ranges of integer values starting from 0.
218217
* @param n1 the number of elements in the 1st dimension
@@ -222,8 +221,8 @@ trait IterableFactory[+CC[_]] extends Serializable, Pure {
222221
* @return A $coll consisting of elements `f(i1, i2, i3)`
223222
* for `0 <= i1 < n1`, `0 <= i2 < n2`, and `0 <= i3 < n3`.
224223
*/
225-
def tabulate[A](n1: Int, n2: Int, n3: Int)(f: (Int, Int, Int) => A): CC[CC[CC[A]] @uncheckedVariance]^{f} = // !!! problem with checking rhs under cc
226-
??? // tabulate(n1)(i1 => tabulate(n2, n3)(f(i1, _, _)))
224+
def tabulate[A](n1: Int, n2: Int, n3: Int)(f: (Int, Int, Int) => A): CC[(CC[CC[A]^{f}]^{f}) @uncheckedVariance]^{f} =
225+
tabulate(n1)(i1 => tabulate(n2, n3)(f(i1, _, _)))
227226

228227
/** Produces a four-dimensional $coll containing values of a given function over ranges of integer values starting from 0.
229228
* @param n1 the number of elements in the 1st dimension
@@ -234,8 +233,8 @@ trait IterableFactory[+CC[_]] extends Serializable, Pure {
234233
* @return A $coll consisting of elements `f(i1, i2, i3, i4)`
235234
* for `0 <= i1 < n1`, `0 <= i2 < n2`, `0 <= i3 < n3`, and `0 <= i4 < n4`.
236235
*/
237-
def tabulate[A](n1: Int, n2: Int, n3: Int, n4: Int)(f: (Int, Int, Int, Int) => A): CC[CC[CC[CC[A]]] @uncheckedVariance]^{f} = // !!! problem with checking rhs under cc
238-
??? // tabulate(n1)(i1 => tabulate(n2, n3, n4)(f(i1, _, _, _)))
236+
def tabulate[A](n1: Int, n2: Int, n3: Int, n4: Int)(f: (Int, Int, Int, Int) => A): CC[(CC[CC[CC[A]^{f}]^{f}]^{f}) @uncheckedVariance]^{f} =
237+
tabulate(n1)(i1 => tabulate(n2, n3, n4)(f(i1, _, _, _)))
239238

240239
/** Produces a five-dimensional $coll containing values of a given function over ranges of integer values starting from 0.
241240
* @param n1 the number of elements in the 1st dimension
@@ -247,8 +246,8 @@ trait IterableFactory[+CC[_]] extends Serializable, Pure {
247246
* @return A $coll consisting of elements `f(i1, i2, i3, i4, i5)`
248247
* for `0 <= i1 < n1`, `0 <= i2 < n2`, `0 <= i3 < n3`, `0 <= i4 < n4`, and `0 <= i5 < n5`.
249248
*/
250-
def tabulate[A](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(f: (Int, Int, Int, Int, Int) => A): CC[CC[CC[CC[CC[A]]]] @uncheckedVariance]^{f} = // !!! problem with checking rhs under cc
251-
??? // tabulate(n1)(i1 => tabulate(n2, n3, n4, n5)(f(i1, _, _, _, _)))
249+
def tabulate[A](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(f: (Int, Int, Int, Int, Int) => A): CC[(CC[CC[CC[CC[A]^{f}]^{f}]^{f}]^{f}) @uncheckedVariance]^{f} =
250+
tabulate(n1)(i1 => tabulate(n2, n3, n4, n5)(f(i1, _, _, _, _)))
252251

253252
/** Concatenates all argument collections into a single $coll.
254253
*

scala2-library-cc/src/scala/collection/Iterable.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ trait IterableOps[+A, +CC[_], +C] extends Any with IterableOnce[A] with Iterable
397397
if (i != headSize)
398398
fail
399399
}
400-
iterableFactory.from(bs.map(_.result())).asInstanceOf // !!! needed for cc
400+
iterableFactory.from(bs.map(_.result()))
401401
}
402402

403403
def filter(pred: A => Boolean): C^{this, pred} = fromSpecific(new View.Filter(this, pred, isFlipped = false))

scala2-library-cc/src/scala/collection/MapView.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ object MapView extends MapViewFactory {
8181

8282
@SerialVersionUID(3L)
8383
object EmptyMapView extends AbstractMapView[Any, Nothing] {
84-
// !!! cc problem: crash when we replace the line with
84+
// !!! cc problem? type mismatch when we replace the line with
8585
// private val EmptyMapView: MapView[Any, Nothing] = new AbstractMapView[Any, Nothing] {
8686
override def get(key: Any): Option[Nothing] = None
8787
override def iterator: Iterator[Nothing] = Iterator.empty[Nothing]

scala2-library-cc/src/scala/collection/concurrent/TrieMap.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,10 +1183,7 @@ private[collection] class TrieMapIterator[K, V](var level: Int, private var ct:
11831183
stack(d) = arr1
11841184
stackpos(d) = -1
11851185
val it = newIterator(level + 1, ct, _mustInit = false)
1186-
val xss: Array[Array[BasicNode]] = it.stack.asInstanceOf
1187-
// !!! cc split into separate xss and asInstanceOf needed because cc gets confused with
1188-
// two-dimensinal invariant arrays
1189-
xss(0) = arr2
1186+
it.stack(0) = arr2
11901187
it.stackpos(0) = -1
11911188
it.depth = 0
11921189
it.advance() // <-- fix it

scala2-library-cc/src/scala/collection/immutable/HashMap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2384,7 +2384,7 @@ private[immutable] final class HashMapBuilder[K, V] extends ReusableBuilder[(K,
23842384
)
23852385
currentValueCursor += 1
23862386
}
2387-
}.asInstanceOf // !!! cc gets confused with representation of capture sets in invariant position
2387+
}
23882388
case hm: collection.mutable.HashMap[K, V] =>
23892389
val iter = hm.nodeIterator
23902390
while (iter.hasNext) {

scala2-library-cc/src/scala/collection/immutable/HashSet.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2101,7 +2101,7 @@ private[collection] final class HashSetBuilder[A] extends ReusableBuilder[A, Has
21012101
)
21022102
currentValueCursor += 1
21032103
}
2104-
}.asInstanceOf // !!! cc gets confused with representation of capture sets in invariant position
2104+
}
21052105
case other =>
21062106
val it = other.iterator
21072107
while(it.hasNext) addOne(it.next())

0 commit comments

Comments
 (0)