[Python-Dev] Re: Proper tail recursion

Chris King colanderman at gmail.com
Fri Jul 16 15:23:15 CEST 2004

On Fri, 16 Jul 2004 00:52:07 -0700, Josiah Carlson <jcarlson at uci.edu> wrote:

> If unlimited recursion were allowed, perhaps limited tracebacks (first
> and last 500 stack frame traces), RLE tracebacks (though a clever
> programmer could easily destroy the generator with fewer than 64
> functions, but we probably shouldn't do that), or combined limited and
> RLE tracebacks would be sufficient. What do I mean by an RLE traceback?

I thought of doing RLE tracebacks, but compression fails in the case
of cooperative recursive calls.  I think perhaps along with the
sys.setrecursionlimit(None) option you suggest, developers should be
allowed to turn recursive tracebacks off entirely in the case of
cooperative recursive calls.

The other problem with RLE tracebacks is that a traceback object also
keeps a reference to each function's locals (by virtue of keeping a
reference to its frame obejct).  Throwing this info out makes RLE
tracebacks no more useful to debuggers than having no traceback at

Keeping the first and last X frames in a traceback seems reasonable,
but this would similarly cripple debuggers (what happens if the bug is
in the (X+1)th frame?).  Implementation would also be complicated.

IMHO it should be an all-or-nothing deal: either the programmer turns
tail-call optimizations on to nullify memory uses, or turns them off
to facilitate debugging.

More information about the Python-Dev mailing list