Skip to content

tailrec optimization of def's involving implicit functions #4196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Mar 26, 2018 · 0 comments
Closed

tailrec optimization of def's involving implicit functions #4196

ghost opened this issue Mar 26, 2018 · 0 comments

Comments

@ghost
Copy link

ghost commented Mar 26, 2018

The following example shows that implicit functions and tail recursion do not seem to get along very well

$ dotr
Starting dotty REPL...
scala> @annotation.tailrec def foo(i: Int): Int = if (i == 0) { 0 } else { foo(i - 1) } // ok  
def foo(i: Int): Int
scala> @annotation.tailrec def bar(i: implicit Unit => Int): implicit Unit => Int = if (i == 0) { 0 } else { bar(i - 1) } // ko 
1 |@annotation.tailrec def bar(i: implicit Unit => Int): implicit Unit => Int = if (i == 0) { 0 } else { bar(i - 1) } // ko
  |                        ^
  |            TailRec optimisation not applicable, method not tail recursive
scala>
smarter added a commit to dotty-staging/dotty that referenced this issue Mar 26, 2018
…types

Before `ShortcutImplicits`, calls to such methods are never in tail
position since we call `.apply` on them to pass the implicit arguments.
By moving `ShortcutImplicits` before `TailRec` we avoid this problem.
smarter added a commit to dotty-staging/dotty that referenced this issue Mar 26, 2018
…types

Before `ShortcutImplicits`, calls to such methods are never in tail
position since we call `.apply` on them to pass the implicit arguments.
By moving `ShortcutImplicits` before `TailRec` we avoid this problem.
smarter added a commit that referenced this issue Mar 29, 2018
Fix #4196: TailRec-optimize methods returning implicit function types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant