[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: Jon L White <firstname.lastname@example.org>
- Subject: SIDE-EFFECT-FREE/STATELESS Functions
- From: David A. Moon <Moon@STONY-BROOK.SCRC.Symbolics.COM>
- Date: Fri, 13 May 88 12:30 EDT
- Cc: common-lisp@SAIL.STANFORD.EDU
- In-reply-to: <8805130856.AA25592@bhopal.lucid.com>
Here is the declaration that Symbolics currently uses (and has used for
some years) to provide this information to the compiler. We keep it
rather simple and do not try to break down side-effects into disjoint
categories; in other words, we assume that any location can be aliased
with any other location. This message does not constitute any kind of
commitment not to change the way this is done in the future.
The LT:SIDE-EFFECTS and LT:REPLICABILITY declarations license the
compiler to assume that the current definition and all future
redefinitions of the declared function will have the declared
properties. The reason these declarations exist is solely for that
constraint on future redefinitions, since this is information that the
compiler could easily deduce for itself by analyzing the function body.
These declarations are placed in the body of a function and
declare properties of the function being defined; these properties are
available in all scopes where the name of the function is lexically
(DECLARE LT:(SIDE-EFFECTS SIMPLE)) means the function neither causes nor
is affected by side-effects. There aren't many examples of this (usually
one uses SIMPLE REDUCIBLE, see below); in Symbolics Common Lisp, CHAR-CODE
is an example, because the only side-effect that affects its value is
rebooting the machine (codes are assigned dynamically but once assigned
do not change for the duration of a session).
(DECLARE LT:(SIDE-EFFECTS READER)) means the function is affected by
side-effects but does not cause them. CONS is an example (allocation of
storage is not considered a side-effect because it doesn't affect the
result of any other function other than performance metering functions.)
(DECLARE LT:(SIDE-EFFECTS WRITER)) means the function may cause
side-effects and may be affected by them. This is the default.
(DECLARE LT:(SIDE-EFFECTS REDUCIBLE)) means the function is affected by
side-effects but does not cause them, and furthermore that the function
is subject to constant-folding. CAR is an example.
(DECLARE LT:(SIDE-EFFECTS SIMPLE REDUCIBLE)) means the function neither
causes nor is affected by side-effects, and furthermore that the
function is subject to constant-folding. + is an example.
LT:REPLICABILITY is much more implementation dependent but I'll
mention it here for completeness.
(DECLARE LT:(REPLICABILITY MANY-TIMES)) means it's worth computing
the function any number of times rather than binding a variable to it.
(DECLARE LT:(REPLICABILITY TWO-TIMES)) means it's worth computing
the function twice rather than binding a variable to it, but if a
common sub-expression calling this function occurs more than twice,
it should be bound to a variable.