summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-08-08 06:35:23 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-08-08 06:35:23 -0700
commit70583ddaae6fa39f2ab69b974d3a6f99c3d40a00 (patch)
treec80c7940f597d1425737b4486af3e57e671b8a2a
parentd45b3f4989157587b7a0e71833784610a8dc19c5 (diff)
downloadtxr-70583ddaae6fa39f2ab69b974d3a6f99c3d40a00.tar.gz
txr-70583ddaae6fa39f2ab69b974d3a6f99c3d40a00.tar.bz2
txr-70583ddaae6fa39f2ab69b974d3a6f99c3d40a00.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.tl11
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)