Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tailcalls is more selective when reporting self-recursion
- Loading branch information
Showing
10 changed files
with
157 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
t12513b.scala:8: error: could not optimize @tailrec annotated method f: it contains a recursive call not in tail position | ||
@T def f: Int = { f ; 42 } // the annotation worked: error, f is not tail recursive | ||
^ | ||
^ | ||
1 error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
t1672b.scala:3: error: could not optimize @tailrec annotated method bar: it contains a recursive call not in tail position | ||
def bar : Nothing = { | ||
^ | ||
t1672b.scala:14: error: could not optimize @tailrec annotated method baz: it contains a recursive call not in tail position | ||
def baz : Nothing = { | ||
^ | ||
t1672b.scala:7: error: could not optimize @tailrec annotated method bar: it contains a recursive call not in tail position | ||
case _: Throwable => bar | ||
^ | ||
t1672b.scala:18: error: could not optimize @tailrec annotated method baz: it contains a recursive call not in tail position | ||
case _: Throwable => baz | ||
^ | ||
t1672b.scala:29: error: could not optimize @tailrec annotated method boz: it contains a recursive call not in tail position | ||
case _: Throwable => boz; ??? | ||
^ | ||
t1672b.scala:34: error: could not optimize @tailrec annotated method bez: it contains a recursive call not in tail position | ||
def bez : Nothing = { | ||
^ | ||
t1672b.scala:36: error: could not optimize @tailrec annotated method bez: it contains a recursive call not in tail position | ||
bez | ||
^ | ||
t1672b.scala:46: error: could not optimize @tailrec annotated method bar: it contains a recursive call not in tail position | ||
else 1 + (try { | ||
^ | ||
t1672b.scala:49: error: could not optimize @tailrec annotated method bar: it contains a recursive call not in tail position | ||
case _: Throwable => bar(i - 1) | ||
^ | ||
5 errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
t4649.scala:12: error: @tailrec annotated method contains no recursive calls | ||
@tailrec final def remove(idx: Int, count: Int): Unit = | ||
^ | ||
1 error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
import annotation.tailrec | ||
|
||
object Test { | ||
|
||
var sz = 3 | ||
def remove(idx: Int) = | ||
if (idx >= 0 && idx < sz) | ||
sz -= 1 | ||
else throw new IndexOutOfBoundsException(s"$idx is out of bounds (min 0, max ${sz-1})") | ||
|
||
@tailrec final def remove(idx: Int, count: Int): Unit = | ||
if (count > 0) { | ||
remove(idx) // at a glance, looks like a tailrec candidate, but must error in the end | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
t6526.scala:8: error: could not optimize @tailrec annotated method inner: it contains a recursive call not in tail position | ||
@tailrec def inner(i: Int): Int = 1 + inner(i) | ||
^ | ||
^ | ||
t6526.scala:14: error: could not optimize @tailrec annotated method inner: it contains a recursive call not in tail position | ||
@tailrec def inner(i: Int): Int = 1 + inner(i) | ||
^ | ||
^ | ||
t6526.scala:20: error: could not optimize @tailrec annotated method inner: it contains a recursive call not in tail position | ||
@tailrec def inner(i: Int): Int = 1 + inner(i) | ||
^ | ||
^ | ||
t6526.scala:30: error: could not optimize @tailrec annotated method inner: it contains a recursive call not in tail position | ||
@tailrec def inner(i: Int): Int = 1 + inner(i) | ||
^ | ||
^ | ||
t6526.scala:39: error: could not optimize @tailrec annotated method inner: it contains a recursive call not in tail position | ||
def inner(i: Int): Int = 1 + inner(i) | ||
^ | ||
^ | ||
5 errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
t6574.scala:4: error: could not optimize @tailrec annotated method notTailPos$extension: it contains a recursive call not in tail position | ||
println("tail") | ||
^ | ||
t6574.scala:3: error: could not optimize @tailrec annotated method notTailPos$extension: it contains a recursive call not in tail position | ||
this.notTailPos[Z](a)(b) | ||
^ | ||
1 error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
tailrec-4.scala:6: error: could not optimize @tailrec annotated method foo: it contains a recursive call not in tail position | ||
@tailrec def foo: Int = foo + 1 | ||
^ | ||
^ | ||
tailrec-4.scala:11: error: could not optimize @tailrec annotated method foo: it contains a recursive call not in tail position | ||
@tailrec def foo: Int = foo + 1 | ||
^ | ||
^ | ||
tailrec-4.scala:17: error: could not optimize @tailrec annotated method foo: it contains a recursive call not in tail position | ||
@tailrec def foo: Int = foo + 1 | ||
^ | ||
^ | ||
tailrec-4.scala:23: error: could not optimize @tailrec annotated method foo: it contains a recursive call not in tail position | ||
@tailrec def foo: Int = foo + 1 | ||
^ | ||
^ | ||
tailrec-4.scala:31: error: could not optimize @tailrec annotated method foo: it contains a recursive call not in tail position | ||
@tailrec def foo: Int = foo + 1 | ||
^ | ||
^ | ||
5 errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,37 @@ | ||
//> abusing options -Vlog:tailcalls -Vdebug -Vprint:~tailcalls | ||
|
||
import annotation.tailrec | ||
|
||
// scalac: -Xfatal-warnings | ||
// | ||
object Test { | ||
// @annotation.tailrec | ||
@tailrec | ||
def lazyFilter[E](s: LazyList[E], p: E => Boolean): LazyList[E] = s match { | ||
case h #:: t => if (p(h)) h #:: lazyFilter(t, p) else lazyFilter(t, p) | ||
case _ => LazyList.empty[E] | ||
} | ||
|
||
@tailrec | ||
def f(i: Int): Int = | ||
if (i <= 0) i | ||
/* not optimized | ||
else if (i == 27) { | ||
val x = f(i - 1) | ||
x | ||
} | ||
*/ | ||
else if (i == 42) { | ||
val g: Int => Int = f(_) | ||
f(i - 1) | ||
} | ||
else f(i - 1) | ||
|
||
var sz = 3 | ||
def remove(idx: Int) = | ||
if (idx >= 0 && idx < sz) | ||
sz -= 1 | ||
else throw new IndexOutOfBoundsException(s"$idx is out of bounds (min 0, max ${sz-1})") | ||
|
||
@tailrec final def remove(idx: Int, count: Int): Unit = | ||
if (count > 0) { | ||
remove(idx) // after rewrite, don't flag me as a leftover tailrec | ||
remove(idx, count-1) | ||
} | ||
} |