demerphq <
deme...@gmail.com> wrote:
> Basically if a subroutine qualifies as "tail recursive" we can check
> to see if the __SUB__ points at the same function as the function
> calls resolves to.
>
> If they are the same we can avoid the stack manipulation and replace
> the sub call by @_ munging and goto.
Is there a way of doing that without breaking user expectations for caller()?
My suspicion is that Perl shouldn't apply any form of call-frame
merging without seeing an explicit indication (whether a pragma, or
use feature feature, or simply an additional/alternative return
builtin) that the programmer is happy for call frames to disappear
from what caller() sees.
However, given such an explicit indication, it seems to me that
comparing the resolved call target to __SUB__ would be an unnecessary
restriction on the scope of the optimisation — why not also permit
call-frame merging for a tail call to a different routine? For that
matter, __SUB__ isn't entirely free, so it's conceivable that having
every tail-position invocation compare the target routine with __SUB__
might turn out to be a net pessimisation for some programs.
--
Aaron Crane **
http://aaroncrane.co.uk/