develooper Front page | perl.perl5.porters | Postings from January 2008

Re: For 5.12: tail calls for methods

Thread Previous | Thread Next
From:
Jim Cromie
Date:
January 22, 2008 12:59
Subject:
Re: For 5.12: tail calls for methods
Message ID:
4796580F.1030501@gmail.com
Stevan Little wrote:
>
> On Jan 18, 2008, at 6:53 AM, Dave Mitchell wrote:
>
>> On Thu, Jan 17, 2008 at 01:46:50PM -0500, Stevan Little wrote:
>>>> And how do you want to detect that?
>>>
>>> Simple, if the last call is to the same function, then it 
>>> tail-recurses.
>>
>> That implies adding an extra test into every sub call, which we try to
>> make as fast as possible.
>
> Actually I would suspect this is something that can be flagged during 
> the compilation of the sub. Of course I know little about perl-guts so 
> I may be totally off here, but it seems to me that is /should/ be 
> possible anyway.
>
> - Stevan
>

ISTM that a tail-call opportunity is self-evident in ops 7,8

$ perl -MO=Concise,-exec,b -e 'sub a{'A'} sub b{a()}; print b'
main::b:
4  <;> nextstate(main 2 -e:1) v
5  <0> pushmark s
6  <#> gv[*a] s
7  <1> entersub[t2] KS/TARG,1
8  <1> leavesub[1 ref] K/REFC,1


IIUC,  CUSTOM_OPS work originally envisioned finding OP-pairs which 
occur with hi-frequency
and mashing the 2 PP-bodies together, removing some of the boiler-plate 
in the process. 
This pair; entersub,leavesub looks like a good candidate for a tail-call 
custom op.

If this OP can be sanely defined (and thats not obvious), finding and 
replacing the
enter-leave pairs looks practical to add to Perl_peep.  (modulo usual 
caveats)
Its worth noting that optimizer / B-Generate could also "pimp-my-optree" 
in this way,
once the PP_TAILCALL is written.



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About