diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-08-08 06:35:23 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-08-08 06:35:23 -0700 |
commit | d7fabf2e890ee21abaaab2bf2396f3f12c57a58d (patch) | |
tree | c80c7940f597d1425737b4486af3e57e671b8a2a | |
parent | a9f907cda6eb2babe5fb5aa2107f7e65ea198872 (diff) | |
download | txr-d7fabf2e890ee21abaaab2bf2396f3f12c57a58d.tar.gz txr-d7fabf2e890ee21abaaab2bf2396f3f12c57a58d.tar.bz2 txr-d7fabf2e890ee21abaaab2bf2396f3f12c57a58d.zip |
compiler: inline-lambda: optimize generated let.
* share/txr/stdlib/compiler.tl (lambda-apply-transform): We
conditionally generate the outer let as an alet, if there are
no shadowing issues. The shadowing test is very conservative:
the intersection between the argument expressions and the
lambda symbols must be empty. Also, we move the gensym for
the apply list expression into the let*, because we need a
real storage location that we can pop.
-rw-r--r-- | share/txr/stdlib/compiler.tl | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/share/txr/stdlib/compiler.tl b/share/txr/stdlib/compiler.tl index 6de381cd..ba7ffb68 100644 --- a/share/txr/stdlib/compiler.tl +++ b/share/txr/stdlib/compiler.tl @@ -1502,10 +1502,15 @@ (let* ((pars (new (fun-param-parser lm-args lm-expr))) (fix-vals (mapcar (ret (gensym)) fix-arg-exprs)) (ign-sym (gensym)) - (al-val (gensym))) - ^(let (,*(zip fix-vals fix-arg-exprs) - ,*(if apply-list-expr ^((,al-val ,apply-list-expr)))) + (al-val (gensym)) + (shadow-p (let ((all-vars (append pars.req pars.(opt-syms) + (if pars.rest (list pars.rest))))) + (or (isec all-vars fix-arg-exprs) + (member apply-list-expr all-vars))))) + ^(,(if shadow-p 'let 'alet) ,(zip fix-vals fix-arg-exprs) (let* ,(build + (if apply-list-expr + (add ^(,al-val ,apply-list-expr))) (while (and fix-vals pars.req) (add ^(,(pop pars.req) ,(pop fix-vals)))) (while (and fix-vals pars.opt) |