diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-06-07 15:44:04 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-06-08 15:32:46 +0200 |
commit | bc5f42f51982eb473075bbd2f474a5d628813031 (patch) | |
tree | a57578c5a21ced5ed38c1a098646fa95ea88f5c2 /src/library | |
parent | 07f7baa21c165d6c2302a8ea26c475968e7d775e (diff) | |
download | scala-bc5f42f51982eb473075bbd2f474a5d628813031.tar.gz scala-bc5f42f51982eb473075bbd2f474a5d628813031.tar.bz2 scala-bc5f42f51982eb473075bbd2f474a5d628813031.zip |
removes array tags
Before 2.10 we had a notion of ClassManifest that could be used to retain
erasures of abstract types (type parameters, abstract type members) for
being used at runtime.
With the advent of ClassManifest (and its subtype Manifest)
it became possible to write:
def mkGenericArray[T: Manifest] = Array[T]()
When compiling array instantiation, scalac would use a ClassManifest
implicit parameter from scope (in this case, provided by a context bound)
to remember Ts that have been passed to invoke mkGenericArray and
use that information to instantiate arrays at runtime (via Java reflection).
When redesigning manifests into what is now known as type tags, we decided
to explore a notion of ArrayTags that would stand for abstract and pure array
creators. Sure, ClassManifests were perfectly fine for this job, but they did
too much - technically speaking, one doesn't necessarily need a java.lang.Class
to create an array. Depending on a platform, e.g. within JavaScript runtime,
one would want to use a different mechanism.
As tempting as this idea was, it has also proven to be problematic.
First, it created an extra abstraction inside the compiler. Along with class tags
and type tags, we had a third flavor of tags - array tags. This has threaded the
additional complexity though implicits and typers.
Second, consequently, when redesigning tags multiple times over the course of
Scala 2.10.0 development, we had to carry this extra abstraction with us, which
exacerbated the overall feeling towards array tags.
Finally, array tags didn't fit into the naming scheme we had for tags.
Both class tags and type tags sound logical, because, they are descriptors for
the things they are supposed to tag, according to their names.
However array tags are the odd ones, because they don't actually tag any arrays.
As funny as it might sound, the naming problem was the last straw
that made us do away with the array tags. Hence this commit.
Diffstat (limited to 'src/library')
29 files changed, 131 insertions, 174 deletions
diff --git a/src/library/scala/Array.scala b/src/library/scala/Array.scala index e7cf399fa4..6784b630c7 100644 --- a/src/library/scala/Array.scala +++ b/src/library/scala/Array.scala @@ -12,7 +12,7 @@ import scala.collection.generic._ import scala.collection.{ mutable, immutable } import mutable.{ ArrayBuilder, ArraySeq } import compat.Platform.arraycopy -import scala.reflect.ArrayTag +import scala.reflect.ClassTag import scala.runtime.ScalaRunTime.{ array_apply, array_update } /** Contains a fallback builder for arrays when the element type @@ -48,7 +48,7 @@ class FallbackArrayBuilding { * @version 1.0 */ object Array extends FallbackArrayBuilding { - implicit def canBuildFrom[T](implicit t: ArrayTag[T]): CanBuildFrom[Array[_], T, Array[T]] = + implicit def canBuildFrom[T](implicit t: ClassTag[T]): CanBuildFrom[Array[_], T, Array[T]] = new CanBuildFrom[Array[_], T, Array[T]] { def apply(from: Array[_]) = ArrayBuilder.make[T]()(t) def apply() = ArrayBuilder.make[T]()(t) @@ -57,7 +57,7 @@ object Array extends FallbackArrayBuilding { /** * Returns a new [[scala.collection.mutable.ArrayBuilder]]. */ - def newBuilder[T](implicit t: ArrayTag[T]): ArrayBuilder[T] = ArrayBuilder.make[T]()(t) + def newBuilder[T](implicit t: ClassTag[T]): ArrayBuilder[T] = ArrayBuilder.make[T]()(t) private def slowcopy(src : AnyRef, srcPos : Int, @@ -98,14 +98,14 @@ object Array extends FallbackArrayBuilding { } /** Returns an array of length 0 */ - def empty[T: ArrayTag]: Array[T] = new Array[T](0) + def empty[T: ClassTag]: Array[T] = new Array[T](0) /** Creates an array with given elements. * * @param xs the elements to put in the array * @return an array containing all elements from xs. */ - def apply[T: ArrayTag](xs: T*): Array[T] = { + def apply[T: ClassTag](xs: T*): Array[T] = { val array = new Array[T](xs.length) var i = 0 for (x <- xs.iterator) { array(i) = x; i += 1 } @@ -194,23 +194,23 @@ object Array extends FallbackArrayBuilding { } /** Creates array with given dimensions */ - def ofDim[T: ArrayTag](n1: Int): Array[T] = + def ofDim[T: ClassTag](n1: Int): Array[T] = new Array[T](n1) /** Creates a 2-dimensional array */ - def ofDim[T: ArrayTag](n1: Int, n2: Int): Array[Array[T]] = { + def ofDim[T: ClassTag](n1: Int, n2: Int): Array[Array[T]] = { val arr: Array[Array[T]] = (new Array[Array[T]](n1): Array[Array[T]]) for (i <- 0 until n1) arr(i) = new Array[T](n2) arr // tabulate(n1)(_ => ofDim[T](n2)) } /** Creates a 3-dimensional array */ - def ofDim[T: ArrayTag](n1: Int, n2: Int, n3: Int): Array[Array[Array[T]]] = + def ofDim[T: ClassTag](n1: Int, n2: Int, n3: Int): Array[Array[Array[T]]] = tabulate(n1)(_ => ofDim[T](n2, n3)) /** Creates a 4-dimensional array */ - def ofDim[T: ArrayTag](n1: Int, n2: Int, n3: Int, n4: Int): Array[Array[Array[Array[T]]]] = + def ofDim[T: ClassTag](n1: Int, n2: Int, n3: Int, n4: Int): Array[Array[Array[Array[T]]]] = tabulate(n1)(_ => ofDim[T](n2, n3, n4)) /** Creates a 5-dimensional array */ - def ofDim[T: ArrayTag](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int): Array[Array[Array[Array[Array[T]]]]] = + def ofDim[T: ClassTag](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int): Array[Array[Array[Array[Array[T]]]]] = tabulate(n1)(_ => ofDim[T](n2, n3, n4, n5)) /** Concatenates all arrays into a single array. @@ -218,7 +218,7 @@ object Array extends FallbackArrayBuilding { * @param xss the given arrays * @return the array created from concatenating `xss` */ - def concat[T: ArrayTag](xss: Array[T]*): Array[T] = { + def concat[T: ClassTag](xss: Array[T]*): Array[T] = { val b = newBuilder[T] b.sizeHint(xss.map(_.size).sum) for (xs <- xss) b ++= xs @@ -239,7 +239,7 @@ object Array extends FallbackArrayBuilding { * @return an Array of size n, where each element contains the result of computing * `elem`. */ - def fill[T: ArrayTag](n: Int)(elem: => T): Array[T] = { + def fill[T: ClassTag](n: Int)(elem: => T): Array[T] = { val b = newBuilder[T] b.sizeHint(n) var i = 0 @@ -257,7 +257,7 @@ object Array extends FallbackArrayBuilding { * @param n2 the number of elements in the 2nd dimension * @param elem the element computation */ - def fill[T: ArrayTag](n1: Int, n2: Int)(elem: => T): Array[Array[T]] = + def fill[T: ClassTag](n1: Int, n2: Int)(elem: => T): Array[Array[T]] = tabulate(n1)(_ => fill(n2)(elem)) /** Returns a three-dimensional array that contains the results of some element @@ -268,7 +268,7 @@ object Array extends FallbackArrayBuilding { * @param n3 the number of elements in the 3nd dimension * @param elem the element computation */ - def fill[T: ArrayTag](n1: Int, n2: Int, n3: Int)(elem: => T): Array[Array[Array[T]]] = + def fill[T: ClassTag](n1: Int, n2: Int, n3: Int)(elem: => T): Array[Array[Array[T]]] = tabulate(n1)(_ => fill(n2, n3)(elem)) /** Returns a four-dimensional array that contains the results of some element @@ -280,7 +280,7 @@ object Array extends FallbackArrayBuilding { * @param n4 the number of elements in the 4th dimension * @param elem the element computation */ - def fill[T: ArrayTag](n1: Int, n2: Int, n3: Int, n4: Int)(elem: => T): Array[Array[Array[Array[T]]]] = + def fill[T: ClassTag](n1: Int, n2: Int, n3: Int, n4: Int)(elem: => T): Array[Array[Array[Array[T]]]] = tabulate(n1)(_ => fill(n2, n3, n4)(elem)) /** Returns a five-dimensional array that contains the results of some element @@ -293,7 +293,7 @@ object Array extends FallbackArrayBuilding { * @param n5 the number of elements in the 5th dimension * @param elem the element computation */ - def fill[T: ArrayTag](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(elem: => T): Array[Array[Array[Array[Array[T]]]]] = + def fill[T: ClassTag](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(elem: => T): Array[Array[Array[Array[Array[T]]]]] = tabulate(n1)(_ => fill(n2, n3, n4, n5)(elem)) /** Returns an array containing values of a given function over a range of integer @@ -303,7 +303,7 @@ object Array extends FallbackArrayBuilding { * @param f The function computing element values * @return A traversable consisting of elements `f(0),f(1), ..., f(n - 1)` */ - def tabulate[T: ArrayTag](n: Int)(f: Int => T): Array[T] = { + def tabulate[T: ClassTag](n: Int)(f: Int => T): Array[T] = { val b = newBuilder[T] b.sizeHint(n) var i = 0 @@ -321,7 +321,7 @@ object Array extends FallbackArrayBuilding { * @param n2 the number of elements in the 2nd dimension * @param f The function computing element values */ - def tabulate[T: ArrayTag](n1: Int, n2: Int)(f: (Int, Int) => T): Array[Array[T]] = + def tabulate[T: ClassTag](n1: Int, n2: Int)(f: (Int, Int) => T): Array[Array[T]] = tabulate(n1)(i1 => tabulate(n2)(f(i1, _))) /** Returns a three-dimensional array containing values of a given function @@ -332,7 +332,7 @@ object Array extends FallbackArrayBuilding { * @param n3 the number of elements in the 3rd dimension * @param f The function computing element values */ - def tabulate[T: ArrayTag](n1: Int, n2: Int, n3: Int)(f: (Int, Int, Int) => T): Array[Array[Array[T]]] = + def tabulate[T: ClassTag](n1: Int, n2: Int, n3: Int)(f: (Int, Int, Int) => T): Array[Array[Array[T]]] = tabulate(n1)(i1 => tabulate(n2, n3)(f(i1, _, _))) /** Returns a four-dimensional array containing values of a given function @@ -344,7 +344,7 @@ object Array extends FallbackArrayBuilding { * @param n4 the number of elements in the 4th dimension * @param f The function computing element values */ - def tabulate[T: ArrayTag](n1: Int, n2: Int, n3: Int, n4: Int)(f: (Int, Int, Int, Int) => T): Array[Array[Array[Array[T]]]] = + def tabulate[T: ClassTag](n1: Int, n2: Int, n3: Int, n4: Int)(f: (Int, Int, Int, Int) => T): Array[Array[Array[Array[T]]]] = tabulate(n1)(i1 => tabulate(n2, n3, n4)(f(i1, _, _, _))) /** Returns a five-dimensional array containing values of a given function @@ -357,7 +357,7 @@ object Array extends FallbackArrayBuilding { * @param n5 the number of elements in the 5th dimension * @param f The function computing element values */ - def tabulate[T: ArrayTag](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(f: (Int, Int, Int, Int, Int) => T): Array[Array[Array[Array[Array[T]]]]] = + def tabulate[T: ClassTag](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(f: (Int, Int, Int, Int, Int) => T): Array[Array[Array[Array[Array[T]]]]] = tabulate(n1)(i1 => tabulate(n2, n3, n4, n5)(f(i1, _, _, _, _))) /** Returns an array containing a sequence of increasing integers in a range. @@ -396,7 +396,7 @@ object Array extends FallbackArrayBuilding { * @param f the function that is repeatedly applied * @return the array returning `len` values in the sequence `start, f(start), f(f(start)), ...` */ - def iterate[T: ArrayTag](start: T, len: Int)(f: T => T): Array[T] = { + def iterate[T: ClassTag](start: T, len: Int)(f: T => T): Array[T] = { val b = newBuilder[T] if (len > 0) { @@ -475,7 +475,7 @@ object Array extends FallbackArrayBuilding { * @define collectExample * @define undefinedorder * @define thatinfo the class of the returned collection. In the standard library configuration, - * `That` is either `Array[B]` if an ArrayTag is available for B or `ArraySeq[B]` otherwise. + * `That` is either `Array[B]` if an ClassTag is available for B or `ArraySeq[B]` otherwise. * @define zipthatinfo $thatinfo * @define bfinfo an implicit value of class `CanBuildFrom` which determines the result class `That` from the current * representation type `Repr` and the new element type `B`. diff --git a/src/library/scala/collection/GenTraversableOnce.scala b/src/library/scala/collection/GenTraversableOnce.scala index 8855c7f783..eadacd9209 100644 --- a/src/library/scala/collection/GenTraversableOnce.scala +++ b/src/library/scala/collection/GenTraversableOnce.scala @@ -8,7 +8,7 @@ package scala.collection -import scala.reflect.ArrayTag +import scala.reflect.ClassTag /** A template trait for all traversable-once objects which may be * traversed in parallel. @@ -461,7 +461,7 @@ trait GenTraversableOnce[+A] extends Any { /** Converts this $coll to an array. * - * @tparam A1 the type of the elements of the array. An `ArrayTag` for + * @tparam A1 the type of the elements of the array. An `ClassTag` for * this type must be available. * @return an array containing all elements of this $coll. * @@ -471,9 +471,9 @@ trait GenTraversableOnce[+A] extends Any { * $willNotTerminateInf * * @return an array containing all elements of this $coll. - * An `ArrayTag` must be available for the element type of this $coll. + * An `ClassTag` must be available for the element type of this $coll. */ - def toArray[A1 >: A: ArrayTag]: Array[A1] + def toArray[A1 >: A: ClassTag]: Array[A1] /** Converts this $coll to a list. * $willNotTerminateInf diff --git a/src/library/scala/collection/Traversable.scala b/src/library/scala/collection/Traversable.scala index cd85ea4d2d..56a73ae62f 100644 --- a/src/library/scala/collection/Traversable.scala +++ b/src/library/scala/collection/Traversable.scala @@ -68,7 +68,7 @@ trait Traversable[+A] extends TraversableLike[A, Traversable[A]] override def copyToBuffer[B >: A](dest: Buffer[B]) override def copyToArray[B >: A](xs: Array[B], start: Int, len: Int) override def copyToArray[B >: A](xs: Array[B], start: Int) - override def toArray[B >: A : ArrayTag]: Array[B] + override def toArray[B >: A : ClassTag]: Array[B] override def toList: List[A] override def toIterable: Iterable[A] override def toSeq: Seq[A] diff --git a/src/library/scala/collection/TraversableOnce.scala b/src/library/scala/collection/TraversableOnce.scala index 4275be949e..386ce2d95a 100644 --- a/src/library/scala/collection/TraversableOnce.scala +++ b/src/library/scala/collection/TraversableOnce.scala @@ -11,7 +11,7 @@ package scala.collection import mutable.{ Buffer, Builder, ListBuffer, ArrayBuffer } import annotation.unchecked.{ uncheckedVariance => uV } import language.{implicitConversions, higherKinds} -import reflect.ArrayTag +import reflect.ClassTag /** A template trait for collections which can be traversed either once only * or one or more times. @@ -228,7 +228,7 @@ trait TraversableOnce[+A] extends Any with GenTraversableOnce[A] { def copyToArray[B >: A](xs: Array[B]): Unit = copyToArray(xs, 0, xs.length) - def toArray[B >: A : ArrayTag]: Array[B] = { + def toArray[B >: A : ClassTag]: Array[B] = { if (isTraversableAgain) { val result = new Array[B](size) copyToArray(result, 0) diff --git a/src/library/scala/collection/TraversableProxyLike.scala b/src/library/scala/collection/TraversableProxyLike.scala index afc9452294..74b30e0faf 100644 --- a/src/library/scala/collection/TraversableProxyLike.scala +++ b/src/library/scala/collection/TraversableProxyLike.scala @@ -12,7 +12,7 @@ package scala.collection import generic._ import mutable.{Buffer, StringBuilder} -import reflect.ArrayTag +import reflect.ClassTag // Methods could be printed by cat TraversableLike.scala | egrep '^ (override )?def' @@ -74,7 +74,7 @@ trait TraversableProxyLike[+A, +Repr <: TraversableLike[A, Repr] with Traversabl override def copyToArray[B >: A](xs: Array[B], start: Int, len: Int) = self.copyToArray(xs, start, len) override def copyToArray[B >: A](xs: Array[B], start: Int) = self.copyToArray(xs, start) override def copyToArray[B >: A](xs: Array[B]) = self.copyToArray(xs) - override def toArray[B >: A: ArrayTag]: Array[B] = self.toArray + override def toArray[B >: A: ClassTag]: Array[B] = self.toArray override def toList: List[A] = self.toList override def toIterable: Iterable[A] = self.toIterable override def toSeq: Seq[A] = self.toSeq diff --git a/src/library/scala/collection/generic/ArrayTagTraversableFactory.scala b/src/library/scala/collection/generic/ClassTagTraversableFactory.scala index bcd73c1eb8..95835d3e90 100644 --- a/src/library/scala/collection/generic/ArrayTagTraversableFactory.scala +++ b/src/library/scala/collection/generic/ClassTagTraversableFactory.scala @@ -10,7 +10,7 @@ package scala.collection package generic import language.higherKinds -import reflect.ArrayTag +import reflect.ClassTag /** A template for companion objects of `ClassTagTraversable` and * subclasses thereof. @@ -22,11 +22,11 @@ import reflect.ArrayTag * @author Aleksandar Prokopec * @since 2.8 */ -abstract class ArrayTagTraversableFactory[CC[X] <: Traversable[X] with GenericArrayTagTraversableTemplate[X, CC]] - extends GenericArrayTagCompanion[CC] { +abstract class ClassTagTraversableFactory[CC[X] <: Traversable[X] with GenericClassTagTraversableTemplate[X, CC]] + extends GenericClassTagCompanion[CC] { - class GenericCanBuildFrom[A](implicit tag: ArrayTag[A]) extends CanBuildFrom[CC[_], A, CC[A]] { - def apply(from: CC[_]) = from.genericArrayTagBuilder[A] + class GenericCanBuildFrom[A](implicit tag: ClassTag[A]) extends CanBuildFrom[CC[_], A, CC[A]] { + def apply(from: CC[_]) = from.genericClassTagBuilder[A] def apply = newBuilder[A] } } diff --git a/src/library/scala/collection/generic/GenericArrayTagCompanion.scala b/src/library/scala/collection/generic/GenericClassTagCompanion.scala index 5c825ebfef..8cce592627 100644 --- a/src/library/scala/collection/generic/GenericArrayTagCompanion.scala +++ b/src/library/scala/collection/generic/GenericClassTagCompanion.scala @@ -11,21 +11,21 @@ package generic import mutable.Builder import language.higherKinds -import reflect.ArrayTag +import reflect.ClassTag -/** This class represents companions of classes which require ArrayTags +/** This class represents companions of classes which require ClassTags * for their element types. * * @author Aleksandar Prokopec */ -abstract class GenericArrayTagCompanion[+CC[X] <: Traversable[X]] { +abstract class GenericClassTagCompanion[+CC[X] <: Traversable[X]] { type Coll = CC[_] - def newBuilder[A](implicit ord: ArrayTag[A]): Builder[A, CC[A]] + def newBuilder[A](implicit ord: ClassTag[A]): Builder[A, CC[A]] - def empty[A: ArrayTag]: CC[A] = newBuilder[A].result + def empty[A: ClassTag]: CC[A] = newBuilder[A].result - def apply[A](elems: A*)(implicit ord: ArrayTag[A]): CC[A] = { + def apply[A](elems: A*)(implicit ord: ClassTag[A]): CC[A] = { val b = newBuilder[A] b ++= elems b.result diff --git a/src/library/scala/collection/generic/GenericArrayTagTraversableTemplate.scala b/src/library/scala/collection/generic/GenericClassTagTraversableTemplate.scala index 88f0b25929..d368d0007b 100644 --- a/src/library/scala/collection/generic/GenericArrayTagTraversableTemplate.scala +++ b/src/library/scala/collection/generic/GenericClassTagTraversableTemplate.scala @@ -12,20 +12,20 @@ package generic import mutable.Builder import annotation.unchecked.uncheckedVariance import language.higherKinds -import reflect.ArrayTag +import reflect.ClassTag -/** This trait represents collections classes which require array +/** This trait represents collections classes which require class * tags for their element types. * * @author Aleksandar Prokopec * @since 2.8 */ -trait GenericArrayTagTraversableTemplate[+A, +CC[X] <: Traversable[X]] extends HasNewBuilder[A, CC[A] @uncheckedVariance] { - implicit protected[this] val tag: ArrayTag[A] - def arrayTagCompanion: GenericArrayTagCompanion[CC] - def genericArrayTagBuilder[B](implicit tag: ArrayTag[B]): Builder[B, CC[B]] = arrayTagCompanion.newBuilder[B] - @deprecated("use arrayTagCompanion instead", "2.10.0") - def classManifestCompanion: GenericClassManifestCompanion[CC] = arrayTagCompanion - @deprecated("use genericArrayTagBuilder instead", "2.10.0") - def genericClassManifestBuilder[B](implicit manifest: ClassManifest[B]): Builder[B, CC[B]] = genericArrayTagBuilder[B](manifest) +trait GenericClassTagTraversableTemplate[+A, +CC[X] <: Traversable[X]] extends HasNewBuilder[A, CC[A] @uncheckedVariance] { + implicit protected[this] val tag: ClassTag[A] + def classTagCompanion: GenericClassTagCompanion[CC] + def genericClassTagBuilder[B](implicit tag: ClassTag[B]): Builder[B, CC[B]] = classTagCompanion.newBuilder[B] + @deprecated("use classTagCompanion instead", "2.10.0") + def classManifestCompanion: GenericClassManifestCompanion[CC] = classTagCompanion + @deprecated("use genericClassTagBuilder instead", "2.10.0") + def genericClassManifestBuilder[B](implicit manifest: ClassManifest[B]): Builder[B, CC[B]] = genericClassTagBuilder[B](manifest) } diff --git a/src/library/scala/collection/generic/TraversableForwarder.scala b/src/library/scala/collection/generic/TraversableForwarder.scala index 86a202f28c..5c55c27983 100644 --- a/src/library/scala/collection/generic/TraversableForwarder.scala +++ b/src/library/scala/collection/generic/TraversableForwarder.scala @@ -11,7 +11,7 @@ package scala.collection.generic import scala.collection._ import mutable.{ Buffer, StringBuilder } import immutable.{ List, Stream } -import reflect.ArrayTag +import reflect.ClassTag /** This trait implements a forwarder for traversable objects. It forwards * all calls to a different traversable, except for: @@ -58,7 +58,7 @@ trait TraversableForwarder[+A] extends Traversable[A] { override def copyToArray[B >: A](xs: Array[B], start: Int, len: Int) = underlying.copyToArray(xs, start, len) override def copyToArray[B >: A](xs: Array[B], start: Int) = underlying.copyToArray(xs, start) override def copyToArray[B >: A](xs: Array[B]) = underlying.copyToArray(xs) - override def toArray[B >: A: ArrayTag]: Array[B] = underlying.toArray + override def toArray[B >: A: ClassTag]: Array[B] = underlying.toArray override def toList: List[A] = underlying.toList override def toIterable: Iterable[A] = underlying.toIterable override def toSeq: Seq[A] = underlying.toSeq diff --git a/src/library/scala/collection/generic/package.scala b/src/library/scala/collection/generic/package.scala index 2e58f313c9..85b9995f2e 100644 --- a/src/library/scala/collection/generic/package.scala +++ b/src/library/scala/collection/generic/package.scala @@ -12,12 +12,12 @@ package object generic { */ type HasElem[Repr, A] = Repr => GenTraversableLike[A, Repr] - @deprecated("use ArrayTagTraversableFactory instead", "2.10.0") - type ClassManifestTraversableFactory[CC[X] <: Traversable[X] with GenericClassManifestTraversableTemplate[X, CC]] = ArrayTagTraversableFactory[CC] + @deprecated("use ClassTagTraversableFactory instead", "2.10.0") + type ClassManifestTraversableFactory[CC[X] <: Traversable[X] with GenericClassManifestTraversableTemplate[X, CC]] = ClassTagTraversableFactory[CC] - @deprecated("use GenericArrayTagCompanion instead", "2.10.0") - type GenericClassManifestCompanion[+CC[X] <: Traversable[X]] = GenericArrayTagCompanion[CC] + @deprecated("use GenericClassTagCompanion instead", "2.10.0") + type GenericClassManifestCompanion[+CC[X] <: Traversable[X]] = GenericClassTagCompanion[CC] - @deprecated("use GenericArrayTagTraversableTemplate instead", "2.10.0") - type GenericClassManifestTraversableTemplate[+A, +CC[X] <: Traversable[X]] = GenericArrayTagTraversableTemplate[A, CC] + @deprecated("use GenericClassTagTraversableTemplate instead", "2.10.0") + type GenericClassManifestTraversableTemplate[+A, +CC[X] <: Traversable[X]] = GenericClassTagTraversableTemplate[A, CC] }
\ No newline at end of file diff --git a/src/library/scala/collection/immutable/PagedSeq.scala b/src/library/scala/collection/immutable/PagedSeq.scala index ac6da23068..7d373b7b39 100644 --- a/src/library/scala/collection/immutable/PagedSeq.scala +++ b/src/library/scala/collection/immutable/PagedSeq.scala @@ -13,7 +13,7 @@ package immutable import java.io._ import scala.util.matching.Regex -import reflect.ArrayTag +import reflect.ClassTag /** The `PagedSeq` object defines a lazy implementations of * a random access sequence. @@ -26,7 +26,7 @@ object PagedSeq { final val UndeterminedEnd = Int.MaxValue /** Constructs a paged sequence from an iterator */ - def fromIterator[T: ArrayTag](source: Iterator[T]): PagedSeq[T] = + def fromIterator[T: ClassTag](source: Iterator[T]): PagedSeq[T] = new PagedSeq[T]((data: Array[T], start: Int, len: Int) => { var i = 0 while (i < len && source.hasNext) { @@ -37,7 +37,7 @@ object PagedSeq { }) /** Constructs a paged sequence from an iterable */ - def fromIterable[T: ArrayTag](source: Iterable[T]): PagedSeq[T] = + def fromIterable[T: ClassTag](source: Iterable[T]): PagedSeq[T] = fromIterator(source.iterator) /** Constructs a paged character sequence from a string iterator */ @@ -116,7 +116,7 @@ import PagedSeq._ * It returns the number of elements produced, or -1 if end of logical input stream was reached * before reading any element. * - * @tparam T the type of the elements contained in this paged sequence, with an `ArrayTag` context bound. + * @tparam T the type of the elements contained in this paged sequence, with an `ClassTag` context bound. * * @author Martin Odersky * @since 2.7 @@ -125,7 +125,7 @@ import PagedSeq._ * @define mayNotTerminateInf * @define willNotTerminateInf */ -class PagedSeq[T: ArrayTag] protected( +class PagedSeq[T: ClassTag] protected( more: (Array[T], Int, Int) => Int, first1: Page[T], start: Int, @@ -206,7 +206,7 @@ extends scala.collection.AbstractSeq[T] /** Page containing up to PageSize characters of the input sequence. */ -private class Page[T: ArrayTag](val num: Int) { +private class Page[T: ClassTag](val num: Int) { private final val PageSize = 4096 diff --git a/src/library/scala/collection/immutable/StringLike.scala b/src/library/scala/collection/immutable/StringLike.scala index 9b6377e979..af7662d2e0 100644 --- a/src/library/scala/collection/immutable/StringLike.scala +++ b/src/library/scala/collection/immutable/StringLike.scala @@ -13,7 +13,7 @@ import generic._ import mutable.Builder import scala.util.matching.Regex import scala.math.ScalaNumber -import reflect.ArrayTag +import reflect.ClassTag /** A companion object for the `StringLike` containing some constants. * @since 2.8 @@ -240,7 +240,7 @@ self => else throw new IllegalArgumentException("For input string: \"null\"") - override def toArray[B >: Char : ArrayTag]: Array[B] = + override def toArray[B >: Char : ClassTag]: Array[B] = toString.toCharArray.asInstanceOf[Array[B]] private def unwrapArg(arg: Any): AnyRef = arg match { diff --git a/src/library/scala/collection/mutable/ArrayBuilder.scala b/src/library/scala/collection/mutable/ArrayBuilder.scala index ff69778772..0eb96de6d7 100644 --- a/src/library/scala/collection/mutable/ArrayBuilder.scala +++ b/src/library/scala/collection/mutable/ArrayBuilder.scala @@ -12,7 +12,7 @@ package scala.collection package mutable import generic._ -import scala.reflect.ArrayTag +import scala.reflect.ClassTag import scala.runtime.ScalaRunTime /** A builder class for arrays. @@ -31,13 +31,12 @@ object ArrayBuilder { /** Creates a new arraybuilder of type `T`. * - * @tparam T type of the elements for the array builder, with a `ArrayTag` context bound. + * @tparam T type of the elements for the array builder, with a `ClassTag` context bound. * @return a new empty array builder. */ - def make[T: ArrayTag](): ArrayBuilder[T] = { - val tag = implicitly[ArrayTag[T]] - val runtimeClass = ScalaRunTime.arrayElementClass(tag) - runtimeClass match { + def make[T: ClassTag](): ArrayBuilder[T] = { + val tag = implicitly[ClassTag[T]] + tag.runtimeClass match { case java.lang.Byte.TYPE => new ArrayBuilder.ofByte().asInstanceOf[ArrayBuilder[T]] case java.lang.Short.TYPE => new ArrayBuilder.ofShort().asInstanceOf[ArrayBuilder[T]] case java.lang.Character.TYPE => new ArrayBuilder.ofChar().asInstanceOf[ArrayBuilder[T]] @@ -47,15 +46,15 @@ object ArrayBuilder { case java.lang.Double.TYPE => new ArrayBuilder.ofDouble().asInstanceOf[ArrayBuilder[T]] case java.lang.Boolean.TYPE => new ArrayBuilder.ofBoolean().asInstanceOf[ArrayBuilder[T]] case java.lang.Void.TYPE => new ArrayBuilder.ofUnit().asInstanceOf[ArrayBuilder[T]] - case _ => new ArrayBuilder.ofRef[T with AnyRef]()(tag.asInstanceOf[ArrayTag[T with AnyRef]]).asInstanceOf[ArrayBuilder[T]] + case _ => new ArrayBuilder.ofRef[T with AnyRef]()(tag.asInstanceOf[ClassTag[T with AnyRef]]).asInstanceOf[ArrayBuilder[T]] } } /** A class for array builders for arrays of reference types. * - * @tparam T type of elements for the array builder, subtype of `AnyRef` with a `ArrayTag` context bound. + * @tparam T type of elements for the array builder, subtype of `AnyRef` with a `ClassTag` context bound. */ - class ofRef[T <: AnyRef : ArrayTag] extends ArrayBuilder[T] { + class ofRef[T <: AnyRef : ClassTag] extends ArrayBuilder[T] { private var elems: Array[T] = _ private var capacity: Int = 0 diff --git a/src/library/scala/collection/mutable/ArrayOps.scala b/src/library/scala/collection/mutable/ArrayOps.scala index 787b8ac228..01636eb54e 100644 --- a/src/library/scala/collection/mutable/ArrayOps.scala +++ b/src/library/scala/collection/mutable/ArrayOps.scala @@ -12,7 +12,7 @@ package scala.collection package mutable import compat.Platform.arraycopy -import scala.reflect.{ArrayTag, ClassTag} +import scala.reflect.ClassTag import scala.runtime.ScalaRunTime._ import parallel.mutable.ParArray @@ -47,8 +47,8 @@ abstract class ArrayOps[T] extends ArrayLike[T, Array[T]] with CustomParalleliza Array.copy(repr, 0, xs, start, l) } - override def toArray[U >: T : ArrayTag]: Array[U] = { - val thatElementClass = arrayElementClass(implicitly[ArrayTag[U]]) + override def toArray[U >: T : ClassTag]: Array[U] = { + val thatElementClass = arrayElementClass(implicitly[ClassTag[U]]) if (elementClass eq thatElementClass) repr.asInstanceOf[Array[U]] else @@ -64,7 +64,7 @@ abstract class ArrayOps[T] extends ArrayLike[T, Array[T]] with CustomParalleliza * @param asTrav A function that converts elements of this array to rows - arrays of type `U`. * @return An array obtained by concatenating rows of this array. */ - def flatten[U, To](implicit asTrav: T => collection.Traversable[U], m: ArrayTag[U]): Array[U] = { + def flatten[U, To](implicit asTrav: T => collection.Traversable[U], m: ClassTag[U]): Array[U] = { val b = Array.newBuilder[U] b.sizeHint(map{case is: collection.IndexedSeq[_] => is.size case _ => 0}.sum) for (xs <- this) diff --git a/src/library/scala/collection/mutable/ArrayStack.scala b/src/library/scala/collection/mutable/ArrayStack.scala index 7870a8f053..040a0e2aa7 100644 --- a/src/library/scala/collection/mutable/ArrayStack.scala +++ b/src/library/scala/collection/mutable/ArrayStack.scala @@ -10,7 +10,7 @@ package scala.collection package mutable import generic._ -import reflect.ArrayTag +import reflect.ClassTag /** Factory object for the `ArrayStack` class. * @@ -22,7 +22,7 @@ object ArrayStack extends SeqFactory[ArrayStack] { implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, ArrayStack[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]] def newBuilder[A]: Builder[A, ArrayStack[A]] = new ArrayStack[A] def empty: ArrayStack[Nothing] = new ArrayStack() - def apply[A: ArrayTag](elems: A*): ArrayStack[A] = { + def apply[A: ClassTag](elems: A*): ArrayStack[A] = { val els: Array[AnyRef] = elems.reverseMap(_.asInstanceOf[AnyRef])(breakOut) if (els.length == 0) new ArrayStack() else new ArrayStack[A](els, els.length) diff --git a/src/library/scala/collection/mutable/UnrolledBuffer.scala b/src/library/scala/collection/mutable/UnrolledBuffer.scala index 9ef34e67e6..6785aba10d 100644 --- a/src/library/scala/collection/mutable/UnrolledBuffer.scala +++ b/src/library/scala/collection/mutable/UnrolledBuffer.scala @@ -12,7 +12,7 @@ import collection.AbstractIterator import collection.Iterator import collection.generic._ import annotation.tailrec -import reflect.ArrayTag +import reflect.ClassTag /** A buffer that stores elements in an unrolled linked list. * @@ -42,11 +42,11 @@ import reflect.ArrayTag * */ @SerialVersionUID(1L) -class UnrolledBuffer[T](implicit val tag: ArrayTag[T]) +class UnrolledBuffer[T](implicit val tag: ClassTag[T]) extends collection.mutable.AbstractBuffer[T] with collection.mutable.Buffer[T] with collection.mutable.BufferLike[T, UnrolledBuffer[T]] - with GenericArrayTagTraversableTemplate[T, UnrolledBuffer] + with GenericClassTagTraversableTemplate[T, UnrolledBuffer] with collection.mutable.Builder[T, UnrolledBuffer[T]] with Serializable { @@ -68,7 +68,7 @@ extends collection.mutable.AbstractBuffer[T] private[collection] def calcNextLength(sz: Int) = sz - def arrayTagCompanion = UnrolledBuffer + def classTagCompanion = UnrolledBuffer /** Concatenates the targer unrolled buffer to this unrolled buffer. * @@ -186,11 +186,11 @@ extends collection.mutable.AbstractBuffer[T] } -object UnrolledBuffer extends ArrayTagTraversableFactory[UnrolledBuffer] { +object UnrolledBuffer extends ClassTagTraversableFactory[UnrolledBuffer] { /** $genericCanBuildFromInfo */ - implicit def canBuildFrom[T](implicit t: ArrayTag[T]): CanBuildFrom[Coll, T, UnrolledBuffer[T]] = + implicit def canBuildFrom[T](implicit t: ClassTag[T]): CanBuildFrom[Coll, T, UnrolledBuffer[T]] = new GenericCanBuildFrom[T] - def newBuilder[T](implicit t: ArrayTag[T]): Builder[T, UnrolledBuffer[T]] = new UnrolledBuffer[T] + def newBuilder[T](implicit t: ClassTag[T]): Builder[T, UnrolledBuffer[T]] = new UnrolledBuffer[T] val waterline = 50 val waterlineDelim = 100 @@ -198,7 +198,7 @@ object UnrolledBuffer extends ArrayTagTraversableFactory[UnrolledBuffer] { /** Unrolled buffer node. */ - class Unrolled[T: ArrayTag] private[collection] (var size: Int, var array: Array[T], var next: Unrolled[T], val buff: UnrolledBuffer[T] = null) { + class Unrolled[T: ClassTag] private[collection] (var size: Int, var array: Array[T], var next: Unrolled[T], val buff: UnrolledBuffer[T] = null) { private[collection] def this() = this(0, new Array[T](unrolledlength), null, null) private[collection] def this(b: UnrolledBuffer[T]) = this(0, new Array[T](unrolledlength), null, b) diff --git a/src/library/scala/collection/mutable/WrappedArray.scala b/src/library/scala/collection/mutable/WrappedArray.scala index 789ccc2d98..fec0fbaa3c 100644 --- a/src/library/scala/collection/mutable/WrappedArray.scala +++ b/src/library/scala/collection/mutable/WrappedArray.scala @@ -11,7 +11,7 @@ package scala.collection package mutable -import scala.reflect.{ArrayTag, ClassTag} +import scala.reflect.ClassTag import scala.runtime.ScalaRunTime._ import scala.collection.generic._ import scala.collection.parallel.mutable.ParArray @@ -42,7 +42,7 @@ extends AbstractSeq[T] override protected[this] def toCollection(repr: WrappedArray[T]): WrappedArray[T] = repr /** The tag of the element type */ - def elemTag: ArrayTag[T] + def elemTag: ClassTag[T] @deprecated("use elemTag instead", "2.10.0") def elemManifest: ClassManifest[T] = ClassManifest.fromClass[T](arrayElementClass(elemTag).asInstanceOf[Class[T]]) @@ -64,8 +64,8 @@ extends AbstractSeq[T] private def elementClass: Class[_] = arrayElementClass(repr.getClass) - override def toArray[U >: T : ArrayTag]: Array[U] = { - val thatElementClass = arrayElementClass(implicitly[ArrayTag[U]]) + override def toArray[U >: T : ClassTag]: Array[U] = { + val thatElementClass = arrayElementClass(implicitly[ClassTag[U]]) if (elementClass eq thatElementClass) array.asInstanceOf[Array[U]] else @@ -110,7 +110,7 @@ object WrappedArray { case x: Array[Unit] => new ofUnit(x) }).asInstanceOf[WrappedArray[T]] - implicit def canBuildFrom[T](implicit m: ArrayTag[T]): CanBuildFrom[WrappedArray[_], T, WrappedArray[T]] = + implicit def canBuildFrom[T](implicit m: ClassTag[T]): CanBuildFrom[WrappedArray[_], T, WrappedArray[T]] = new CanBuildFrom[WrappedArray[_], T, WrappedArray[T]] { def apply(from: WrappedArray[_]): Builder[T, WrappedArray[T]] = ArrayBuilder.make[T]()(m) mapResult WrappedArray.make[T] diff --git a/src/library/scala/collection/mutable/WrappedArrayBuilder.scala b/src/library/scala/collection/mutable/WrappedArrayBuilder.scala index abd46500fa..b7db8d1245 100644 --- a/src/library/scala/collection/mutable/WrappedArrayBuilder.scala +++ b/src/library/scala/collection/mutable/WrappedArrayBuilder.scala @@ -12,7 +12,7 @@ package scala.collection package mutable import generic._ -import scala.reflect.ArrayTag +import scala.reflect.ClassTag import scala.runtime.ScalaRunTime._ /** A builder class for arrays. @@ -22,10 +22,10 @@ import scala.runtime.ScalaRunTime._ * * @since 2.8 */ -class WrappedArrayBuilder[A](tag: ArrayTag[A]) extends Builder[A, WrappedArray[A]] { +class WrappedArrayBuilder[A](tag: ClassTag[A]) extends Builder[A, WrappedArray[A]] { @deprecated("use tag instead", "2.10.0") - val manifest: ArrayTag[A] = tag + val manifest: ClassTag[A] = tag private var elems: WrappedArray[A] = _ private var capacity: Int = 0 diff --git a/src/library/scala/collection/parallel/ParIterableLike.scala b/src/library/scala/collection/parallel/ParIterableLike.scala index 0b2a0ec5bb..a447f1b5e4 100644 --- a/src/library/scala/collection/parallel/ParIterableLike.scala +++ b/src/library/scala/collection/parallel/ParIterableLike.scala @@ -24,7 +24,7 @@ import scala.collection.GenIterable import scala.collection.GenTraversableOnce import scala.collection.GenTraversable import immutable.HashMapCombiner -import reflect.{ArrayTag, ClassTag} +import reflect.{ClassTag, classTag} import java.util.concurrent.atomic.AtomicBoolean @@ -184,25 +184,25 @@ self: ParIterableLike[T, Repr, Sequential] => def hasDefiniteSize = true def isEmpty = size == 0 - + def nonEmpty = size != 0 - + def head = iterator.next - + def headOption = if (nonEmpty) Some(head) else None - + def tail = drop(1) - + def last = { var lst = head for (x <- this.seq) lst = x lst } - + def lastOption = if (nonEmpty) Some(last) else None - + def init = take(size - 1) - + /** Creates a new parallel iterator used to traverse the elements of this parallel collection. * This iterator is more specific than the iterator of the returned by `iterator`, and augmented * with additional accessor and transformer methods. @@ -823,7 +823,7 @@ self: ParIterableLike[T, Repr, Sequential] => def size = splitter.remaining } - override def toArray[U >: T: ArrayTag]: Array[U] = { + override def toArray[U >: T: ClassTag]: Array[U] = { val arr = new Array[U](size) copyToArray(arr) arr diff --git a/src/library/scala/collection/parallel/mutable/ParArray.scala b/src/library/scala/collection/parallel/mutable/ParArray.scala index e61eab2072..6889d8b472 100644 --- a/src/library/scala/collection/parallel/mutable/ParArray.scala +++ b/src/library/scala/collection/parallel/mutable/ParArray.scala @@ -26,7 +26,7 @@ import scala.collection.parallel.CHECK_RATE import scala.collection.mutable.ArraySeq import scala.collection.mutable.Builder import scala.collection.GenTraversableOnce -import scala.reflect.ArrayTag +import scala.reflect.ClassTag @@ -706,7 +706,7 @@ object ParArray extends ParFactory[ParArray] { case _ => new ParArray[T](new ExposedArraySeq[T](runtime.ScalaRunTime.toObjectArray(arr), sz)) } - def createFromCopy[T <: AnyRef : ArrayTag](arr: Array[T]): ParArray[T] = { + def createFromCopy[T <: AnyRef : ClassTag](arr: Array[T]): ParArray[T] = { val newarr = new Array[T](arr.length) Array.copy(arr, 0, newarr, 0, arr.length) handoff(newarr) diff --git a/src/library/scala/collection/parallel/mutable/UnrolledParArrayCombiner.scala b/src/library/scala/collection/parallel/mutable/UnrolledParArrayCombiner.scala index 42c015e0b4..9648791502 100644 --- a/src/library/scala/collection/parallel/mutable/UnrolledParArrayCombiner.scala +++ b/src/library/scala/collection/parallel/mutable/UnrolledParArrayCombiner.scala @@ -21,12 +21,12 @@ import scala.collection.parallel.TaskSupport import scala.collection.parallel.unsupportedop import scala.collection.parallel.Combiner import scala.collection.parallel.Task -import scala.reflect.ArrayTag +import scala.reflect.ClassTag -private[mutable] class DoublingUnrolledBuffer[T](implicit t: ArrayTag[T]) extends UnrolledBuffer[T]()(t) { +private[mutable] class DoublingUnrolledBuffer[T](implicit t: ClassTag[T]) extends UnrolledBuffer[T]()(t) { override def calcNextLength(sz: Int) = if (sz < 10000) sz * 2 else sz protected override def newUnrolled = new Unrolled[T](0, new Array[T](4), null, this) } diff --git a/src/library/scala/reflect/ArrayTag.scala b/src/library/scala/reflect/ArrayTag.scala deleted file mode 100644 index 0dc25c8dc2..0000000000 --- a/src/library/scala/reflect/ArrayTag.scala +++ /dev/null @@ -1,25 +0,0 @@ -package scala.reflect - -/** An `ArrayTag[T]` is a descriptor that is requested by the compiler every time - * when an array is instantiated, but the element type is unknown at compile time. - * - * Implicit in the contract of `ArrayTag[T]` is the fact that `T` - * cannot contain unresolved references to type parameters or abstract types. - * - * Scala library provides a standard implementation of this trait, - * `ClassTag[T]` that explicitly carries the runtime class of type T - * and uses reflection to instantiate arrays. - * - * However other platforms (e.g. a Scala -> JS crosscompiler) may reimplement this trait as they see fit - * and then expose the implementation via an implicit macro. - * - * @see [[scala.reflect.base.TypeTags]] - */ -@annotation.implicitNotFound(msg = "No ArrayTag available for ${T}") -trait ArrayTag[T] { - /** Produces an `ArrayTag` that knows how to build `Array[Array[T]]` */ - def wrap: ArrayTag[Array[T]] - - /** Produces a new array with element type `T` and length `len` */ - def newArray(len: Int): Array[T] -}
\ No newline at end of file diff --git a/src/library/scala/reflect/ClassTag.scala b/src/library/scala/reflect/ClassTag.scala index 11fa4c8dc7..350003a8d8 100644 --- a/src/library/scala/reflect/ClassTag.scala +++ b/src/library/scala/reflect/ClassTag.scala @@ -9,21 +9,17 @@ import scala.runtime.ScalaRunTime.arrayClass * This is useful in itself, but also enables very important use case. * Having this knowledge ClassTag can instantiate `Arrays` * in those cases where the element type is unknown at compile time. - * Hence, ClassTag[T] conforms to the ArrayTag[T] trait. * * If an implicit value of type u.ClassTag[T] is required, the compiler will make one up on demand. * The implicitly created value contains in its `runtimeClass` field the runtime class that is the result of erasing type T. * In that value, any occurrences of type parameters or abstract types U which come themselves with a ClassTag - * or a reflect.mirror.ConcreteTypeTag are represented by the type referenced by that tag. + * are represented by the type referenced by that tag. * If the type T contains unresolved references to type parameters or abstract types, a static error results. * - * A ConcreteTypeTag member of the reflect.mirror object is convertible to a ClassTag via an implicit conversion - * (this is not possible to do in all reflection universes because an operation that converts a type to a Java class might not be available). - * * @see [[scala.reflect.base.TypeTags]] */ @annotation.implicitNotFound(msg = "No ClassTag available for ${T}") -trait ClassTag[T] extends ArrayTag[T] with Equals with Serializable { +trait ClassTag[T] extends Equals with Serializable { // please, don't add any APIs here, like it was with `newWrappedArray` and `newArrayBuilder` // class tags, and all tags in general, should be as minimalistic as possible diff --git a/src/library/scala/reflect/base/TagInterop.scala b/src/library/scala/reflect/base/TagInterop.scala index 4315341630..9c4159f1d8 100644 --- a/src/library/scala/reflect/base/TagInterop.scala +++ b/src/library/scala/reflect/base/TagInterop.scala @@ -4,11 +4,11 @@ package base import scala.runtime.ScalaRunTime._ trait TagInterop { self: Universe => - def arrayTagToClassManifest[T](tag: ArrayTag[T]): ClassManifest[T] = { - val runtimeClass = arrayElementClass(tag) + def classTagToClassManifest[T](tag: ClassTag[T]): ClassManifest[T] = { + val runtimeClass = tag.runtimeClass if (runtimeClass.isArray) { val elementClass = arrayElementClass(runtimeClass) - val elementManifest = arrayTagToClassManifest(ClassTag(elementClass)) + val elementManifest = classTagToClassManifest(ClassTag(elementClass)) ClassManifest.arrayType(elementManifest).asInstanceOf[ClassManifest[T]] } else { ClassManifest.fromClass(runtimeClass.asInstanceOf[Class[T]]) diff --git a/src/library/scala/reflect/base/TypeTags.scala b/src/library/scala/reflect/base/TypeTags.scala index 8d4aa04efc..ed927fd889 100644 --- a/src/library/scala/reflect/base/TypeTags.scala +++ b/src/library/scala/reflect/base/TypeTags.scala @@ -16,16 +16,11 @@ import language.implicitConversions * * === Overview === * - * Type tags are organized in a hierarchy of four classes: - * [[scala.reflect.ArrayTag]], [[scala.reflect.ClassTag]], - * [[scala.reflect.base.Universe#TypeTag]] and [[scala.reflect.base.Universe#ConcreteTypeTag]]. + * Type tags are organized in a hierarchy of three classes: + * [[scala.reflect.ClassTag]], [[scala.reflect.base.Universe#TypeTag]] and [[scala.reflect.base.Universe#ConcreteTypeTag]]. * - * An [[scala.reflect.ArrayTag]] value carries knowledge about how to build an array of elements of type T. - * Typically such operation is performed by storing a runtime class and instantiating arrays via reflection, - * but [[scala.reflect.ArrayTag]] only defines an interface, not an implementation, hence it only contains the factory methods - * `newArray` and `wrap` that can be used to build, correspondingly, single-dimensional and multi-dimensional arrays. - * - * A [[scala.reflect.ClassTag]] is a standard implementation of [[scala.reflect.ArrayTag]]. + * A [[scala.reflect.ClassTag]] carries a runtime class that corresponds to the source type T. + * As of such, it possesses the knowledge about how to build single- and multi-dimensional arrays of elements of that type. * It guarantees that the source type T did not to contain any references to type parameters or abstract types. * [[scala.reflect.ClassTag]] corresponds to a previous notion of [[scala.reflect.ClassManifest]]. * @@ -33,10 +28,6 @@ import language.implicitConversions * A [[scala.reflect.base.Universe#ConcreteTypeTag]] value is a [[scala.reflect.base.Universe#TypeTag]] * that is guaranteed not to contain any references to type parameters or abstract types. * - * It is recommended to use the tag supertypes of to precisely express your intent, i.e.: - * use ArrayTag when you just want to construct arrays, - * use ClassTag only when you need a runtime class, e.g. for serialization or pattern matching. - * * [Eugene++] also mention sensitivity to prefixes, i.e. that rb.TypeTag is different from ru.TypeTag * [Eugene++] migratability between mirrors and universes is also worth mentioning * diff --git a/src/library/scala/reflect/makro/internal/package.scala b/src/library/scala/reflect/makro/internal/package.scala index de7350bf48..f98177542a 100644 --- a/src/library/scala/reflect/makro/internal/package.scala +++ b/src/library/scala/reflect/makro/internal/package.scala @@ -10,7 +10,6 @@ import scala.reflect.base.{Universe => BaseUniverse} // todo. once we have implicit macros for tag generation, we can remove these anchors // [Eugene++] how do I hide this from scaladoc? package object internal extends scala.reflect.internal_compat { - private[scala] def materializeArrayTag[T](u: BaseUniverse): ArrayTag[T] = macro ??? private[scala] def materializeClassTag[T](u: BaseUniverse): ClassTag[T] = macro ??? private[scala] def materializeTypeTag[T](u: BaseUniverse): u.TypeTag[T] = macro ??? private[scala] def materializeConcreteTypeTag[T](u: BaseUniverse): u.ConcreteTypeTag[T] = macro ??? diff --git a/src/library/scala/reflect/package.scala b/src/library/scala/reflect/package.scala index 447d509292..49374a552c 100644 --- a/src/library/scala/reflect/package.scala +++ b/src/library/scala/reflect/package.scala @@ -19,9 +19,7 @@ package object reflect extends reflect_compat { @deprecated("Use `@scala.beans.ScalaBeanInfo` instead", "2.10.0") type ScalaBeanInfo = scala.beans.ScalaBeanInfo - // ArrayTag trait is defined outside the basis // ClassTag class is defined outside the basis - def arrayTag[T](implicit atag: ArrayTag[T]) = atag def classTag[T](implicit ctag: ClassTag[T]) = ctag // typeTag incantation is defined inside the basis // concreteTypeTag incantation is defined inside the basis diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala index 5715ed2719..e5f5e9dc5d 100644 --- a/src/library/scala/runtime/ScalaRunTime.scala +++ b/src/library/scala/runtime/ScalaRunTime.scala @@ -12,7 +12,7 @@ import scala.collection.{ Seq, IndexedSeq, TraversableView, AbstractIterator } import scala.collection.mutable.WrappedArray import scala.collection.immutable.{ StringLike, NumericRange, List, Stream, Nil, :: } import scala.collection.generic.{ Sorted } -import scala.reflect.{ ArrayTag, ClassTag, arrayTag, classTag } +import scala.reflect.{ ClassTag, classTag } import scala.util.control.ControlThrowable import scala.xml.{ Node, MetaData } @@ -61,7 +61,6 @@ object ScalaRunTime { def arrayElementClass(schematic: Any): Class[_] = schematic match { case cls: Class[_] => cls.getComponentType case tag: ClassTag[_] => tag.runtimeClass - case tag: ArrayTag[_] => tag.newArray(0).getClass.getComponentType case _ => throw new UnsupportedOperationException("unsupported schematic %s (%s)".format(schematic, if (schematic == null) "null" else schematic.getClass)) } diff --git a/src/library/scala/util/Sorting.scala b/src/library/scala/util/Sorting.scala index 2e4709a7f8..5f0edf964f 100644 --- a/src/library/scala/util/Sorting.scala +++ b/src/library/scala/util/Sorting.scala @@ -8,7 +8,7 @@ package scala.util -import scala.reflect.{ ArrayTag, ClassTag } +import scala.reflect.{ ClassTag, classTag } import scala.math.Ordering /** The Sorting object provides functions that can sort various kinds of @@ -39,14 +39,14 @@ object Sorting { /** Sort an array of K where K is Ordered, preserving the existing order * where the values are equal. */ - def stableSort[K: ArrayTag: Ordering](a: Array[K]) { + def stableSort[K: ClassTag: Ordering](a: Array[K]) { stableSort(a, 0, a.length-1, new Array[K](a.length), Ordering[K].lt _) } /** Sorts an array of `K` given an ordering function `f`. * `f` should return `true` iff its first parameter is strictly less than its second parameter. */ - def stableSort[K: ArrayTag](a: Array[K], f: (K, K) => Boolean) { + def stableSort[K: ClassTag](a: Array[K], f: (K, K) => Boolean) { stableSort(a, 0, a.length-1, new Array[K](a.length), f) } @@ -57,14 +57,14 @@ object Sorting { * @param f the comparison function. * @return the sorted sequence of items. */ - def stableSort[K: ArrayTag](a: Seq[K], f: (K, K) => Boolean): Array[K] = { + def stableSort[K: ClassTag](a: Seq[K], f: (K, K) => Boolean): Array[K] = { val ret = a.toArray stableSort(ret, f) ret } /** Sorts an arbitrary sequence of items that are viewable as ordered. */ - def stableSort[K: ArrayTag: Ordering](a: Seq[K]): Array[K] = + def stableSort[K: ClassTag: Ordering](a: Seq[K]): Array[K] = stableSort(a, Ordering[K].lt _) /** Stably sorts a sequence of items given an extraction function that will @@ -74,8 +74,8 @@ object Sorting { * @param f the comparison function. * @return the sorted sequence of items. */ - def stableSort[K: ArrayTag, M: Ordering](a: Seq[K], f: K => M): Array[K] = - stableSort(a)(implicitly[ArrayTag[K]], Ordering[M] on f) + def stableSort[K: ClassTag, M: Ordering](a: Seq[K], f: K => M): Array[K] = + stableSort(a)(implicitly[ClassTag[K]], Ordering[M] on f) private def sort1[K: Ordering](x: Array[K], off: Int, len: Int) { val ord = Ordering[K] @@ -498,7 +498,7 @@ object Sorting { sort2(off, len) } - private def stableSort[K : ArrayTag](a: Array[K], lo: Int, hi: Int, scratch: Array[K], f: (K,K) => Boolean) { + private def stableSort[K : ClassTag](a: Array[K], lo: Int, hi: Int, scratch: Array[K], f: (K,K) => Boolean) { if (lo < hi) { val mid = (lo+hi) / 2 stableSort(a, lo, mid, scratch, f) |