Indirect tests for tail call diagnostics removed

This commit is contained in:
Andrey Breslav
2013-11-26 21:21:36 +04:00
parent 94500bd968
commit 0316e6cb8d
20 changed files with 80 additions and 451 deletions
@@ -1,12 +1,10 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
tailRecursive fun test(counter : Int, a : Any) : Int? {
tailRecursive fun test(counter : Int) : Int? {
if (counter < 0) return null
if (counter == 0) return 777
return <!NON_TAIL_RECURSIVE_CALL!>test<!>(-1, "no tail") ?: <!NON_TAIL_RECURSIVE_CALL!>test<!>(-2, "no tail") ?: test(counter - 1, "tail")
return <!NON_TAIL_RECURSIVE_CALL!>test<!>(-1) ?: <!NON_TAIL_RECURSIVE_CALL!>test<!>(-2) ?: test(counter - 1)
}
fun box() : String =
if (test(100000, "test") == 777) "OK"
if (test(100000) == 777) "OK"
else "FAIL"
@@ -2,9 +2,9 @@
class B {
inner class C {
tailRecursive fun h(counter : Int, x : Any) {
tailRecursive fun h(counter : Int) {
if (counter > 0) {
this@C.h(counter - 1, "tail")
this@C.h(counter - 1)
}
}
@@ -21,7 +21,7 @@ class B {
}
fun box() : String {
B().makeC().h(1000000, "test")
B().makeC().h(1000000)
B().makeC().h2(0)
return "OK"
}
@@ -1,16 +1,14 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
tailRecursive fun test(x : Int, a : Any) : Int {
tailRecursive fun test(x : Int) : Int {
var z = if (x > 3) 3 else x
while (z > 0) {
if (z > 10) {
return test(x - 1, "tail")
return test(x - 1)
}
<!NON_TAIL_RECURSIVE_CALL!>test<!>(0, "no tail")
<!NON_TAIL_RECURSIVE_CALL!>test<!>(0)
z = z - 1
}
return 1
}
fun box() : String = if (test(100000, "test") == 1) "OK" else "FAIL"
fun box() : String = if (test(100000) == 1) "OK" else "FAIL"
@@ -1,17 +1,15 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
tailRecursive fun test(x : Int, a : Any) : Int {
tailRecursive fun test(x : Int) : Int {
if (x == 1) {
if (x != 1) {
<!NON_TAIL_RECURSIVE_CALL!>test<!>(0, "no tail")
return test(0, "tail")
<!NON_TAIL_RECURSIVE_CALL!>test<!>(0)
return test(0)
} else {
return test(x + <!NON_TAIL_RECURSIVE_CALL!>test<!>(0, "no tail"), "tail")
return test(x + <!NON_TAIL_RECURSIVE_CALL!>test<!>(0))
}
} else if (x > 0) {
return test(x - 1, "tail")
return test(x - 1)
}
return -1
}
fun box() : String = if (test(1000000, "test") == -1) "OK" else "FAIL"
fun box() : String = if (test(1000000) == -1) "OK" else "FAIL"
@@ -1,10 +1,8 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun test() {
[tailRecursive] fun g3(counter : Int, x : Any) {
if (counter > 0) { g3(counter - 1, "tail") }
[tailRecursive] fun g3(counter : Int) {
if (counter > 0) { g3(counter - 1) }
}
g3(1000000, "test")
g3(1000000)
}
fun box() : String {
@@ -1,13 +1,11 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun test(counter : Int, a : Any) : Int<!> {
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun test(counter : Int) : Int<!> {
if (counter == 0) return 0
try {
throw Exception()
} catch (e : Exception) {
return <!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(counter - 1, "no tail")
return <!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(counter - 1)
}
}
fun box() : String = if (test(3, "test") == 0) "OK" else "FAIL"
fun box() : String = if (test(3) == 0) "OK" else "FAIL"
@@ -1,13 +1,11 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun test(counter : Int, a : Any) : Int<!> {
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun test(counter : Int) : Int<!> {
if (counter == 0) return 0
try {
// do nothing
} finally {
return <!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(counter - 1, "no tail")
return <!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(counter - 1)
}
}
fun box() : String = if (test(3, "test") == 0) "OK" else "FAIL"
fun box() : String = if (test(3) == 0) "OK" else "FAIL"
@@ -1,17 +1,15 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun test(counter : Int, a : Any) : Int<!> {
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun test(counter : Int) : Int<!> {
if (counter == 0) return 0
try {
// do nothing
} finally {
if (counter > 0) {
return <!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(counter - 1, "no tail")
return <!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(counter - 1)
}
}
return -1
}
fun box() : String = if (test(3, "test") == 0) "OK" else "FAIL"
fun box() : String = if (test(3) == 0) "OK" else "FAIL"
@@ -1,13 +1,11 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun test(counter : Int, a : Any) : Int<!> {
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun test(counter : Int) : Int<!> {
if (counter == 0) return 0
try {
return <!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(counter - 1, "no tail")
return <!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(counter - 1)
} catch (any : Throwable) {
return -1
}
}
fun box() : String = if (test(3, "test") == 0) "OK" else "FAIL"
fun box() : String = if (test(3) == 0) "OK" else "FAIL"
@@ -1,13 +1,11 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
tailRecursive fun test(x : Int, a : Any) : Int =
tailRecursive fun test(x : Int) : Int =
if (x == 1) {
<!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1, "no tail")
1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1, "no tail")
<!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
} else if (x > 0) {
test(x - 1, "tail")
test(x - 1)
} else {
0
}
fun box() : String = if (test(1000000, "test") == 1) "OK" else "FAIL"
fun box() : String = if (test(1000000) == 1) "OK" else "FAIL"
@@ -1,13 +1,11 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
tailRecursive fun test(x : Int, z : Any) : Int {
tailRecursive fun test(x : Int) : Int {
if (x == 10) {
return 1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1, "no tail")
return 1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
}
if (x > 0) {
return test(x - 1, "tail")
return test(x - 1)
}
return 0
}
fun box() : String = if (test(1000000, "test") == 1) "OK" else "FAIL"
fun box() : String = if (test(1000000) == 1) "OK" else "FAIL"
@@ -1,14 +1,12 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
tailRecursive fun test(x : Int, a : Any) : Int {
tailRecursive fun test(x : Int) : Int {
if (x == 0) {
return 0
} else if (x == 10) {
<!NON_TAIL_RECURSIVE_CALL!>test<!>(0, "no tail")
return 1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1, "no tail")
<!NON_TAIL_RECURSIVE_CALL!>test<!>(0)
return 1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
} else {
return test(x - 1, "tail")
return test(x - 1)
}
}
fun box() : String = if (test(1000000, "test") == 1) "OK" else "FAIL"
fun box() : String = if (test(1000000) == 1) "OK" else "FAIL"
@@ -1,25 +1,23 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class A {
tailRecursive fun f1(c : Int, x : Any) {
tailRecursive fun f1(c : Int) {
if (c > 0) {
this.f1(c - 1, "tail")
this.f1(c - 1)
}
}
tailRecursive fun f2(c : Int, x : Any) {
tailRecursive fun f2(c : Int) {
if (c > 0) {
f2(c - 1, "tail 108")
f2(c - 1)
}
}
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun f3(a : A, x : Any)<!> {
a.<!NON_TAIL_RECURSIVE_CALL!>f3<!>(a, "no tail") // non-tail recursion, could be potentially resolved by condition if (a == this) f3() else a.f3()
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun f3(a : A)<!> {
a.<!NON_TAIL_RECURSIVE_CALL!>f3<!>(a) // non-tail recursion, could be potentially resolved by condition if (a == this) f3() else a.f3()
}
}
fun box() : String {
A().f1(1000000, "test")
A().f2(1000000, "test")
A().f1(1000000)
A().f2(1000000)
return "OK"
}
@@ -1,23 +1,21 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
tailRecursive fun test(x : Int, e : Any) : Unit {
tailRecursive fun test(x : Int) : Unit {
if (x == 1) {
test(x - 1, "tail")
test(x - 1)
} else if (x == 2) {
test(x - 1, "tail")
test(x - 1)
return
} else if (x == 3) {
<!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1, "no tail")
<!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
if (x == 3) {
test(x - 1, "tail")
test(x - 1)
}
return
} else if (x > 0) {
test(x - 1, "tail")
test(x - 1)
}
}
fun box() : String {
test(1000000, "test")
test(1000000)
return "OK"
}
@@ -1,10 +1,8 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
tailRecursive fun withWhen(counter : Int, x : Any) : Int =
tailRecursive fun withWhen(counter : Int) : Int =
when (counter) {
0 -> counter
50 -> 1 + <!NON_TAIL_RECURSIVE_CALL!>withWhen<!>(counter - 1, "no tail")
else -> withWhen(counter - 1, "tail")
50 -> 1 + <!NON_TAIL_RECURSIVE_CALL!>withWhen<!>(counter - 1)
else -> withWhen(counter - 1)
}
fun box() : String = if (withWhen(100000, "test") == 1) "OK" else "FAIL"
fun box() : String = if (withWhen(100000) == 1) "OK" else "FAIL"
@@ -1,13 +1,13 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
tailRecursive fun withWhen(counter : Int, d : Any, x : Any) : Int =
tailRecursive fun withWhen(counter : Int, d : Any) : Int =
when (counter) {
0 -> counter
1, 2 -> withWhen(counter - 1, "1,2", "tail")
in 3..49 -> withWhen(counter - 1, "3..49", "tail")
50 -> 1 + <!NON_TAIL_RECURSIVE_CALL!>withWhen<!>(counter - 1, "50", "no tail")
!in 0..50 -> withWhen(counter - 1, "!0..50", "tail")
else -> withWhen(counter - 1, "else", "tail")
1, 2 -> withWhen(counter - 1, "1,2")
in 3..49 -> withWhen(counter - 1, "3..49")
50 -> 1 + <!NON_TAIL_RECURSIVE_CALL!>withWhen<!>(counter - 1, "50")
!in 0..50 -> withWhen(counter - 1, "!0..50")
else -> withWhen(counter - 1, "else")
}
fun box() : String = if (withWhen(100000, "test", "test") == 1) "OK" else "FAIL"
fun box() : String = if (withWhen(100000, "test") == 1) "OK" else "FAIL"
@@ -1,17 +1,15 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
tailRecursive fun withWhen(counter : Int, d : Any, x : Any) : Int =
tailRecursive fun withWhen(counter : Int, d : Any) : Int =
if (counter == 0) {
0
}
else if (counter == 5) {
withWhen(counter - 1, 999, "tail")
withWhen(counter - 1, 999)
}
else
when (d) {
is String -> withWhen(counter - 1, "is String", "tail")
is Number -> withWhen(counter, "is Number", "tail")
is String -> withWhen(counter - 1, "is String")
is Number -> withWhen(counter, "is Number")
else -> throw IllegalStateException()
}
fun box() : String = if (withWhen(100000, "test", "test") == 0) "OK" else "FAIL"
fun box() : String = if (withWhen(100000, "test") == 0) "OK" else "FAIL"
@@ -1,11 +1,9 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
tailRecursive fun withWhen2(counter : Int, x : Any) : Int =
tailRecursive fun withWhen2(counter : Int) : Int =
when {
counter == 0 -> counter
counter == 50 -> 1 + <!NON_TAIL_RECURSIVE_CALL!>withWhen2<!>(counter - 1, "no tail")
<!NON_TAIL_RECURSIVE_CALL!>withWhen2<!>(0, "no tail") == 0 -> withWhen2(counter - 1, "tail")
counter == 50 -> 1 + <!NON_TAIL_RECURSIVE_CALL!>withWhen2<!>(counter - 1)
<!NON_TAIL_RECURSIVE_CALL!>withWhen2<!>(0) == 0 -> withWhen2(counter - 1)
else -> 1
}
fun box() : String = if (withWhen2(100000, "test") == 1) "OK" else "FAIL"
fun box() : String = if (withWhen2(100000) == 1) "OK" else "FAIL"