[Openmcl-devel] destructuring-bind breaks tail-recursion optimization

Ron Garret ron at flownet.com
Tue Feb 9 19:29:11 UTC 2010


On Feb 9, 2010, at 2:12 AM, Gary Byers wrote:

> In general, DYNAMIC-EXTENT on a variable binding means that the lifetime
> of the initial value of the variable is no greater than the scope of the
> variable.  In some cases, the lifetime of the value could be made shorter
> than that; in the expansion of DESTRUCTURING-BIND, the stack-consed
> object can't be referenced after the lambda list has been processed and
> isn't aliased in any way, so it -could- be popped off the stack earlier
> (and the function call in the body would then be tail-recursive.)  Without
> doing this kind of analysis, the compiler has to assume that the called
> function -could- somehow reference the stack-allocated object, and can't
> safely deallocate the object until that function returns.

Ah.

> (This kind of tradeoff involves the "howling factor" : would
>   people be more likely to howl if DESTRUCTURING-BIND consed unnecessarily
>   or if it did stack allocation that interfered with tail-recursion
>   optimization ?)

AAAOOOOOOOOOOOOOOOOO!!!!

;-)

How about...

(defvar *dbind-tail-call-optimization* nil)  ; NOTE: setting this to T will make destructure-bind cons

(defun %destructure-lambda-list ...
...
	(if *dbind-tail-call-optimization* (push `(dynamic-extent ,argptr) decls))
...


or something like that?

rg




More information about the Openmcl-devel mailing list