[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: constant folding/smashing
Kent Pitman's 1.5 bit rule is correct as far as it goes, but doesn't supply
enough bits to cover the set of declarations of "constant"ness under
1) It says nothing about whether (portions of) the constant
can be COLLAPSED to EQness with (portions of) other constants. I am
starting to believe this may be a moot point, and that NOBODY really wants
to authorize an implementation to EQify values just because they have
been declared constant.
2) It does not address how much of READ-ONLY datum is read only. It seems
to imply that KMP does NOT like the distinction made currently between
lists and arrays. But it does not say whether, if a list is "read only"
constant, its component lists must be read-only as well.
Nor does it imply anything about other (non list or array) datatypes that
might appear QUOTEd. Just suppose I want to establish
a symbol with a couple special properties that I use as a constant --
#,(let ((s (gensym)))
(setf s 0
(get s 'indicator1) 0
(get s 'indicator2) 0)))
Suppose further that I do NOT intend to change the value cell of this
symbol, or change, add, or remove any of the properties of this constant
symbol -- just read them. Should I be able to declare any of this to the
lisp implementation, so it can produce better code or allocate structure
in read-only memory? Maybe so, but certainly not by differently named
variants of QUOTE. So the only reason I can see for inventing any
variant special forms, is that there are a very few variants (but more than 1)
that cover the overwhelming majority of uses. On the other hand,
a syntax along the lines of
QUOTE object &rest declarations
leaves room for extensibility.
A comment on Brad Miller's question:
It is still an open question, however, as to when the compiler is
allowed to take advantage of read-only objects and treat them as
inline. That is, given:
(defun foo () (constant '(a b c))
(defun mumble () (foo))
is the compiler allowed to collapse mumble into the equivalent of foo?
Seems like a red herring to me. Why would the fact that foo happens to
compute a CONSTANT result influence whether or not calls on it
are allowed to be INLINEd? I don't think anyone would want foo INLINEd if
it were not explicitly declared INLINE. I see nothing in CLtL that could
be construed to authorize doing so. This is NOT the issue of constant
folding discussed in earlier messages in this series -- they have to
do with the folding of SYMBOL values for symbols declared DEFCONSTANT.
(This folding is authorized by CLtL on P. 69)