primarly optimizes LETs and pseudo LETs (CALLs with LAMBDAs as their
operators). This is a restricted form of static beta-substitution.
-1. It eliminates unused bound variables and substitutes bound
-variables by their values if the expressions for the values are
-sufficiently simple. Currently only the following value expressions
-can be substituted:
+1. It substitutes bound variables by their values if the expressions for
+the values are sufficiently simple. Currently only the following value
+expressions can be substituted:
a) LOOKUP forms.
b) QUOTE forms.
c) CALLs to a simple magic cookie procedure (currently
- %VECTOR-INDEX, %STACK-CLOSURE-REF and %HEAP-CLOSURE-REF) in
- which all of the operands trivial (QUOTE or LOOKUP forms, or
- calls to trivial operators (%VECTOR-INDEX) with quoted operands)
- and there is at most one LOOKUP argument.
+ %STACK-CLOSURE-REF and %HEAP-CLOSURE-REF). The essential
+ property of such expressions is that they are side-effect
+ insensitive and too cheap to pre-compute and bind to a
+ name. (%HEAP-CLOSURE-REF is side-effect insensitive because
+ %HEAP-CLOSURE-SET! is used only in limited ways to construct
+ mutually referring closures).
+
The substitution is, of course, careful to avoid name capture.
2. CALL to a LAMBDA is not quite identical to a LET, because there is
3. There is special handling for calls to explicit heap closures (i.e.
expressions of the form
(CALL %INTERNAL-APPLY ...
- (CALL %MAKE-HEAP-CLOSURE ... (LAMBDA (...) body))
+ (CALL %MAKE-HEAP-CLOSURE '#F (LAMBDA (...) body) ...)
...)
This can be converted to the simpler form
- (CALL (LAMBDA (...') body'))
-if the body has no self-references.
+ (CALL (LAMBDA (...) body') ...)
+provided the body has no self-references.
4. There is special handling for calls to explicit trivial closures,
similar to that for explicit heap closures. This, too, replaces the
closure with a LAMBDA expression.
+5. Known operators with sufficiently constrained argument expressions
+are replaced by `simpler' expressions. Most generic arithmetic
+operations are constant-folded. Some are re-written, for example
+ (fix:+ (fix:+ 1 x) 2)
+is rewritten to (fix:+ x 3) in two steps.
+
Operators Introduced:
---------------------
none
Special forms introduced:
-------------------------
- none
+none
Magic Cookies handled specially:
--------------------------------
%HEAP-CLOSURE-REF for optimization 3 and as part of the restriction on
optimization 1.
-%VECTOR-INDEX and %STACK-CLOSURE-REF as part of the restriction on
- optimization 1.
+%STACK-CLOSURE-REF as part of the restriction on optimization 1.
%INTERNAL-APPLY for optimizations 3 and 4.
%MAKE-HEAP-CLOSURE for optimization 3.
%MAKE-TRIVIAL-CLOSURE for optimization 4.
Guarantees on Output:
---------------------
- No unused bindings.
+1. No empty binding forms like (LET () e)
+2. No `chained' bindings of the form (LET ((x y)) ...)
+
+[Original guarantee: `No unused bindings' is not true.]