Tail-call detection support in the front-end

This commit is contained in:
Sergey Mashkov
2013-11-26 18:56:18 +04:00
committed by Andrey Breslav
parent 83b4ad4eac
commit 1c81102941
19 changed files with 684 additions and 6 deletions
@@ -0,0 +1,3 @@
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun noTails()<!> {
// nothing here
}
@@ -0,0 +1,12 @@
tailRecursive fun badTails(x : Int) : Int {
if (x > 0) {
return 1 + <!NON_TAIL_RECURSIVE_CALL!>badTails<!>(x - 1)
}
else if (x == 10) {
[suppress("NON_TAIL_RECURSIVE_CALL")]
return 1 + badTails(x - 1)
} else if (x == 50) {
return badTails(x - 1)
}
return 0
}
@@ -0,0 +1,6 @@
fun withoutAnnotation(x : Int) : Int {
if (x > 0) {
return 1 + withoutAnnotation(x - 1)
}
return 0
}
@@ -0,0 +1,9 @@
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun test() : Unit<!> {
try {
<!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>()
} catch (any : Exception) {
<!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>()
} finally {
<!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>()
}
}