Skip to content

Commit 2bcc5a2

Browse files
committed
Copy sources from tests/pos-special/stdlib to scala2-library-cc
1 parent 64f3fdc commit 2bcc5a2

File tree

143 files changed

+2692
-1119
lines changed

Some content is hidden

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

143 files changed

+2692
-1119
lines changed

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package collection
1515

1616
import java.lang.Math.{max, min}
1717
import java.util.Arrays
18+
import language.experimental.captureChecking
1819

1920
import scala.Predef.{ // unimport all array-related implicit conversions to avoid triggering them accidentally
2021
genericArrayOps => _,
@@ -116,7 +117,7 @@ object ArrayOps {
116117
flatMap[B](x => asIterable(f(x)))
117118

118119
/** Creates a new non-strict filter which combines this filter with the given predicate. */
119-
def withFilter(q: A => Boolean): WithFilter[A] = new WithFilter[A](a => p(a) && q(a), xs)
120+
def withFilter(q: A => Boolean): WithFilter[A]^{this, q} = new WithFilter[A](a => p(a) && q(a), xs)
120121
}
121122

122123
@SerialVersionUID(3L)
@@ -366,7 +367,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
366367
def inits: Iterator[Array[A]] = iterateUntilEmpty(xs => new ArrayOps(xs).init)
367368

368369
// A helper for tails and inits.
369-
private[this] def iterateUntilEmpty(f: Array[A] => Array[A]): Iterator[Array[A]] =
370+
private[this] def iterateUntilEmpty(f: Array[A] => Array[A]): Iterator[Array[A]]^{f} =
370371
Iterator.iterate(xs)(f).takeWhile(x => x.length != 0) ++ Iterator.single(Array.empty[A])
371372

372373
/** An array containing the first `n` elements of this array. */
@@ -663,7 +664,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
663664
* All these operations apply to those elements of this array
664665
* which satisfy the predicate `p`.
665666
*/
666-
def withFilter(p: A => Boolean): ArrayOps.WithFilter[A] = new ArrayOps.WithFilter[A](p, xs)
667+
def withFilter(p: A => Boolean): ArrayOps.WithFilter[A]^{p} = new ArrayOps.WithFilter[A](p, xs)
667668

668669
/** Finds index of first occurrence of some value in this array after or at some start index.
669670
*
@@ -1345,7 +1346,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
13451346
* @tparam B the type of the elements after being transformed by `f`
13461347
* @return a new array consisting of all the elements of this array without duplicates.
13471348
*/
1348-
def distinctBy[B](f: A => B): Array[A] =
1349+
def distinctBy[B](f: A -> B): Array[A] =
13491350
ArrayBuilder.make[A].addAll(iterator.distinctBy(f)).result()
13501351

13511352
/** A copy of this array with an element value appended until a given target length is reached.

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import java.io.{ObjectInputStream, ObjectOutputStream}
1818
import scala.annotation.nowarn
1919
import scala.collection.Stepper.EfficientSplit
2020
import scala.collection.mutable.Builder
21-
21+
import language.experimental.captureChecking
2222

2323
/** Base type of bitsets.
2424
*
@@ -33,7 +33,7 @@ import scala.collection.mutable.Builder
3333
* @define Coll `BitSet`
3434
*/
3535
trait BitSet extends SortedSet[Int] with BitSetOps[BitSet] {
36-
override protected def fromSpecific(coll: IterableOnce[Int]): BitSet = bitSetFactory.fromSpecific(coll)
36+
override protected def fromSpecific(coll: IterableOnce[Int]^): BitSet = bitSetFactory.fromSpecific(coll)
3737
override protected def newSpecificBuilder: Builder[Int, BitSet] = bitSetFactory.newBuilder
3838
override def empty: BitSet = bitSetFactory.empty
3939
@nowarn("""cat=deprecation&origin=scala\.collection\.Iterable\.stringPrefix""")
@@ -48,7 +48,7 @@ object BitSet extends SpecificIterableFactory[Int, BitSet] {
4848

4949
def empty: BitSet = immutable.BitSet.empty
5050
def newBuilder: Builder[Int, BitSet] = immutable.BitSet.newBuilder
51-
def fromSpecific(it: IterableOnce[Int]): BitSet = immutable.BitSet.fromSpecific(it)
51+
def fromSpecific(it: IterableOnce[Int]^): BitSet = immutable.BitSet.fromSpecific(it)
5252

5353
@SerialVersionUID(3L)
5454
private[collection] abstract class SerializationProxy(@transient protected val coll: BitSet) extends Serializable {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
package scala.collection
14-
14+
import language.experimental.captureChecking
1515

1616
/** Buffered iterators are iterators which provide a method `head`
1717
* that inspects the next element without discarding it.

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

+19-13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import scala.annotation.implicitNotFound
1616
import scala.collection.mutable.Builder
1717
import scala.collection.immutable.WrappedString
1818
import scala.reflect.ClassTag
19+
import language.experimental.captureChecking
20+
import caps.unsafe.unsafeAssumePure
1921

2022
/** Builds a collection of type `C` from elements of type `A` when a source collection of type `From` is available.
2123
* Implicit instances of `BuildFrom` are available for all collection types.
@@ -26,7 +28,11 @@ import scala.reflect.ClassTag
2628
*/
2729
@implicitNotFound(msg = "Cannot construct a collection of type ${C} with elements of type ${A} based on a collection of type ${From}.")
2830
trait BuildFrom[-From, -A, +C] extends Any { self =>
29-
def fromSpecific(from: From)(it: IterableOnce[A]): C
31+
def fromSpecific(from: From)(it: IterableOnce[A]^): C
32+
// !!! this is wrong, we need two versions of fromSpecific; one mapping
33+
// to C^{it} when C is an Iterable, and one mapping to C when C is a Seq, Map, or Set.
34+
// But that requires a large scale refactoring of BuildFrom. The unsafeAssumePure
35+
// calls in this file are needed to sweep that problem under the carpet.
3036

3137
/** Get a Builder for the collection. For non-strict collection types this will use an intermediate buffer.
3238
* Building collections with `fromSpecific` is preferred because it can be lazy for lazy collections. */
@@ -37,7 +43,7 @@ trait BuildFrom[-From, -A, +C] extends Any { self =>
3743

3844
/** Partially apply a BuildFrom to a Factory */
3945
def toFactory(from: From): Factory[A, C] = new Factory[A, C] {
40-
def fromSpecific(it: IterableOnce[A]): C = self.fromSpecific(from)(it)
46+
def fromSpecific(it: IterableOnce[A]^): C = self.fromSpecific(from)(it)
4147
def newBuilder: Builder[A, C] = self.newBuilder(from)
4248
}
4349
}
@@ -48,42 +54,42 @@ object BuildFrom extends BuildFromLowPriority1 {
4854
implicit def buildFromMapOps[CC[X, Y] <: Map[X, Y] with MapOps[X, Y, CC, _], K0, V0, K, V]: BuildFrom[CC[K0, V0] with Map[K0, V0], (K, V), CC[K, V] with Map[K, V]] = new BuildFrom[CC[K0, V0], (K, V), CC[K, V]] {
4955
//TODO: Reuse a prototype instance
5056
def newBuilder(from: CC[K0, V0]): Builder[(K, V), CC[K, V]] = (from: MapOps[K0, V0, CC, _]).mapFactory.newBuilder[K, V]
51-
def fromSpecific(from: CC[K0, V0])(it: IterableOnce[(K, V)]): CC[K, V] = (from: MapOps[K0, V0, CC, _]).mapFactory.from(it)
57+
def fromSpecific(from: CC[K0, V0])(it: IterableOnce[(K, V)]^): CC[K, V] = (from: MapOps[K0, V0, CC, _]).mapFactory.from(it)
5258
}
5359

5460
/** Build the source collection type from a SortedMapOps */
5561
implicit def buildFromSortedMapOps[CC[X, Y] <: SortedMap[X, Y] with SortedMapOps[X, Y, CC, _], K0, V0, K : Ordering, V]: BuildFrom[CC[K0, V0] with SortedMap[K0, V0], (K, V), CC[K, V] with SortedMap[K, V]] = new BuildFrom[CC[K0, V0], (K, V), CC[K, V]] {
5662
def newBuilder(from: CC[K0, V0]): Builder[(K, V), CC[K, V]] = (from: SortedMapOps[K0, V0, CC, _]).sortedMapFactory.newBuilder[K, V]
57-
def fromSpecific(from: CC[K0, V0])(it: IterableOnce[(K, V)]): CC[K, V] = (from: SortedMapOps[K0, V0, CC, _]).sortedMapFactory.from(it)
63+
def fromSpecific(from: CC[K0, V0])(it: IterableOnce[(K, V)]^): CC[K, V] = (from: SortedMapOps[K0, V0, CC, _]).sortedMapFactory.from(it)
5864
}
5965

6066
implicit def buildFromBitSet[C <: BitSet with BitSetOps[C]]: BuildFrom[C, Int, C] =
6167
new BuildFrom[C, Int, C] {
62-
def fromSpecific(from: C)(it: IterableOnce[Int]): C = from.bitSetFactory.fromSpecific(it)
68+
def fromSpecific(from: C)(it: IterableOnce[Int]^): C = from.bitSetFactory.fromSpecific(it)
6369
def newBuilder(from: C): Builder[Int, C] = from.bitSetFactory.newBuilder
6470
}
6571

6672
implicit val buildFromString: BuildFrom[String, Char, String] =
6773
new BuildFrom[String, Char, String] {
68-
def fromSpecific(from: String)(it: IterableOnce[Char]): String = Factory.stringFactory.fromSpecific(it)
74+
def fromSpecific(from: String)(it: IterableOnce[Char]^): String = Factory.stringFactory.fromSpecific(it)
6975
def newBuilder(from: String): Builder[Char, String] = Factory.stringFactory.newBuilder
7076
}
7177

7278
implicit val buildFromWrappedString: BuildFrom[WrappedString, Char, WrappedString] =
7379
new BuildFrom[WrappedString, Char, WrappedString] {
74-
def fromSpecific(from: WrappedString)(it: IterableOnce[Char]): WrappedString = WrappedString.fromSpecific(it)
80+
def fromSpecific(from: WrappedString)(it: IterableOnce[Char]^): WrappedString = WrappedString.fromSpecific(it)
7581
def newBuilder(from: WrappedString): mutable.Builder[Char, WrappedString] = WrappedString.newBuilder
7682
}
7783

7884
implicit def buildFromArray[A : ClassTag]: BuildFrom[Array[_], A, Array[A]] =
7985
new BuildFrom[Array[_], A, Array[A]] {
80-
def fromSpecific(from: Array[_])(it: IterableOnce[A]): Array[A] = Factory.arrayFactory[A].fromSpecific(it)
86+
def fromSpecific(from: Array[_])(it: IterableOnce[A]^): Array[A] = Factory.arrayFactory[A].fromSpecific(it)
8187
def newBuilder(from: Array[_]): Builder[A, Array[A]] = Factory.arrayFactory[A].newBuilder
8288
}
8389

8490
implicit def buildFromView[A, B]: BuildFrom[View[A], B, View[B]] =
8591
new BuildFrom[View[A], B, View[B]] {
86-
def fromSpecific(from: View[A])(it: IterableOnce[B]): View[B] = View.from(it)
92+
def fromSpecific(from: View[A])(it: IterableOnce[B]^): View[B] = View.from(it).unsafeAssumePure
8793
def newBuilder(from: View[A]): Builder[B, View[B]] = View.newBuilder
8894
}
8995

@@ -97,12 +103,12 @@ trait BuildFromLowPriority1 extends BuildFromLowPriority2 {
97103
// test in test/junit/scala/collection/BuildFromTest.scala and discussion in https://github.com/scala/scala/pull/10209
98104
implicit def buildFromSortedSetOps[CC[X] <: SortedSet[X] with SortedSetOps[X, CC, _], A0, A : Ordering]: BuildFrom[CC[A0] with SortedSet[A0], A, CC[A] with SortedSet[A]] = new BuildFrom[CC[A0], A, CC[A]] {
99105
def newBuilder(from: CC[A0]): Builder[A, CC[A]] = (from: SortedSetOps[A0, CC, _]).sortedIterableFactory.newBuilder[A]
100-
def fromSpecific(from: CC[A0])(it: IterableOnce[A]): CC[A] = (from: SortedSetOps[A0, CC, _]).sortedIterableFactory.from(it)
106+
def fromSpecific(from: CC[A0])(it: IterableOnce[A]^): CC[A] = (from: SortedSetOps[A0, CC, _]).sortedIterableFactory.from(it)
101107
}
102108

103109
implicit def fallbackStringCanBuildFrom[A]: BuildFrom[String, A, immutable.IndexedSeq[A]] =
104110
new BuildFrom[String, A, immutable.IndexedSeq[A]] {
105-
def fromSpecific(from: String)(it: IterableOnce[A]): immutable.IndexedSeq[A] = immutable.IndexedSeq.from(it)
111+
def fromSpecific(from: String)(it: IterableOnce[A]^): immutable.IndexedSeq[A] = immutable.IndexedSeq.from(it)
106112
def newBuilder(from: String): Builder[A, immutable.IndexedSeq[A]] = immutable.IndexedSeq.newBuilder[A]
107113
}
108114
}
@@ -112,11 +118,11 @@ trait BuildFromLowPriority2 {
112118
implicit def buildFromIterableOps[CC[X] <: Iterable[X] with IterableOps[X, CC, _], A0, A]: BuildFrom[CC[A0], A, CC[A]] = new BuildFrom[CC[A0], A, CC[A]] {
113119
//TODO: Reuse a prototype instance
114120
def newBuilder(from: CC[A0]): Builder[A, CC[A]] = (from: IterableOps[A0, CC, _]).iterableFactory.newBuilder[A]
115-
def fromSpecific(from: CC[A0])(it: IterableOnce[A]): CC[A] = (from: IterableOps[A0, CC, _]).iterableFactory.from(it)
121+
def fromSpecific(from: CC[A0])(it: IterableOnce[A]^): CC[A] = (from: IterableOps[A0, CC, _]).iterableFactory.from(it).unsafeAssumePure
116122
}
117123

118124
implicit def buildFromIterator[A]: BuildFrom[Iterator[_], A, Iterator[A]] = new BuildFrom[Iterator[_], A, Iterator[A]] {
119125
def newBuilder(from: Iterator[_]): mutable.Builder[A, Iterator[A]] = Iterator.newBuilder
120-
def fromSpecific(from: Iterator[_])(it: IterableOnce[A]): Iterator[A] = Iterator.from(it)
126+
def fromSpecific(from: Iterator[_])(it: IterableOnce[A]^): Iterator[A] = Iterator.from(it).unsafeAssumePure
121127
}
122128
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
package scala
1414
package collection
15-
15+
import language.experimental.captureChecking
1616

1717
/** A default map which builds a default `immutable.Map` implementation for all
1818
* transformations.

0 commit comments

Comments
 (0)