[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
I think it would be possible to define a limited set of cases
in which GCC could handle tail recursion. For example, suppose there is
a way to declare a function type as tail-recursive. Then it would be
called with a different calling sequence. All callers would need to
have a declaration saying that the function being called is
tail-recursive, so they could use the special calling sequence. This
calling sequence would be designed to make tail recursion
straightforward to implement.
Does this basically amount to saying that there would be special calling
sequence that Lisp could use? If so, that sounds desirable, though I'm not
sure that tail-recursion is the biggest problem with efficiently
implementing Common Lisp function call in C. I'm not enough of a C
programmer to know where all the problems are, but I would imagine that
things like multiple return values could cause problems.
Single-value return is most common, so you don't want to penalize it in
order to support multiple return. But it is also undesirable to require
that the compiler statically know which functions might return undesired
additional values. In our current implementation, each function return
point actually has two entries, one for when there is exactly one value
returned, and one for other numbers of values.
Would you also want tail recursive calls to be annotated as such? That
would be easy to do.
Another major problem with compilation to C is garbage collection. Without
a lot of compiler hooks, you are pretty much forced to use a conservative
garbage collector. I am somewhat worried that conservative GC would cause
serious storage leaks in a complex Lisp environment like CMU CL.