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
+4 -3
View File
@@ -1249,6 +1249,10 @@ kotlin.annotation.target(allowedTargets = {AnnotationTarget.CLASSIFIER, Annotati
internal final fun <get-names>(): kotlin.Array<out kotlin.String> internal final fun <get-names>(): kotlin.Array<out kotlin.String>
} }
kotlin.annotation.target(allowedTargets = {AnnotationTarget.FUNCTION}) kotlin.annotation.annotation(retention = AnnotationRetention.SOURCE) public final class TailRecursive : kotlin.Annotation {
/*primary*/ public constructor TailRecursive()
}
public open class Throwable { public open class Throwable {
/*primary*/ public constructor Throwable(/*0*/ message: kotlin.String? = ..., /*1*/ cause: kotlin.Throwable? = ...) /*primary*/ public constructor Throwable(/*0*/ message: kotlin.String? = ..., /*1*/ cause: kotlin.Throwable? = ...)
public final fun getCause(): kotlin.Throwable? public final fun getCause(): kotlin.Throwable?
@@ -1287,6 +1291,3 @@ kotlin.annotation.target(allowedTargets = {AnnotationTarget.VALUE_PARAMETER}) ko
kotlin.annotation.target(allowedTargets = {AnnotationTarget.VALUE_PARAMETER}) kotlin.annotation.annotation(mustBeDocumented = true, retention = AnnotationRetention.RUNTIME) public final class noinline : kotlin.Annotation { kotlin.annotation.target(allowedTargets = {AnnotationTarget.VALUE_PARAMETER}) kotlin.annotation.annotation(mustBeDocumented = true, retention = AnnotationRetention.RUNTIME) public final class noinline : kotlin.Annotation {
/*primary*/ public constructor noinline() /*primary*/ public constructor noinline()
} }
kotlin.annotation.target(allowedTargets = {AnnotationTarget.FUNCTION}) kotlin.annotation.annotation(retention = AnnotationRetention.SOURCE) public final class tailRecursive : kotlin.Annotation {
/*primary*/ public constructor tailRecursive()
}
+1 -1
View File
@@ -1,5 +1,5 @@
== test == == test ==
tailRecursive fun test() : Int { tailrec fun test() : Int {
try { try {
// do nothing // do nothing
} finally { } finally {
+1 -1
View File
@@ -1,4 +1,4 @@
tailRecursive fun test() : Int { tailrec fun test() : Int {
try { try {
// do nothing // do nothing
} finally { } finally {
+1 -1
View File
@@ -1,5 +1,5 @@
== test == == test ==
tailRecursive fun test() : Int { tailrec fun test() : Int {
try { try {
// do nothing // do nothing
} finally { } finally {
@@ -1,5 +1,5 @@
== test == == test ==
tailRecursive fun test() : Int { tailrec fun test() : Int {
try { try {
// do nothing // do nothing
} finally { } finally {
+1 -1
View File
@@ -1,4 +1,4 @@
tailRecursive fun test() : Int { tailrec fun test() : Int {
try { try {
// do nothing // do nothing
} finally { } finally {
+1 -1
View File
@@ -1,5 +1,5 @@
== test == == test ==
tailRecursive fun test() : Int { tailrec fun test() : Int {
try { try {
// do nothing // do nothing
} finally { } finally {
+1 -1
View File
@@ -1,5 +1,5 @@
== sum == == sum ==
tailRecursive fun sum(x: Long, sum: Long): Long { tailrec fun sum(x: Long, sum: Long): Long {
if (x == 0.toLong()) return sum if (x == 0.toLong()) return sum
return sum(x - 1, sum + x) return sum(x - 1, sum + x)
} }
+1 -1
View File
@@ -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 if (x == 0.toLong()) return sum
return sum(x - 1, sum + x) return sum(x - 1, sum + x)
} }
+1 -1
View File
@@ -1,5 +1,5 @@
== sum == == sum ==
tailRecursive fun sum(x: Long, sum: Long): Long { tailrec fun sum(x: Long, sum: Long): Long {
if (x == 0.toLong()) return sum if (x == 0.toLong()) return sum
return sum(x - 1, sum + x) return sum(x - 1, sum + x)
} }
+1 -1
View File
@@ -1,5 +1,5 @@
== foo == == foo ==
tailRecursive fun foo() { tailrec fun foo() {
try { try {
return foo() return foo()
} }
+1 -1
View File
@@ -1,4 +1,4 @@
tailRecursive fun foo() { tailrec fun foo() {
try { try {
return foo() return foo()
} }
+1 -1
View File
@@ -1,5 +1,5 @@
== foo == == foo ==
tailRecursive fun foo() { tailrec fun foo() {
try { try {
return foo() return foo()
} }
@@ -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")) { if (!e.equals("a")) {
throw IllegalArgumentException() throw IllegalArgumentException()
} }
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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 // !DIAGNOSTICS: -UNUSED_PARAMETER
tailRecursive fun Int.foo(x: Int) { tailrec fun Int.foo(x: Int) {
if (x == 0) return if (x == 0) return
return 1.foo(x - 1) return 1.foo(x - 1)
} }
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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 // nothing here
} }
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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) { if (x < 50 && x != 10 && x > 0) {
return 1 + <!NON_TAIL_RECURSIVE_CALL!>badTails<!>(x - 1) return 1 + <!NON_TAIL_RECURSIVE_CALL!>badTails<!>(x - 1)
} }
@@ -1,4 +1,4 @@
package 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 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) { if (this > 1) {
return (this - 1) test x return (this - 1) test x
} }
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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 // !DIAGNOSTICS: -UNUSED_PARAMETER
tailRecursive fun Int.foo(x: Int) { tailrec fun Int.foo(x: Int) {
if (x == 0) return if (x == 0) return
val xx = x - 1 val xx = x - 1
return 1 foo xx return 1 foo xx
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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 null
if (counter == 0) return 777 if (counter == 0) return 777
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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 { class B {
inner class C { inner class C {
tailRecursive fun h(counter : Int) { tailrec fun h(counter : Int) {
if (counter > 0) { if (counter > 0) {
this@C.h(counter - 1) 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 this@B.h2("no recursion") // keep vigilance
} }
@@ -13,8 +13,8 @@ internal final class B {
internal final inner class C { internal final inner class C {
public constructor C() public constructor C()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean 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.tailrec() 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 h2(/*0*/ x: kotlin.Any): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String 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 var z = if (x > 3) 3 else x
while (z > 0) { while (z > 0) {
if (z > 10) { if (z > 10) {
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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) {
if (x != 1) { if (x != 1) {
<!NON_TAIL_RECURSIVE_CALL!>test<!>(0) <!NON_TAIL_RECURSIVE_CALL!>test<!>(0)
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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 if (!hasNext()) acc
else foldl(foldFunction(next(), acc), foldFunction) else foldl(foldFunction(next(), acc), foldFunction)
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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 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() if (i == length()) result.toString()
else escape(i + 1, result.append(escapeChar(get(i)))) else escape(i + 1, result.append(escapeChar(get(i))))
@@ -2,4 +2,4 @@ package
internal fun box(): kotlin.String internal fun box(): kotlin.String
internal fun escapeChar(/*0*/ c: kotlin.Char): 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() if (num == 0) acc.toString()
else repeat(num - 1, acc.append(this)) else repeat(num - 1, acc.append(this))
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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 // !DIAGNOSTICS: -UNUSED_PARAMETER
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun foo()<!> { <!NO_TAIL_CALLS_FOUND!>tailrec fun foo()<!> {
bar { bar {
<!NON_TAIL_RECURSIVE_CALL!>foo<!>() <!NON_TAIL_RECURSIVE_CALL!>foo<!>()
} }
@@ -2,4 +2,4 @@ package
internal fun bar(/*0*/ a: kotlin.Any): kotlin.Unit internal fun bar(/*0*/ a: kotlin.Any): kotlin.Unit
internal fun box(): kotlin.String 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() { fun bar() {
<!NON_TAIL_RECURSIVE_CALL!>foo<!>() <!NON_TAIL_RECURSIVE_CALL!>foo<!>()
} }
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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() { fun test() {
@tailRecursive fun g3(counter : Int) { @tailrec fun g3(counter : Int) {
if (counter > 0) { g3(counter - 1) } if (counter > 0) { g3(counter - 1) }
} }
g3(1000000) g3(1000000)
@@ -1,4 +1,4 @@
tailRecursive fun test(x : Int) : Int { tailrec fun test(x : Int) : Int {
return if (x == 1) { return if (x == 1) {
<!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1) <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1) 1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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 if (counter == 0) return 0
try { try {
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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 if (counter == 0) return 0
try { try {
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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 if (counter == 0) return 0
try { try {
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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 if (x == 0) return
(return foo(x - 1)) (return foo(x - 1))
} }
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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 if (counter == 0) return 0
try { try {
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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) { if (x == 1) {
<!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1) <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1) 1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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) { if (x == 10) {
return 1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1) return 1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
} }
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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) { if (x == 0) {
return 0 return 0
} else if (x == 10) { } else if (x == 10) {
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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 if (x == 0.toLong()) return sum
return sum(x - 1, sum + x) return sum(x - 1, sum + x)
} }
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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) { return if (x > 0) {
(foo(x - 1)) (foo(x - 1))
} }
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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 if (x == 0) return
return (foo(x - 1)) return (foo(x - 1))
} }
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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 if (!go) return
try { try {
<!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(false) <!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(false)
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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 { class A {
tailRecursive fun f1(c : Int) { tailrec fun f1(c : Int) {
if (c > 0) { if (c > 0) {
this.f1(c - 1) this.f1(c - 1)
} }
} }
tailRecursive fun f2(c : Int) { tailrec fun f2(c : Int) {
if (c > 0) { if (c > 0) {
f2(c - 1) 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() 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 { internal final class A {
public constructor A() public constructor A()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean 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.tailrec() internal final fun f1(/*0*/ c: kotlin.Int): kotlin.Unit
kotlin.tailRecursive() internal final fun f2(/*0*/ c: kotlin.Int): kotlin.Unit kotlin.tailrec() 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 f3(/*0*/ a: A): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String 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) { if (x == 1) {
test(x - 1) test(x - 1)
} else if (x == 2) { } else if (x == 2) {
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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) { when (counter) {
0 -> counter 0 -> counter
50 -> 1 + <!NON_TAIL_RECURSIVE_CALL!>withWhen<!>(counter - 1) 50 -> 1 + <!NON_TAIL_RECURSIVE_CALL!>withWhen<!>(counter - 1)
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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 // !DIAGNOSTICS: -UNUSED_PARAMETER
tailRecursive fun withWhen(counter : Int, d : Any) : Int = tailrec fun withWhen(counter : Int, d : Any) : Int =
when (counter) { when (counter) {
0 -> counter 0 -> counter
1, 2 -> withWhen(counter - 1, "1,2") 1, 2 -> withWhen(counter - 1, "1,2")
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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) { if (counter == 0) {
0 0
} }
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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 { when {
counter == 0 -> counter counter == 0 -> counter
counter == 50 -> 1 + <!NON_TAIL_RECURSIVE_CALL!>withWhen2<!>(counter - 1) counter == 50 -> 1 + <!NON_TAIL_RECURSIVE_CALL!>withWhen2<!>(counter - 1)
@@ -1,4 +1,4 @@
package package
internal fun box(): kotlin.String 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
+3
View File
@@ -78,6 +78,9 @@ public annotation(retention = SOURCE) class Suppress(vararg val names: String)
target(FUNCTION) target(FUNCTION)
public annotation(retention = SOURCE) class tailRecursive public annotation(retention = SOURCE) class tailRecursive
target(FUNCTION)
public annotation(retention = SOURCE) class tailrec
/** /**
* Hides the annotated function, property or constructor from the overload resolution, * Hides the annotated function, property or constructor from the overload resolution,
* thus preventing its usages from newly compiled code, but keeps compiling it * thus preventing its usages from newly compiled code, but keeps compiling it
@@ -171,7 +171,8 @@ public class KotlinBuiltIns {
public final FqName data = fqName("data"); public final FqName data = fqName("data");
public final FqName deprecated = fqName("deprecated"); public final FqName deprecated = fqName("deprecated");
public final FqName tailRecursive = fqName("tailRecursive"); public final FqName tailRecursive = fqName("tailrec");
public final FqName tailRecursiveDeprecated = fqName("tailRecursive");
public final FqName inline = fqName("inline"); public final FqName inline = fqName("inline");
public final FqName noinline = fqName("noinline"); public final FqName noinline = fqName("noinline");
public final FqName inlineOptions = fqName("inlineOptions"); public final FqName inlineOptions = fqName("inlineOptions");
@@ -1031,7 +1032,8 @@ public class KotlinBuiltIns {
} }
public static boolean isTailRecursive(@NotNull DeclarationDescriptor declarationDescriptor) { public static boolean isTailRecursive(@NotNull DeclarationDescriptor declarationDescriptor) {
return containsAnnotation(declarationDescriptor, FQ_NAMES.tailRecursive); return containsAnnotation(declarationDescriptor, FQ_NAMES.tailRecursive)
|| containsAnnotation(declarationDescriptor, FQ_NAMES.tailRecursiveDeprecated);
} }
/** Checks that the symbol represented by the descriptor is annotated with the {@code kotlin.noinline} annotation */ /** Checks that the symbol represented by the descriptor is annotated with the {@code kotlin.noinline} annotation */