Deprecate tailRecursive in favor of tailrec

This commit is contained in:
Denis Zharkov
2015-09-04 16:30:25 +03:00
parent bbc192fda5
commit 9254b1b461
84 changed files with 98 additions and 92 deletions
@@ -1,4 +1,4 @@
tailRecursive fun test(x : Int = 0, e : Any = "a") {
tailrec fun test(x : Int = 0, e : Any = "a") {
if (!e.equals("a")) {
throw IllegalArgumentException()
}
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun test(/*0*/ x: kotlin.Int = ..., /*1*/ e: kotlin.Any = ...): kotlin.Unit
kotlin.tailrec() internal fun test(/*0*/ x: kotlin.Int = ..., /*1*/ e: kotlin.Any = ...): kotlin.Unit
@@ -1,5 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
tailRecursive fun Int.foo(x: Int) {
tailrec fun Int.foo(x: Int) {
if (x == 0) return
return 1.foo(x - 1)
}
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun kotlin.Int.foo(/*0*/ x: kotlin.Int): kotlin.Unit
kotlin.tailrec() internal fun kotlin.Int.foo(/*0*/ x: kotlin.Int): kotlin.Unit
@@ -1,4 +1,4 @@
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun noTails()<!> {
<!NO_TAIL_CALLS_FOUND!>tailrec fun noTails()<!> {
// nothing here
}
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun noTails(): kotlin.Unit
kotlin.tailrec() internal fun noTails(): kotlin.Unit
@@ -1,4 +1,4 @@
tailRecursive fun badTails(x : Int) : Int {
tailrec fun badTails(x : Int) : Int {
if (x < 50 && x != 10 && x > 0) {
return 1 + <!NON_TAIL_RECURSIVE_CALL!>badTails<!>(x - 1)
}
@@ -1,4 +1,4 @@
package
kotlin.tailRecursive() internal fun badTails(/*0*/ x: kotlin.Int): kotlin.Int
kotlin.tailrec() internal fun badTails(/*0*/ x: kotlin.Int): kotlin.Int
internal fun box(): kotlin.String
@@ -1,4 +1,4 @@
tailRecursive fun Int.test(x : Int) : Int {
tailrec fun Int.test(x : Int) : Int {
if (this > 1) {
return (this - 1) test x
}
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun kotlin.Int.test(/*0*/ x: kotlin.Int): kotlin.Int
kotlin.tailrec() internal fun kotlin.Int.test(/*0*/ x: kotlin.Int): kotlin.Int
@@ -1,5 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
tailRecursive fun Int.foo(x: Int) {
tailrec fun Int.foo(x: Int) {
if (x == 0) return
val xx = x - 1
return 1 foo xx
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun kotlin.Int.foo(/*0*/ x: kotlin.Int): kotlin.Unit
kotlin.tailrec() internal fun kotlin.Int.foo(/*0*/ x: kotlin.Int): kotlin.Unit
@@ -1,4 +1,4 @@
tailRecursive fun test(counter : Int) : Int? {
tailrec fun test(counter : Int) : Int? {
if (counter < 0) return null
if (counter == 0) return 777
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun test(/*0*/ counter: kotlin.Int): kotlin.Int?
kotlin.tailrec() internal fun test(/*0*/ counter: kotlin.Int): kotlin.Int?
@@ -2,13 +2,13 @@
class B {
inner class C {
tailRecursive fun h(counter : Int) {
tailrec fun h(counter : Int) {
if (counter > 0) {
this@C.h(counter - 1)
}
}
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun h2(x : Any)<!> {
<!NO_TAIL_CALLS_FOUND!>tailrec fun h2(x : Any)<!> {
this@B.h2("no recursion") // keep vigilance
}
@@ -13,8 +13,8 @@ internal final class B {
internal final inner class C {
public constructor C()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
kotlin.tailRecursive() internal final fun h(/*0*/ counter: kotlin.Int): kotlin.Unit
kotlin.tailRecursive() internal final fun h2(/*0*/ x: kotlin.Any): kotlin.Unit
kotlin.tailrec() internal final fun h(/*0*/ counter: kotlin.Int): kotlin.Unit
kotlin.tailrec() internal final fun h2(/*0*/ x: kotlin.Any): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -1,4 +1,4 @@
tailRecursive fun test(x : Int) : Int {
tailrec fun test(x : Int) : Int {
var z = if (x > 3) 3 else x
while (z > 0) {
if (z > 10) {
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun test(/*0*/ x: kotlin.Int): kotlin.Int
kotlin.tailrec() internal fun test(/*0*/ x: kotlin.Int): kotlin.Int
@@ -1,4 +1,4 @@
tailRecursive fun test(x : Int) : Int {
tailrec fun test(x : Int) : Int {
if (x == 1) {
if (x != 1) {
<!NON_TAIL_RECURSIVE_CALL!>test<!>(0)
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun test(/*0*/ x: kotlin.Int): kotlin.Int
kotlin.tailrec() internal fun test(/*0*/ x: kotlin.Int): kotlin.Int
@@ -1,4 +1,4 @@
tailRecursive fun <T, A> Iterator<T>.foldl(acc : A, foldFunction : (e : T, acc : A) -> A) : A =
tailrec fun <T, A> Iterator<T>.foldl(acc : A, foldFunction : (e : T, acc : A) -> A) : A =
if (!hasNext()) acc
else foldl(foldFunction(next(), acc), foldFunction)
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun </*0*/ T, /*1*/ A> kotlin.Iterator<T>.foldl(/*0*/ acc: A, /*1*/ foldFunction: (T, A) -> A): A
kotlin.tailrec() internal fun </*0*/ T, /*1*/ A> kotlin.Iterator<T>.foldl(/*0*/ acc: A, /*1*/ foldFunction: (T, A) -> A): A
@@ -5,7 +5,7 @@ fun escapeChar(c : Char) : String? = when (c) {
else -> "" + c
}
tailRecursive fun String.escape(i : Int = 0, result : StringBuilder = StringBuilder()) : String =
tailrec fun String.escape(i : Int = 0, result : StringBuilder = StringBuilder()) : String =
if (i == length()) result.toString()
else escape(i + 1, result.append(escapeChar(get(i))))
@@ -2,4 +2,4 @@ package
internal fun box(): kotlin.String
internal fun escapeChar(/*0*/ c: kotlin.Char): kotlin.String?
kotlin.tailRecursive() internal fun kotlin.String.escape(/*0*/ i: kotlin.Int = ..., /*1*/ result: java.lang.StringBuilder = ...): kotlin.String
kotlin.tailrec() internal fun kotlin.String.escape(/*0*/ i: kotlin.Int = ..., /*1*/ result: java.lang.StringBuilder = ...): kotlin.String
@@ -1,4 +1,4 @@
tailRecursive fun String.repeat(num : Int, acc : StringBuilder = StringBuilder()) : String =
tailrec fun String.repeat(num : Int, acc : StringBuilder = StringBuilder()) : String =
if (num == 0) acc.toString()
else repeat(num - 1, acc.append(this))
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun kotlin.String.repeat(/*0*/ num: kotlin.Int, /*1*/ acc: java.lang.StringBuilder = ...): kotlin.String
kotlin.tailrec() internal fun kotlin.String.repeat(/*0*/ num: kotlin.Int, /*1*/ acc: java.lang.StringBuilder = ...): kotlin.String
@@ -1,5 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun foo()<!> {
<!NO_TAIL_CALLS_FOUND!>tailrec fun foo()<!> {
bar {
<!NON_TAIL_RECURSIVE_CALL!>foo<!>()
}
@@ -2,4 +2,4 @@ package
internal fun bar(/*0*/ a: kotlin.Any): kotlin.Unit
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun foo(): kotlin.Unit
kotlin.tailrec() internal fun foo(): kotlin.Unit
@@ -1,4 +1,4 @@
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun foo()<!> {
<!NO_TAIL_CALLS_FOUND!>tailrec fun foo()<!> {
fun bar() {
<!NON_TAIL_RECURSIVE_CALL!>foo<!>()
}
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun foo(): kotlin.Unit
kotlin.tailrec() internal fun foo(): kotlin.Unit
@@ -1,5 +1,5 @@
fun test() {
@tailRecursive fun g3(counter : Int) {
@tailrec fun g3(counter : Int) {
if (counter > 0) { g3(counter - 1) }
}
g3(1000000)
@@ -1,4 +1,4 @@
tailRecursive fun test(x : Int) : Int {
tailrec fun test(x : Int) : Int {
return if (x == 1) {
<!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun test(/*0*/ x: kotlin.Int): kotlin.Int
kotlin.tailrec() internal fun test(/*0*/ x: kotlin.Int): kotlin.Int
@@ -1,4 +1,4 @@
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun test(counter : Int) : Int<!> {
<!NO_TAIL_CALLS_FOUND!>tailrec fun test(counter : Int) : Int<!> {
if (counter == 0) return 0
try {
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun test(/*0*/ counter: kotlin.Int): kotlin.Int
kotlin.tailrec() internal fun test(/*0*/ counter: kotlin.Int): kotlin.Int
@@ -1,4 +1,4 @@
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun test(counter : Int) : Int<!> {
<!NO_TAIL_CALLS_FOUND!>tailrec fun test(counter : Int) : Int<!> {
if (counter == 0) return 0
try {
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun test(/*0*/ counter: kotlin.Int): kotlin.Int
kotlin.tailrec() internal fun test(/*0*/ counter: kotlin.Int): kotlin.Int
@@ -1,4 +1,4 @@
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun test(counter : Int) : Int<!> {
<!NO_TAIL_CALLS_FOUND!>tailrec fun test(counter : Int) : Int<!> {
if (counter == 0) return 0
try {
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun test(/*0*/ counter: kotlin.Int): kotlin.Int
kotlin.tailrec() internal fun test(/*0*/ counter: kotlin.Int): kotlin.Int
@@ -1,4 +1,4 @@
tailRecursive fun foo(x: Int) {
tailrec fun foo(x: Int) {
if (x == 0) return
(return foo(x - 1))
}
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun foo(/*0*/ x: kotlin.Int): kotlin.Unit
kotlin.tailrec() internal fun foo(/*0*/ x: kotlin.Int): kotlin.Unit
@@ -1,4 +1,4 @@
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun test(counter : Int) : Int<!> {
<!NO_TAIL_CALLS_FOUND!>tailrec fun test(counter : Int) : Int<!> {
if (counter == 0) return 0
try {
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun test(/*0*/ counter: kotlin.Int): kotlin.Int
kotlin.tailrec() internal fun test(/*0*/ counter: kotlin.Int): kotlin.Int
@@ -1,4 +1,4 @@
tailRecursive fun test(x : Int) : Int =
tailrec fun test(x : Int) : Int =
if (x == 1) {
<!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun test(/*0*/ x: kotlin.Int): kotlin.Int
kotlin.tailrec() internal fun test(/*0*/ x: kotlin.Int): kotlin.Int
@@ -1,4 +1,4 @@
tailRecursive fun test(x : Int) : Int {
tailrec fun test(x : Int) : Int {
if (x == 10) {
return 1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
}
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun test(/*0*/ x: kotlin.Int): kotlin.Int
kotlin.tailrec() internal fun test(/*0*/ x: kotlin.Int): kotlin.Int
@@ -1,4 +1,4 @@
tailRecursive fun test(x : Int) : Int {
tailrec fun test(x : Int) : Int {
if (x == 0) {
return 0
} else if (x == 10) {
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun test(/*0*/ x: kotlin.Int): kotlin.Int
kotlin.tailrec() internal fun test(/*0*/ x: kotlin.Int): kotlin.Int
@@ -1,4 +1,4 @@
tailRecursive fun sum(x: Long, sum: Long): Long {
tailrec fun sum(x: Long, sum: Long): Long {
if (x == 0.toLong()) return sum
return sum(x - 1, sum + x)
}
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun sum(/*0*/ x: kotlin.Long, /*1*/ sum: kotlin.Long): kotlin.Long
kotlin.tailrec() internal fun sum(/*0*/ x: kotlin.Long, /*1*/ sum: kotlin.Long): kotlin.Long
@@ -1,4 +1,4 @@
tailRecursive fun foo(x: Int) {
tailrec fun foo(x: Int) {
return if (x > 0) {
(foo(x - 1))
}
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun foo(/*0*/ x: kotlin.Int): kotlin.Unit
kotlin.tailrec() internal fun foo(/*0*/ x: kotlin.Int): kotlin.Unit
@@ -1,4 +1,4 @@
tailRecursive fun foo(x: Int) {
tailrec fun foo(x: Int) {
if (x == 0) return
return (foo(x - 1))
}
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun foo(/*0*/ x: kotlin.Int): kotlin.Unit
kotlin.tailrec() internal fun foo(/*0*/ x: kotlin.Int): kotlin.Unit
@@ -1,4 +1,4 @@
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun test(go: Boolean) : Unit<!> {
<!NO_TAIL_CALLS_FOUND!>tailrec fun test(go: Boolean) : Unit<!> {
if (!go) return
try {
<!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(false)
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun test(/*0*/ go: kotlin.Boolean): kotlin.Unit
kotlin.tailrec() internal fun test(/*0*/ go: kotlin.Boolean): kotlin.Unit
@@ -1,17 +1,17 @@
class A {
tailRecursive fun f1(c : Int) {
tailrec fun f1(c : Int) {
if (c > 0) {
this.f1(c - 1)
}
}
tailRecursive fun f2(c : Int) {
tailrec fun f2(c : Int) {
if (c > 0) {
f2(c - 1)
}
}
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun f3(a : A)<!> {
<!NO_TAIL_CALLS_FOUND!>tailrec 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()
}
}
@@ -5,9 +5,9 @@ internal fun box(): kotlin.String
internal final class A {
public constructor A()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
kotlin.tailRecursive() internal final fun f1(/*0*/ c: kotlin.Int): kotlin.Unit
kotlin.tailRecursive() internal final fun f2(/*0*/ c: kotlin.Int): kotlin.Unit
kotlin.tailRecursive() internal final fun f3(/*0*/ a: A): kotlin.Unit
kotlin.tailrec() internal final fun f1(/*0*/ c: kotlin.Int): kotlin.Unit
kotlin.tailrec() internal final fun f2(/*0*/ c: kotlin.Int): kotlin.Unit
kotlin.tailrec() internal final fun f3(/*0*/ a: A): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -1,4 +1,4 @@
tailRecursive fun test(x : Int) : Unit {
tailrec fun test(x : Int) : Unit {
if (x == 1) {
test(x - 1)
} else if (x == 2) {
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun test(/*0*/ x: kotlin.Int): kotlin.Unit
kotlin.tailrec() internal fun test(/*0*/ x: kotlin.Int): kotlin.Unit
@@ -1,4 +1,4 @@
tailRecursive fun withWhen(counter : Int) : Int =
tailrec fun withWhen(counter : Int) : Int =
when (counter) {
0 -> counter
50 -> 1 + <!NON_TAIL_RECURSIVE_CALL!>withWhen<!>(counter - 1)
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun withWhen(/*0*/ counter: kotlin.Int): kotlin.Int
kotlin.tailrec() internal fun withWhen(/*0*/ counter: kotlin.Int): kotlin.Int
@@ -1,6 +1,6 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
tailRecursive fun withWhen(counter : Int, d : Any) : Int =
tailrec fun withWhen(counter : Int, d : Any) : Int =
when (counter) {
0 -> counter
1, 2 -> withWhen(counter - 1, "1,2")
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun withWhen(/*0*/ counter: kotlin.Int, /*1*/ d: kotlin.Any): kotlin.Int
kotlin.tailrec() internal fun withWhen(/*0*/ counter: kotlin.Int, /*1*/ d: kotlin.Any): kotlin.Int
@@ -1,4 +1,4 @@
tailRecursive fun withWhen(counter : Int, d : Any) : Int =
tailrec fun withWhen(counter : Int, d : Any) : Int =
if (counter == 0) {
0
}
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun withWhen(/*0*/ counter: kotlin.Int, /*1*/ d: kotlin.Any): kotlin.Int
kotlin.tailrec() internal fun withWhen(/*0*/ counter: kotlin.Int, /*1*/ d: kotlin.Any): kotlin.Int
@@ -1,4 +1,4 @@
tailRecursive fun withWhen2(counter : Int) : Int =
tailrec fun withWhen2(counter : Int) : Int =
when {
counter == 0 -> counter
counter == 50 -> 1 + <!NON_TAIL_RECURSIVE_CALL!>withWhen2<!>(counter - 1)
@@ -1,4 +1,4 @@
package
internal fun box(): kotlin.String
kotlin.tailRecursive() internal fun withWhen2(/*0*/ counter: kotlin.Int): kotlin.Int
kotlin.tailrec() internal fun withWhen2(/*0*/ counter: kotlin.Int): kotlin.Int