lampepfl/dotty

Consider implementing per-tailcall-position tailrec annotation

DarkDimius opened this issue · 1 comments

Consider a method of form

final def foo(a: Int): Int = {
  if (foo(a - 1) > 0) foo(a - 1) 
  else foo(a - 2)
}

During discussion with @sirthias I understood that it's now commonly known tailrec would actually transform such a method, though it cannot be annotated with @tailrec as it contains recursive calls in non-tail position.

It would be great if it was possible to annotate specific calls, eg:

final def foo(a: Int): Int = {
  if (foo(a - 1) > 0) 
    foo(a - 1): @tailrec 
  else 
    foo(a - 2): @tailrec
}

Implemented in #1227 long time ago.