From d7fabf2e890ee21abaaab2bf2396f3f12c57a58d Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 8 Aug 2019 06:35:23 -0700 Subject: 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. --- share/txr/stdlib/compiler.tl | 11 ++++++++--- 1 file 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) -- cgit v1.2.3