summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorSeth Tisue <seth@tisue.net>2017-02-17 06:56:11 -0800
committerGitHub <noreply@github.com>2017-02-17 06:56:11 -0800
commit71a8a4429f3ca004ebbf88f78146691bb9f084d9 (patch)
treea766ac4fab6d91d3fad2789ba5bf8d85775aabba /src/library
parent04c45e15f198c3e33b0e6709fb8ca5267f129fac (diff)
parentc8b80053bd41b5a6cf4c03b2a709099ae1b668d7 (diff)
downloadscala-71a8a4429f3ca004ebbf88f78146691bb9f084d9.tar.gz
scala-71a8a4429f3ca004ebbf88f78146691bb9f084d9.tar.bz2
scala-71a8a4429f3ca004ebbf88f78146691bb9f084d9.zip
Merge branch '2.12.x' into merge-2.11.x-to-2.12.x-20170214
Diffstat (limited to 'src/library')
-rw-r--r--src/library/rootdoc.txt3
-rw-r--r--src/library/scala/annotation/showAsInfix.scala27
-rw-r--r--src/library/scala/collection/BitSetLike.scala16
-rw-r--r--src/library/scala/collection/GenTraversableLike.scala24
-rw-r--r--src/library/scala/collection/IterableLike.scala12
-rw-r--r--src/library/scala/collection/Iterator.scala59
-rw-r--r--src/library/scala/collection/concurrent/TrieMap.scala27
-rw-r--r--src/library/scala/sys/process/ProcessBuilder.scala4
8 files changed, 106 insertions, 66 deletions
diff --git a/src/library/rootdoc.txt b/src/library/rootdoc.txt
index d78df01046..0aef41c4da 100644
--- a/src/library/rootdoc.txt
+++ b/src/library/rootdoc.txt
@@ -44,8 +44,7 @@ Additional parts of the standard library are shipped as separate libraries. Thes
- [[scala.reflect `scala.reflect`]] - Scala's reflection API (scala-reflect.jar)
- [[scala.xml `scala.xml`]] - XML parsing, manipulation, and serialization (scala-xml.jar)
- [[scala.swing `scala.swing`]] - A convenient wrapper around Java's GUI framework called Swing (scala-swing.jar)
- - [[scala.util.parsing `scala.util.parsing`]] - [[scala.util.parsing.combinator Parser combinators]], including an
- example implementation of a [[scala.util.parsing.json JSON parser]] (scala-parser-combinators.jar)
+ - [[scala.util.parsing `scala.util.parsing`]] - Parser combinators (scala-parser-combinators.jar)
== Automatic imports ==
diff --git a/src/library/scala/annotation/showAsInfix.scala b/src/library/scala/annotation/showAsInfix.scala
new file mode 100644
index 0000000000..6c25e08efa
--- /dev/null
+++ b/src/library/scala/annotation/showAsInfix.scala
@@ -0,0 +1,27 @@
+package scala.annotation
+
+/**
+ * This annotation configures how Scala prints two-parameter generic types.
+ *
+ * By default, types with symbolic names are printed infix; while types without
+ * them are printed using the regular generic type syntax.
+ *
+ * Example of usage:
+ {{{
+ scala> class Map[T, U]
+ defined class Map
+
+ scala> def foo: Int Map Int = ???
+ foo: Map[Int,Int]
+
+ scala> @showAsInfix class Map[T, U]
+ defined class Map
+
+ scala> def foo: Int Map Int = ???
+ foo: Int Map Int
+ }}}
+ *
+ * @param enabled whether to show this type as an infix type operator.
+ * @since 2.12.2
+ */
+class showAsInfix(enabled: Boolean = true) extends annotation.StaticAnnotation \ No newline at end of file
diff --git a/src/library/scala/collection/BitSetLike.scala b/src/library/scala/collection/BitSetLike.scala
index 209b00ebf9..f0a70170c2 100644
--- a/src/library/scala/collection/BitSetLike.scala
+++ b/src/library/scala/collection/BitSetLike.scala
@@ -77,26 +77,26 @@ trait BitSetLike[+This <: BitSetLike[This] with SortedSet[Int]] extends SortedSe
def rangeImpl(from: Option[Int], until: Option[Int]): This = {
val a = toBitMask
val len = a.length
- if(from.isDefined) {
+ if (from.isDefined) {
var f = from.get
var pos = 0
- while(f >= 64 && pos < len) {
+ while (f >= 64 && pos < len) {
f -= 64
a(pos) = 0
pos += 1
}
- if(f > 0 && pos < len) a(pos) &= ~((1L << f)-1)
+ if (f > 0 && pos < len) a(pos) &= ~((1L << f)-1)
}
- if(until.isDefined) {
+ if (until.isDefined) {
val u = until.get
val w = u / 64
val b = u % 64
var clearw = w+1
- while(clearw < len) {
+ while (clearw < len) {
a(clearw) = 0
clearw += 1
}
- if(w < len) a(w) &= (1L << b)-1
+ if (w < len) a(w) &= (1L << b)-1
}
fromBitMaskNoCopy(a)
}
@@ -220,7 +220,7 @@ trait BitSetLike[+This <: BitSetLike[This] with SortedSet[Int]] extends SortedSe
while (i >= 0) {
val wi = word(i)
if (wi != 0L) return WordLength*i + 63 - java.lang.Long.numberOfLeadingZeros(wi)
- i += 1
+ i -= 1
}
throw new NoSuchElementException("Empty BitSet")
}
@@ -230,7 +230,7 @@ trait BitSetLike[+This <: BitSetLike[This] with SortedSet[Int]] extends SortedSe
var pre = ""
val max = nwords * WordLength
var i = 0
- while(i != max) {
+ while (i != max) {
if (contains(i)) {
sb append pre append i
pre = sep
diff --git a/src/library/scala/collection/GenTraversableLike.scala b/src/library/scala/collection/GenTraversableLike.scala
index 1cd126f94f..0ee5542e30 100644
--- a/src/library/scala/collection/GenTraversableLike.scala
+++ b/src/library/scala/collection/GenTraversableLike.scala
@@ -249,30 +249,6 @@ trait GenTraversableLike[+A, +Repr] extends Any with GenTraversableOnce[A] with
* @param bf $bfinfo
* @return a new collection of type `That` which contains all elements
* of this $coll followed by all elements of `that`.
- *
- * @usecase def ++[B](that: GenTraversableOnce[B]): $Coll[B]
- * @inheritdoc
- *
- * Example:
- * {{{
- * scala> val a = List(1)
- * a: List[Int] = List(1)
- *
- * scala> val b = List(2)
- * b: List[Int] = List(2)
- *
- * scala> val c = a ++ b
- * c: List[Int] = List(1, 2)
- *
- * scala> val d = List('a')
- * d: List[Char] = List(a)
- *
- * scala> val e = c ++ d
- * e: List[AnyVal] = List(1, 2, a)
- * }}}
- *
- * @return a new $coll which contains all elements of this $coll
- * followed by all elements of `that`.
*/
def ++[B >: A, That](that: GenTraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That
diff --git a/src/library/scala/collection/IterableLike.scala b/src/library/scala/collection/IterableLike.scala
index b89720da78..419206c226 100644
--- a/src/library/scala/collection/IterableLike.scala
+++ b/src/library/scala/collection/IterableLike.scala
@@ -177,14 +177,14 @@ self =>
}
/** Groups elements in fixed size blocks by passing a "sliding window"
- * over them (as opposed to partitioning them, as is done in grouped.)
- * "Sliding window" step is 1 by default.
+ * over them (as opposed to partitioning them, as is done in `grouped`.)
+ * The "sliding window" step is set to one.
* @see [[scala.collection.Iterator]], method `sliding`
*
* @param size the number of elements per group
* @return An iterator producing ${coll}s of size `size`, except the
- * last and the only element will be truncated if there are
- * fewer elements than size.
+ * last element (which may be the only element) will be truncated
+ * if there are fewer than `size` elements remaining to be grouped.
*/
def sliding(size: Int): Iterator[Repr] = sliding(size, 1)
@@ -196,8 +196,8 @@ self =>
* @param step the distance between the first elements of successive
* groups
* @return An iterator producing ${coll}s of size `size`, except the
- * last and the only element will be truncated if there are
- * fewer elements than size.
+ * last element (which may be the only element) will be truncated
+ * if there are fewer than `size` elements remaining to be grouped.
*/
def sliding(size: Int, step: Int): Iterator[Repr] =
for (xs <- iterator.sliding(size, step)) yield {
diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala
index d000d22f72..809e851494 100644
--- a/src/library/scala/collection/Iterator.scala
+++ b/src/library/scala/collection/Iterator.scala
@@ -1091,7 +1091,7 @@ trait Iterator[+A] extends TraversableOnce[A] {
extends AbstractIterator[Seq[B]]
with Iterator[Seq[B]] {
- require(size >= 1 && step >= 1, "size=%d and step=%d, but both must be positive".format(size, step))
+ require(size >= 1 && step >= 1, f"size=$size%d and step=$step%d, but both must be positive")
private[this] var buffer: ArrayBuffer[B] = ArrayBuffer() // the buffer
private[this] var filled = false // whether the buffer is "hot"
@@ -1099,30 +1099,30 @@ trait Iterator[+A] extends TraversableOnce[A] {
private[this] var pad: Option[() => B] = None // what to pad short sequences with
/** Public functions which can be used to configure the iterator before use.
- *
- * Pads the last segment if necessary so that all segments will
- * have the same size.
- *
- * @param x The element that will be appended to the last segment, if necessary.
- * @return The same iterator, and ''not'' a new iterator.
- * @note This method mutates the iterator it is called on, which can be safely used afterwards.
- * @note This method is mutually exclusive with `withPartial(true)`.
- */
+ *
+ * Pads the last segment if necessary so that all segments will
+ * have the same size.
+ *
+ * @param x The element that will be appended to the last segment, if necessary.
+ * @return The same iterator, and ''not'' a new iterator.
+ * @note This method mutates the iterator it is called on, which can be safely used afterwards.
+ * @note This method is mutually exclusive with `withPartial(true)`.
+ */
def withPadding(x: => B): this.type = {
pad = Some(() => x)
this
}
- /** Public functions which can be used to configure the iterator before use.
- *
- * Select whether the last segment may be returned with less than `size`
- * elements. If not, some elements of the original iterator may not be
- * returned at all.
- *
- * @param x `true` if partial segments may be returned, `false` otherwise.
- * @return The same iterator, and ''not'' a new iterator.
- * @note This method mutates the iterator it is called on, which can be safely used afterwards.
- * @note This method is mutually exclusive with `withPadding`.
- */
+ /** Public functions which can be used to configure the iterator before use.
+ *
+ * Select whether the last segment may be returned with less than `size`
+ * elements. If not, some elements of the original iterator may not be
+ * returned at all.
+ *
+ * @param x `true` if partial segments may be returned, `false` otherwise.
+ * @return The same iterator, and ''not'' a new iterator.
+ * @note This method mutates the iterator it is called on, which can be safely used afterwards.
+ * @note This method is mutually exclusive with `withPadding`.
+ */
def withPartial(x: Boolean): this.type = {
_partial = x
if (_partial == true) // reset pad since otherwise it will take precedence
@@ -1231,9 +1231,15 @@ trait Iterator[+A] extends TraversableOnce[A] {
new GroupedIterator[B](self, size, size)
/** Returns an iterator which presents a "sliding window" view of
- * another iterator. The first argument is the window size, and
- * the second is how far to advance the window on each iteration;
- * defaults to `1`. Example usages:
+ * this iterator. The first argument is the window size, and
+ * the second argument `step` is how far to advance the window
+ * on each iteration. The `step` defaults to `1`.
+ *
+ * The default `GroupedIterator` can be configured to either
+ * pad a partial result to size `size` or suppress the partial
+ * result entirely.
+ *
+ * Example usages:
* {{{
* // Returns List(List(1, 2, 3), List(2, 3, 4), List(3, 4, 5))
* (1 to 5).iterator.sliding(3).toList
@@ -1247,6 +1253,11 @@ trait Iterator[+A] extends TraversableOnce[A] {
* (1 to 5).iterator.sliding(4, 3).withPadding(it2.next).toList
* }}}
*
+ * @return An iterator producing `Seq[B]`s of size `size`, except the
+ * last element (which may be the only element) will be truncated
+ * if there are fewer than `size` elements remaining to be grouped.
+ * This behavior can be configured.
+ *
* @note Reuse: $consumesAndProducesIterator
*/
def sliding[B >: A](size: Int, step: Int = 1): GroupedIterator[B] =
diff --git a/src/library/scala/collection/concurrent/TrieMap.scala b/src/library/scala/collection/concurrent/TrieMap.scala
index 769d7b0dac..fe0b5c4f0e 100644
--- a/src/library/scala/collection/concurrent/TrieMap.scala
+++ b/src/library/scala/collection/concurrent/TrieMap.scala
@@ -932,6 +932,33 @@ extends scala.collection.concurrent.Map[K, V]
if (nonReadOnly) readOnlySnapshot().iterator
else new TrieMapIterator(0, this)
+ ////////////////////////////////////////////////////////////////////////////
+ //
+ // SI-10177 These methods need overrides as the inherited implementations
+ // call `.iterator` more than once, which doesn't guarantee a coherent
+ // view of the data if there is a concurrent writer
+ // Note that the we don't need overrides for keysIterator or valuesIterator
+ // TrieMapTest validates the behaviour.
+ override def values: Iterable[V] = {
+ if (nonReadOnly) readOnlySnapshot().values
+ else super.values
+ }
+ override def keySet: Set[K] = {
+ if (nonReadOnly) readOnlySnapshot().keySet
+ else super.keySet
+ }
+ override def filterKeys(p: K => Boolean): collection.Map[K, V] = {
+ if (nonReadOnly) readOnlySnapshot().filterKeys(p)
+ else super.filterKeys(p)
+ }
+ override def mapValues[W](f: V => W): collection.Map[K, W] = {
+ if (nonReadOnly) readOnlySnapshot().mapValues(f)
+ else super.mapValues(f)
+ }
+ // END extra overrides
+ ///////////////////////////////////////////////////////////////////
+
+
private def cachedSize() = {
val r = RDCSS_READ_ROOT()
r.cachedSize(this)
diff --git a/src/library/scala/sys/process/ProcessBuilder.scala b/src/library/scala/sys/process/ProcessBuilder.scala
index 8288d8d480..b7966b0341 100644
--- a/src/library/scala/sys/process/ProcessBuilder.scala
+++ b/src/library/scala/sys/process/ProcessBuilder.scala
@@ -186,7 +186,7 @@ trait ProcessBuilder extends Source with Sink {
def lineStream(log: ProcessLogger): Stream[String]
/** Deprecated (renamed). Use `lineStream(log: ProcessLogger)` instead. */
- @deprecated("use stream instead", "2.11.0")
+ @deprecated("use lineStream instead", "2.11.0")
def lines(log: ProcessLogger): Stream[String] = lineStream(log)
/** Starts the process represented by this builder. The output is returned as
@@ -210,7 +210,7 @@ trait ProcessBuilder extends Source with Sink {
def lineStream_!(log: ProcessLogger): Stream[String]
/** Deprecated (renamed). Use `lineStream_!(log: ProcessLogger)` instead. */
- @deprecated("use stream_! instead", "2.11.0")
+ @deprecated("use lineStream_! instead", "2.11.0")
def lines_!(log: ProcessLogger): Stream[String] = lineStream_!(log)
/** Starts the process represented by this builder, blocks until it exits, and