-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add compiler-known attribute for enforced tail recursion #721
Comments
See also:
@haf If you're interested, I think it would be productive to flesh out the existing RFC a bit more. There were some open design questions that the trial implementation produced that you might also want to consider. Also tagging as |
It would be great if this could be tweaked to be able to be forced at the assembly level (e.g. via compiler flag), not only at method level via attribute. |
Usually I want functions that are totally tail recursive, but sometimes in some branch I accept a non-tail recursive call because I know that the particular branch will only be called one or a few times. Using an attribute on the function level won't cover this case. |
Would/should this be extensible to cover Adyncseq and Taskseq ? |
Was wondering that now that we have the |
Yeah, I think so. Any additional requests should come via separate issues, thanks. |
For future readers, here's the current RFC location: https://github.com/fsharp/fslang-design/blob/main/FSharp-8.0/FS-1011-warn-on-recursive-without-tail-call.md And the accepted implementation: dotnet/fsharp#15503 |
Enforce tail-recursion with attribute
I propose we add a new attribute
[<TailRecursive>]
, applicable to functions that:use _ = ...
statements above the supposed-to-be recursive call.The existing way of approaching this problem in F# is to think hard about the problem every time, and when that fails, we get this stuff: Hopac/Hopac#193
Pros and Cons
The advantages of making this adjustment to F# are correctness, speed, saving memory/stack space. Also, this issue mostly only crops up under load, after chewing through a few gigabytes of memory, so it's hard to spot during development and the crashes from OOM are not always the most clear crashes. Furthermore, in prod, a fix would be to read the code well and then "fix" it in the obvious way, and then redeploy, hoping that 4 hours later, there's no crash.
The disadvantages of making this adjustment to F# are: another attribute, more compiler complexity and the trampoline may be advanced enough to warrant splitting out to another feature. Furthermore, the compiler could in the initial implementation require such functions to be private (to be able to reason about all calls to them being "full" and not curried).
Extra information
Example from Logary, that I would like to have the compiler prove for me:
Estimated cost (XS, S, M, L, XL, XXL): S-M
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: