[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

inline declaration for FLET and LABELS

    Date: Thu, 27 Mar 86 11:56:25 EST
    From: "Patrick G. Sobalvarro" <PGS@AI.AI.MIT.EDU>

	Date: Tue, 25 Mar 86 11:04 EST
	From: David C. Plummer <DCP at SCRC-QUABBIN.ARPA>

	A few of us just realized that
	    (defun foo ()
	      (labels ((bar ...)
		       (baz ...))
		(declare (inline bar baz))
	is realitively easy to implement compare to
	    (defun foo ()
	      (flet ((bar ...)
		     (baz ...))
		(declare (inline bar baz))
	The problem is the scoping rules.  Consider
	    (defun foo ()
	      (flet ((car (x) (cdr x))
		     (cdr (x) (car x)))
		(declare (inline car cdr))
	While this is quite legal, it may be VERY hard to implement.  Therefore,
	when we consider allowing inline declarations for local functions, we
	should keep this in mind in the documentation.

    I'm not sure I understand this -- do you have your flet and your labels
    backwards here?  In that case, I think that most compilers that couldn't do
    block compilation would just ignore inline declarations when they caused
    circularities.  Consider that the situation you're describing isn't too
    different from compiling globally defined mutually recursive functions that
    are declared inline.

The problem is that when you expand an FLET'ed or LABELS'ed function,
you have to 'fool' somebody by backing up the lexical environment
correctly.  Consider this contoration:
	(compiler-let ((*foo* 'foo))
	  (macrolet ((foo () `'(outer ,*foo*)))
	    (flet ((foo1 () (foo)))
	      (flet ((foo2 () (foo1)))
		(declare (inline foo2))
		(compiler-let ((*foo* 'bar))
		  (macrolet ((foo () `'(inner ,*foo*)))
		    (flet ((foo1 () (foo)))
This is supposed to return (OUTER FOO).  If the call to FOO2 were
expanded into FOO1 but the environment were not unrolled, it would
instead return (INNER BAR).  I'm not saying it is impossible; I'm saying
it is probably damn hard to implement.