Possibly Pythonic Tail Call Optimization (TCO/TRE)

Gregory Ewing greg.ewing at canterbury.ac.nz
Wed Jul 15 18:34:43 EDT 2015


Chris Angelico wrote:
> Which really says that TCO is impossible if you have any sort of
> clean-up or deallocation to be done after the call begins. The only
> way to truly turn your tail call into a GOTO is to do all your cleanup
> first.

Indeed. In compilers that implement TCO, there's quite
a lot more to it than just "replace CALL with JMP". It
requires rethinking your whole strategy on when to put
various things on the stack and take them off again,
so that by the time you get to the point of the tail
call, there is nothing on the stack other than the
arguments to the tail call and the ultimate return
address.

-- 
Greg



More information about the Python-list mailing list