[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: common-lisp@SAIL.STANFORD.EDU
- Subject: Constant Functions
- From: ELIOT@cs.umass.edu
- Date: Wed, 4 May 88 10:35 EDT
"Defconstant ... does licence the compiler to buildassumptions about
the value into programs being compiled."
This mechanism has been in place for some time, and I imagine most
people agree that it is useful. I don't know of any equivalent
mechanism for declaring that the definition of a function will not
change. A good compiler could make use of this knowledge to do
some useful optimizations. For example, knowing that the definition
of SIN won't change, and looking to see that SIN is defined as a
mathematical function (this might be hard) implies that (sin pi) can
be compiled into a number. Similarly, the compiler could freely
eliminate code to check argument counts and types if the call is
correct at compile time, and the callee is guaranteed (by declaration)
not to change.
As a specific proposal I would add a weak version of the INLINE declaration.
INLINE already effectively gives the compiler a licence to assume that
a function definition will not change. However, it also gives the
compiler a licence to compile "bloated" code.
My proposal is to add to CLtL P.159 a new declaration for CONSTANT-FUNCTION.
The declaration (CONSTANT-FUNCTION foo) specifies that the compiler
may assume that the semantics of FOO are fixed. The actual effect
depends upon the definition of FOO, the call, and any DECLARE (OPTIMIZE ..)
that are in effect. With SPACE=0, SPEED=3 this should be equivalent to
an INLINE declaration.
As a special case (declare constant-function) in a DEFUN is equivalent
to both a proclaim and the defun.
In any case, an implementation is free to completely ignore this
Student, Umass Amherst.