1.0.48.25: automatic &rest to &more conversion
lp#504575
Automatically convert
(values-list rest-arg)
to
(%more-arg-values more-context 0 more-count)
when possible, making functions such as
(defun foo (f1 f2 &rest args)
(apply f1 args)
(apply f2 args))
non-consing.
The conversion is done iff:
* The rest arg is never assigned to.
* The rest arg only appears in VALUES-LIST (incl. APPLY)
calls.
* Those calls are all in either the same lambda that
allocates the rest-list, or one that has been declared
dynamic extent. (Conservative guess re. escaping.)
The way this works is as follows:
1. When we convert a lambda with a non-ignored &rest argument, as add
more-context and more-count arguments to the function, and
stick their lambda-vars into arg-info-default of the &rest arg.
2. When we source-transform a values-list form, we check if its argument is
a &rest argument for which context and count are available. If so, we
source-transform into
(%values-list-or-context list context count)
3. When we are optimizing, a deftransform fires for the form above. It
checks if all the necessary conditions hold and converts into either
%more-arg-values or values-list.
The reason for this roundabout way of doing things lies in locall analysis:
unless the extra context and count argument are used nontrivially when it
runs, they get deleted -- and we don't know if we want them or not until the
entire function has been converted. Absent a convenient pass between
conversion and locall analysis, we must therefore do things in two stages.
13 files changed: