I don't understand what you mean by "reuse": if a fn makes multiple non-tail calls it reuses a region of stack for each; and if it finishes with a tail call, it reuses the place its own inbound args went. What am I missing?
-
-
-
The problem is if you tail call a function that takes more argument space than you do.
-
(What you describe is called "sibling call optimization", and it's a special case of TCO. GCC and LLVM will do sibling call optimization since it works with the C calling convention.)
End of conversation
New conversation -
-
-
There are definitely multiple calling conventions possible for tail calls. Rabbit did it differently than almost all compilers today, for example.
-
Yes, and if you think of "guaranteed tail call optimization" as a degenerate case of code from a compiler that CPS transforms before final gen, there's a family of calling conventions even within a single compiler (self recursive, known target, unknown, FV(f)=0 vs. >0, etc.).
End of conversation
New conversation -
-
-
And having to memorize the patterns. Give me growable stacks and I love you. Give me tail calls and maybe I'll think about it sometimes.
-
What's "the patterns"? return f(x) is a tail call, other stuff not so much.
-
But then I have to avoid using other kinds of recursion. Growable stacks don't have that problem.
-
I'm not knocking growable stacks! Neither pointless low limits on resources nor holding onto resources that are no longer needed are things we should accept from our systems.
-
I'm saying that from a programming model perspective, growable stacks let me stop thinking about recursion limits as fundamental, while PTC or TCO lets me try to optimize a subset of recursion cases. The former is a more fundamental improvement to my QOL.
-
I agree that if you have arbitrary depth stacks, then proper tail calls cause your program to work (vs crash) in many fewer cases. But I think that "allow the programmer to avoid using too many resources" is fundamental as well.
-
Which works as long as you spend the time to structure your recursive program to use tail calls for recursion.
-
No the point is that you *can* avoid holding onto unnecessary resources. Without proper tail calls, some programs have memory leaks that you can't fix.
- 1 more reply
New conversation -
-
-
Is this something that could be monomorphized? Or is the issue more to do with the complexity of having multiple calling conventions?
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.