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

Re: Local redefs of special forms



> From: Jeff Barnett <jbarnett@nrtc.northrop.com>
> Date: 12 Nov 87 05:21:47 GMT
> 
> If you allow FLETS, et al, to shadow special forms, there is an implementation
> issue with inline function expansions nee DEFSUBSTs.  The compiler cannot
> substitute the function body and optimize as some compilers now do.  In fact
> the body must be (re)expanded in the null lexical environment no matter what.
> Consider the following example:
> 
> (defsubst foo (x) (car x))
> 
> (flet((car (l) (cdr l)))
>   (foo (car q)))
> 
> The value of the flet should be (cadr q) while if the compiler is not careful,
> the result will be (cddr q) instead.   ...

Jeff,

But DEFSUBST is not part of Common Lisp, and I imagine that this is part
of the reason it isn't.  Furthermore, DEFSUBSTs and INLINE functions are
not the same thing.  Doing it the Common Lisp way:

  (proclaim '(inline foo))
  (defun foo (x) (car x))

the compiler is required to ensure that any inline expansion preserves
the semantics of the function call.  Rather than attempting to achieve
this as a source transformation, our compiler does the expansion during
compilation, after all local function and variable names have been
replaced by pointers to the appropriate symbol table entries.  Thus for
something that can be done by either a macro or inline function (a
DEFSUBST is considered to be a macro in this context), it is preferable
to use an inline function and let the compiler worry about getting the
environments right.  The problem remains for things that have to be
implemented as macros because they don't follow the syntax or semantics
of a function call.  

  -- David Gray