Skip to content

Commit c6c5807

Browse files
committed
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 = { <synthetic> 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.
1 parent cae09d7 commit c6c5807

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test/files/run/t8893b.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Testing that recursive calls in tail positions are replaced with
2+
// jumps, even though the method contains recursive calls outside
3+
// of the tail position.
4+
object Test {
5+
def tick(i : Int): Unit =
6+
if (i == 0) ()
7+
else if (i == 42) {
8+
tick(0) /*not in tail posiiton*/
9+
tick(i - 1)
10+
} else tick(i - 1)
11+
12+
def main(args: Array[String]): Unit = {
13+
tick(1000000)
14+
}
15+
}

0 commit comments

Comments
 (0)