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

Constant Functions

I believe the point of a CONSTANT-FUNCTION declaration would be to allow
references to the function cell of a symbol to be replaced with its
compile-time contents (or moral equivalent thereof).  I.e. to tell the
compiler that it can replace (FOO ...) with (FUNCALL '#<Function FOO> ...).

This is very different from declaring, say, that FOO returns a float. That
certainly doesn't give the compiler license to assume that I will never
redefine FOO, just that any definition I ever give it will be a

Regarding inlining, I think it is perfectly valid for a compiler to inline
explicit constant references to compiled functions (i.e. references of the
form '#<Function>) since there is nothing in common lisp that would allow you
to tell the difference.  Allowing CONSTANT-FUNCTION's to get inlined under some
SPEED/SPACE settings would just be a special case of that.

Having said all that, I don't think a CONSTANT-FUNCTION declaration would be
very useful.  Unlike variables, most functions in most programs are constant
(once debugging is done), and you don't really want to maintain huge sets of
CONSTANT-FUNCTION declarations all over the place (that you have to keep
turning off when you need to debug).  I think it would be more useful to have
some syntax for requesting block compilation of a file or a set of files
(presumably with some argument to compile-file), and a way to declare
exceptions (for which purpose NOTINLINE declarations seem to be the defacto
standard).  I don't really see any need here for language extensions, since
requesting block compilation is sort of an environmental issue that I don't
think needs to be standardized; and for the exceptions, NOTINLINE will do fine
since any implementation that 'snaps links' on functions declared NOTINLINE
is asking to lose anyway given current usage.