summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2010-02-22 13:11:49 +0000
committerIulian Dragos <jaguarul@gmail.com>2010-02-22 13:11:49 +0000
commit57d38b321e73f78e03469ad5dab23e84999a817d (patch)
treeeacda0bb39b039f625567edbee4cf1c6d40eeb50
parent6e061d6f2597a3e4bdc7fcf192abbdb419917b70 (diff)
downloadscala-57d38b321e73f78e03469ad5dab23e84999a817d.tar.gz
scala-57d38b321e73f78e03469ad5dab23e84999a817d.tar.bz2
scala-57d38b321e73f78e03469ad5dab23e84999a817d.zip
Specialized types are not substituted inside ty...
Specialized types are not substituted inside type arguments. Closes #3085, no review.
-rw-r--r--src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala4
-rw-r--r--test/files/run/spec-absfun.flags1
-rw-r--r--test/files/run/spec-absfun.scala43
-rw-r--r--test/files/run/spec-matrix.check1
-rw-r--r--test/files/run/spec-matrix.flags1
-rw-r--r--test/files/run/spec-matrix.scala70
6 files changed, 118 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
index b2dd77ccfa..27a95d1ae1 100644
--- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
+++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
@@ -173,7 +173,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
override def apply(tp: Type): Type = tp match {
case TypeRef(pre, sym, args) if !args.isEmpty =>
val pre1 = this(pre)
- val args1 = args map this
+ val args1 = args// map this
val unspecArgs = unspecializedArgs(sym, args)
specializedClass.get((sym, TypeEnv.fromSpecialization(sym, args1))) match {
case Some(sym1) =>
@@ -182,7 +182,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
case None =>
typeRef(pre1, sym, args1)
}
- case _ => mapOver(tp)
+ case _ => tp // mapOver(tp)
}
}
diff --git a/test/files/run/spec-absfun.flags b/test/files/run/spec-absfun.flags
new file mode 100644
index 0000000000..3a910a936c
--- /dev/null
+++ b/test/files/run/spec-absfun.flags
@@ -0,0 +1 @@
+-Yspecialize \ No newline at end of file
diff --git a/test/files/run/spec-absfun.scala b/test/files/run/spec-absfun.scala
new file mode 100644
index 0000000000..ab16e8febc
--- /dev/null
+++ b/test/files/run/spec-absfun.scala
@@ -0,0 +1,43 @@
+
+/** Test inheritance. See #3085.
+ * Anonymous functions extend AbstractFunction1[SpecializedPair[Int], Unit]. The
+ * specialized type SpecializedPair$mcI$sp should not leak into the superclass because
+ * the definition of apply would vary covariantly, and erasure won't consider it an
+ * override of the abstract apply, leading to an AbstractMethodError at runtime.
+ */
+
+object Test {
+
+ private val Max = 1000
+
+ def main(args: Array[String]) {
+ notSpecialized()
+ specialized()
+ }
+
+ def notSpecialized() {
+ val pairs = for { i <- 1 to Max; j <- 1 to i } yield new Pair(i, j)
+ val time0 = System.nanoTime
+ pairs foreach { p => p.first * p.second }
+ val time1 = System.nanoTime
+// println(time1 - time0)
+ }
+
+ def specialized() {
+ val pairs = for { i <- 1 to Max; j <- 1 to i } yield new SpecializedPair(i, j)
+ val time0 = System.nanoTime
+ pairs foreach { p => p.first * p.second }
+ val time1 = System.nanoTime
+// println(time1 - time0)
+ }
+}
+
+class Pair[A](_first: A, _second: A) {
+ def first = _first
+ def second = _second
+}
+
+class SpecializedPair[@specialized("Int") A](_first: A, _second: A) {
+ def first = _first
+ def second = _second
+}
diff --git a/test/files/run/spec-matrix.check b/test/files/run/spec-matrix.check
new file mode 100644
index 0000000000..72e8ffc0db
--- /dev/null
+++ b/test/files/run/spec-matrix.check
@@ -0,0 +1 @@
+*
diff --git a/test/files/run/spec-matrix.flags b/test/files/run/spec-matrix.flags
new file mode 100644
index 0000000000..3a910a936c
--- /dev/null
+++ b/test/files/run/spec-matrix.flags
@@ -0,0 +1 @@
+-Yspecialize \ No newline at end of file
diff --git a/test/files/run/spec-matrix.scala b/test/files/run/spec-matrix.scala
new file mode 100644
index 0000000000..212a800672
--- /dev/null
+++ b/test/files/run/spec-matrix.scala
@@ -0,0 +1,70 @@
+/** Test matrix multiplication with specialization.
+ */
+
+class Matrix[@specialized A: ClassManifest](val rows: Int, val cols: Int) {
+ private val arr: Array[Array[A]] = new Array[Array[A]](rows, cols)
+
+ def apply(i: Int, j: Int): A = {
+ if (i < 0 || i >= rows || j < 0 || j >= cols)
+ throw new NoSuchElementException("Indexes out of bounds: " + (i, j))
+
+ arr(i)(j)
+ }
+
+ def update(i: Int, j: Int, e: A) {
+ arr(i)(j) = e
+ }
+
+ def rowsIterator: Iterator[Array[A]] = new Iterator[Array[A]] {
+ var idx = 0;
+ def hasNext = idx < rows
+ def next = {
+ idx += 1
+ arr(idx - 1)
+ }
+ }
+}
+
+object Test {
+ def main(args: Array[String]) {
+ val m = randomMatrix(200, 100)
+ val n = randomMatrix(100, 200)
+
+ mult(m, n)
+ println("*")
+ }
+
+ def randomMatrix(n: Int, m: Int) = {
+ val r = new util.Random(10)
+ val x = new Matrix[Int](n, m)
+ for (i <- 0 until n; j <- 0 until m)
+ x(i, j) = r.nextInt
+ x
+ }
+
+
+ def multManifest[@specialized("Int") T](m: Matrix[T], n: Matrix[T])(implicit cm: ClassManifest[T], num: Numeric[T]) {
+ val p = new Matrix[T](m.rows, n.cols)
+ import num._
+
+ for (i <- 0 until m.rows)
+ for (j <- 0 until n.cols) {
+ var sum = num.zero
+ for (k <- 0 until n.rows)
+ sum += m(i, k) * n(k, j)
+ p(i, j) = sum
+ }
+ }
+
+ def mult(m: Matrix[Int], n: Matrix[Int]) {
+ val p = new Matrix[Int](m.rows, n.cols)
+
+ for (i <- 0 until m.rows)
+ for (j <- 0 until n.cols) {
+ var sum = 0
+ for (k <- 0 until n.rows)
+ sum += m(i, k) * n(k, j)
+ p(i, j) = sum
+ }
+ }
+}