summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2010-04-09 15:42:34 +0000
committerIulian Dragos <jaguarul@gmail.com>2010-04-09 15:42:34 +0000
commit710e1cb6c4029f39bdd1eece975dbb3cdfafdeda (patch)
tree9d2fd741d17d2410b571f72bed5d7e5525ad5440 /src
parentd76943f9ae43176980f21f90f400053fe2da3fbf (diff)
downloadscala-710e1cb6c4029f39bdd1eece975dbb3cdfafdeda.tar.gz
scala-710e1cb6c4029f39bdd1eece975dbb3cdfafdeda.tar.bz2
scala-710e1cb6c4029f39bdd1eece975dbb3cdfafdeda.zip
Changed the syntax of the specialized annotation:
instead of a flaky string, it now takes a repeated parameter list of primitive types: @specialized("Int, Double") becomes @specialized(Int, Double). No review.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala55
-rw-r--r--src/library/scala/Function1.scala2
-rw-r--r--src/library/scala/Function2.scala4
-rw-r--r--src/library/scala/Product1.scala2
-rw-r--r--src/library/scala/Product2.scala3
-rw-r--r--src/library/scala/Tuple1.scala2
-rw-r--r--src/library/scala/Tuple2.scala3
-rw-r--r--src/library/scala/collection/immutable/Range.scala4
-rw-r--r--src/library/scala/runtime/AbstractFunction0.scala9
-rw-r--r--src/library/scala/specialized.scala11
10 files changed, 39 insertions, 56 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
index 0284745243..25943af964 100644
--- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
+++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
@@ -243,51 +243,30 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
}
}
- lazy val primitiveTypes = Map(
- "Unit" -> definitions.UnitClass.tpe,
- "Boolean" -> definitions.BooleanClass.tpe,
- "Byte" -> definitions.ByteClass.tpe,
- "Short" -> definitions.ShortClass.tpe,
- "Char" -> definitions.CharClass.tpe,
- "Int" -> definitions.IntClass.tpe,
- "Long" -> definitions.LongClass.tpe,
- "Float" -> definitions.FloatClass.tpe,
- "Double" -> definitions.DoubleClass.tpe)
-
-
-
- /** Parse the given string into the list of types it contains.
- *
- * @param str comma-separated string of distinct primitive types.
- */
- def parseTypes(str: String): List[Type] = {
- if (str.trim == "")
- List()
- else {
- val buf = new mutable.ListBuffer[Type]
- for (t <- str.split(','))
- primitiveTypes.get(t.trim) match {
- case Some(tpe) => buf += tpe
- case None =>
- error("Invalid type " + t + ". Expected one of " + primitiveTypes.keysIterator.mkString("", ", ", "."))
- }
- buf.toList
- }
- }
-
- /** Return the concrete types `sym' should be specialized at.
+ lazy val primitiveTypes = List(
+ definitions.UnitClass.tpe,
+ definitions.BooleanClass.tpe,
+ definitions.ByteClass.tpe,
+ definitions.ShortClass.tpe,
+ definitions.CharClass.tpe,
+ definitions.IntClass.tpe,
+ definitions.LongClass.tpe,
+ definitions.FloatClass.tpe,
+ definitions.DoubleClass.tpe)
+
+ /** Return the concrete types `sym' should be specialized at.
*/
def concreteTypes(sym: Symbol): List[Type] =
sym.getAnnotation(SpecializedClass) match {
case Some(AnnotationInfo(_, args, _)) =>
args match {
- case Literal(ct) :: _ =>
- val tpes = parseTypes(ct.stringValue)
+ case Nil =>
+ log(sym + " specialized on everything")
+ primitiveTypes.toList
+ case _ =>
+ val tpes = args.map(_.symbol.companionClass.tpe)
log(sym + " specialized on " + tpes)
tpes
- case _ =>
- log(sym + " specialized on everything")
- primitiveTypes.valuesIterator.toList
}
case _ =>
Nil
diff --git a/src/library/scala/Function1.scala b/src/library/scala/Function1.scala
index 75110d7d4e..afc19417a2 100644
--- a/src/library/scala/Function1.scala
+++ b/src/library/scala/Function1.scala
@@ -35,7 +35,7 @@ package scala
* println(anonfun1(0))
* }</pre>
*/
-trait Function1[-T1, +R] extends AnyRef { self =>
+trait Function1[@specialized(Int, Long, Double) -T1, @specialized(Unit, Int, Long, Double) +R] extends AnyRef { self =>
def apply(v1:T1): R
override def toString() = "<function1>"
diff --git a/src/library/scala/Function2.scala b/src/library/scala/Function2.scala
index 99c4ed1d2a..46023a9b3b 100644
--- a/src/library/scala/Function2.scala
+++ b/src/library/scala/Function2.scala
@@ -35,7 +35,9 @@ package scala
* println(anonfun2(0, 1))
* }</pre>
*/
-trait Function2[-T1, -T2, +R] extends AnyRef { self =>
+trait Function2[@specialized(Int, Long, Double) -T1,
+ @specialized(Int, Long, Double) -T2,
+ @specialized(Unit, Int, Long, Double) +R] extends AnyRef { self =>
def apply(v1:T1,v2:T2): R
override def toString() = "<function2>"
diff --git a/src/library/scala/Product1.scala b/src/library/scala/Product1.scala
index 2cca5fe7d5..0e93065e5a 100644
--- a/src/library/scala/Product1.scala
+++ b/src/library/scala/Product1.scala
@@ -22,7 +22,7 @@ object Product1 {
*
* @since 2.3
*/
-trait Product1[+T1] extends Product {
+trait Product1[@specialized(Int, Long, Double) +T1] extends Product {
/**
* The arity of this product.
* @return 1
diff --git a/src/library/scala/Product2.scala b/src/library/scala/Product2.scala
index 27580f8658..436de41a01 100644
--- a/src/library/scala/Product2.scala
+++ b/src/library/scala/Product2.scala
@@ -22,7 +22,8 @@ object Product2 {
*
* @since 2.3
*/
-trait Product2[+T1, +T2] extends Product {
+trait Product2[@specialized(Int, Long, Double) +T1,
+ @specialized(Int, Long, Double) +T2] extends Product {
/**
* The arity of this product.
* @return 2
diff --git a/src/library/scala/Tuple1.scala b/src/library/scala/Tuple1.scala
index d57c58fe78..5d25cc5abb 100644
--- a/src/library/scala/Tuple1.scala
+++ b/src/library/scala/Tuple1.scala
@@ -17,7 +17,7 @@ package scala
/** Tuple1 is the canonical representation of a @see Product1
*
*/
-case class Tuple1[+T1](_1:T1)
+case class Tuple1[@specialized(Int, Long, Double) +T1](_1:T1)
extends Product1[T1]
{
override def toString() = "(" + _1 + ")"
diff --git a/src/library/scala/Tuple2.scala b/src/library/scala/Tuple2.scala
index 8c4e5973c5..7fea22410d 100644
--- a/src/library/scala/Tuple2.scala
+++ b/src/library/scala/Tuple2.scala
@@ -19,7 +19,8 @@ import scala.collection.generic.CanBuildFrom
/** Tuple2 is the canonical representation of a @see Product2
*
*/
-case class Tuple2[+T1, +T2](_1:T1,_2:T2)
+case class Tuple2[@specialized(Int, Long, Double) +T1,
+ @specialized(Int, Long, Double) +T2](_1:T1,_2:T2)
extends Product2[T1, T2]
{
override def toString() = "(" + _1 + "," + _2 + ")"
diff --git a/src/library/scala/collection/immutable/Range.scala b/src/library/scala/collection/immutable/Range.scala
index dc79d0d5e0..5424a7afcb 100644
--- a/src/library/scala/collection/immutable/Range.scala
+++ b/src/library/scala/collection/immutable/Range.scala
@@ -39,7 +39,7 @@ class Range(val start: Int, val end: Int, val step: Int) extends IndexedSeq[Int]
def isInclusive = false
- override def foreach[U](f: Int => U) {
+ override def foreach[@specialized(Unit) U](f: Int => U) {
if (fullLength > 0) {
val last = this.last
var i = start
@@ -191,7 +191,7 @@ object Range {
def inclusive(start: Int, end: Int): Range.Inclusive with ByOne = new Inclusive(start, end, 1) with ByOne
trait ByOne extends Range {
- override final def foreach[U](f: Int => U) {
+ override final def foreach[@specialized(Unit) U](f: Int => U) {
if (length > 0) {
val last = this.last
var i = start
diff --git a/src/library/scala/runtime/AbstractFunction0.scala b/src/library/scala/runtime/AbstractFunction0.scala
index 1022a056f9..2d7d613132 100644
--- a/src/library/scala/runtime/AbstractFunction0.scala
+++ b/src/library/scala/runtime/AbstractFunction0.scala
@@ -8,9 +8,12 @@
package scala.runtime
-abstract class AbstractFunction0[+R] extends Function0[R] { }
-abstract class AbstractFunction1[-T1, +R] extends Function1[T1, R] { }
-abstract class AbstractFunction2[-T1, -T2, +R] extends Function2[T1, T2, R] { }
+abstract class AbstractFunction0[@specialized(Unit, Int, Long, Double) +R] extends Function0[R] { }
+abstract class AbstractFunction1[@specialized(Int, Long, Double) -T1,
+ @specialized(Unit, Int, Long, Double) +R] extends Function1[T1, R] { }
+abstract class AbstractFunction2[@specialized(Int, Long, Double) -T1,
+ @specialized(Int, Long, Double) -T2,
+ @specialized(Unit, Int, Long, Double) +R] extends Function2[T1, T2, R] { }
abstract class AbstractFunction3[-T1, -T2, -T3, +R] extends Function3[T1, T2, T3, R] { }
abstract class AbstractFunction4[-T1, -T2, -T3, -T4, +R] extends Function4[T1, T2, T3, T4, R] { }
abstract class AbstractFunction5[-T1, -T2, -T3, -T4, -T5, +R] extends Function5[T1, T2, T3, T4, T5, R] { }
diff --git a/src/library/scala/specialized.scala b/src/library/scala/specialized.scala
index 5ad2b0501f..4ac3037328 100644
--- a/src/library/scala/specialized.scala
+++ b/src/library/scala/specialized.scala
@@ -18,20 +18,17 @@ package scala
* </code>
*
* Type T can be specialized on a subset of the primitive types by
- * specifying a comma-separated string argument:
+ * specifying a list of primitive types to specialize at:
*
* <code>
- * class MyList[@specialized("Int, Double, Boolean") T] ..
+ * class MyList[@specialized(Int, Double, Boolean) T] ..
* </code>
- * Only primitive types are supported and no name resolution is currently
- * done on the string arguments (meaning imports and type aliases are
- * not resolved).
*
* @since 2.8
*/
-class specialized(types: String) extends StaticAnnotation {
+class specialized(types: runtime.AnyValCompanion*) extends StaticAnnotation {
def this() {
- this("Boolean, Byte, Short, Char, Int, Long, Float, Double")
+ this(Unit, Boolean, Byte, Short, Char, Int, Long, Float, Double)
}
}