From c6c58071a785af3a55e7e51339461e86c58ae876 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Mon, 3 Nov 2014 11:11:28 +1000 Subject: SI-8893 Test tailcall transform for mix of tail/non-tail recursion Another excellent test suggestion by Dear Reviewer. After tail calls, the transform results in: ``` def tick(i: Int): Unit = { val _$this: Test.type = Test.this; _tick(_$this: Test.type, i: Int){ if (i.==(0)) () else if (i.==(42)) { Test.this.tick(0); _tick(Test.this, i.-(1).asInstanceOf[Int]()) } else _tick(Test.this, i.-(1).asInstanceOf[Int]()).asInstanceOf[Unit]() } }; ``` We test this by mostly exercising the tail-recursive code path with a level of recursion that would overflow the stack if we weren't using jumps. --- test/files/run/t8893b.scala | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 test/files/run/t8893b.scala (limited to 'test') diff --git a/test/files/run/t8893b.scala b/test/files/run/t8893b.scala new file mode 100644 index 0000000000..19120871aa --- /dev/null +++ b/test/files/run/t8893b.scala @@ -0,0 +1,15 @@ +// Testing that recursive calls in tail positions are replaced with +// jumps, even though the method contains recursive calls outside +// of the tail position. +object Test { + def tick(i : Int): Unit = + if (i == 0) () + else if (i == 42) { + tick(0) /*not in tail posiiton*/ + tick(i - 1) + } else tick(i - 1) + + def main(args: Array[String]): Unit = { + tick(1000000) + } +} -- cgit v1.2.3