From 748d1d852ce28785f61f511758071c70a6137356 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 13 Sep 2016 18:15:21 +0200 Subject: Generalize checkInlineConformant to functions Pure expressions with function types now are considered conforming. Necessitated a change in TreeInfo to accept closures as pure expressions. Test case in inlineForeach --- tests/run/inlineForeach.scala | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/run/inlineForeach.scala (limited to 'tests/run') diff --git a/tests/run/inlineForeach.scala b/tests/run/inlineForeach.scala new file mode 100644 index 000000000..0c6135c6d --- /dev/null +++ b/tests/run/inlineForeach.scala @@ -0,0 +1,44 @@ +object Test { + + class Range(from: Int, end: Int) { + + inline + def foreach(inline op: Int => Unit): Unit = { + var i = from + while (i < end) { + op(i) + i += 1 + } + } + + def filter(p: Int => Boolean): List[Int] = ??? + } + + implicit class intWrapper(private val start: Int) extends AnyVal { + def until(end: Int) = new Range(start, end) + def to(limit: Int) = new Range(start, limit + 1) + }/* + + def matmul(xs: Array[Array[Double]], ys: Array[Array[Double]]): Array[Array[Double]] = { + def nrows = xs.length + def ncols = ys(0).length + def n = ys.length + assert(xs(0).length == n) + val zs = Array.ofDim[Double](nrows, ncols) + for (i <- intWrapper(0) until nrows) + for (j <- 0 until ncols) { + var x = 0.0 + for (k <- 0 until n) + x += xs(i)(k) * ys(k)(j) + zs(i)(j) = x + } + zs + } +*/ + def main(args: Array[String]) = { + /* 1.until(10).foreach(i => println(i)) + 1.until(10).foreach(println(_))*/ + 1.until(10).foreach(println) + for (i <- 1 to 10) println(i) + } +} -- cgit v1.2.3