Subject: bug#29520: peval leaves behind dangling lexical reference

From: Mark H Weaver <[email-masked]>
Date: Mon, 04 Dec 2017 00:41:01 -0500

Mark H Weaver <[email-masked]> writes:

> I believe the problem is most likely in 'lift-applied-lambda' in
> peval.scm.  When transforming:
>
>   (lambda args (apply (lambda ...) args)) => (lambda ...)
>
> it does not appear to check whether 'args' is referenced within the
> inner lambda.

Here's a proposed patch, which seems to fix compilation of the code
Stefan provided.

      Mark

diff --git a/module/language/tree-il/peval.scm b/module/language/tree-il/peval.scm
index 993fa0ad6..9f6c26520 100644
--- a/module/language/tree-il/peval.scm
+++ b/module/language/tree-il/peval.scm
@@ -1589,6 +1589,9 @@ top-level bindings from ENV and return the resulting expression."
                      ($ <lexical-ref> _ _ sym)
                      ...))
                  (and (equal? sym gensyms)
+                      (every (lambda (s)
+                               (= (lexical-refcount s) 1))
+                             sym)
                       (not (lambda-case-alternate lcase))
                       lcase))
                 (_ #f))))