[gclist] tail recursion requires gc

Richard A. O'Keefe ok@cs.rmit.edu.au
Thu, 8 Aug 1996 13:28:28 +1000 (EST)


	Tail recursion is therefore very tightly coupled to garbage
	collection.  General tail recursion optimization _requires_
	garbage collection.

	So don't expect gcc or any other C compiler to provide fully
	general tail recursion any time soon.  That won't happen
	until gc becomes a de facto standard part of C.

This and the supporting argument that I have deleted sounds impressive
until you realise that "fully general tail recursion" has been covertly
redefined as "those tail calls that require garbage collection".

What is of interest to people compiling languages like Scheme and Mercury
to C is that at least one existing commercial C compiler in daily use
does turn any tail call to a prototyped function not passing the address
of a local variable into code that reclaims the current stack frame (or
never allocates a frame in the first place).  Since Scheme and Mercury
to C compilers are already taking care of heap allocation, and already
generate fully prototyped code, none of the necessary restrictions on C
tail calls that have been identified so far limit such compilers in the
slightest.

Tail call improvement pays off most when you have lots of little functions;
I suspect we have C++ to thank for the improvement in the SPARCompiler C
compiler's back end (which is shared with SPARCompiler C++).