DIP: Tail call optimization

Dietrich Daroch via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Sun Jul 10 10:32:32 PDT 2016


On Sunday, 10 July 2016 at 17:16:10 UTC, Ola Fosheim Grøstad 
wrote:
> On Sunday, 10 July 2016 at 17:10:32 UTC, Dietrich Daroch wrote:
>> Annotating every callsite seems uncomfortable, being able to 
>> perform TCO is a property of the function and not something 
>> that might look call-site dependant.
>
> You only need to annotate the location where the function calls 
> itself. The function might want some recursive calls to work 
> without tail recursion restrictions and at the same time use 
> tail recursion at the end.
>
> Or do you mean that this should prevent all kinds of recursion? 
> That is a quite demanding analysis. For instance, the function 
> could get itself passed in as a parameter...

My bad, I misunderstood your point. Annotating recursive calls 
seems more flexible.
Now the question is how should they be annotated? pragma is 
verbose, but avoids adding keywords.


I think a constant stack size annotation would still make sense, 
but might not promise that stack overflows are not possible if a 
lot of local data is used and a big, but constant numbers of 
calls are made.
It might be interesting to have proof that the stack is bounded 
(and won't overflow).


More information about the Digitalmars-d-announce mailing list