unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Stefan Israelsson Tampe <stefan.itampe@gmail.com>
Cc: 29520@debbugs.gnu.org
Subject: bug#29520: peval leaves behind dangling lexical reference
Date: Mon, 04 Dec 2017 21:55:21 -0500	[thread overview]
Message-ID: <878tehvq7a.fsf@netris.org> (raw)
In-Reply-To: <87wp22w66v.fsf@netris.org> (Mark H. Weaver's message of "Mon, 04 Dec 2017 16:10:00 -0500")

Mark H Weaver <mhw@netris.org> writes:

> It occurs to me that there's another problem with this optimization:
>
>   scheme@(guile-user)> ,optimize (lambda (x y . z) (apply (lambda x x) x y z))
>   $1 = (lambda x x)
>
> This optimization changes the arity of the procedure.  The original
> version checks that at least 2 arguments are provided, and ensures that
> at least 2 arguments are passed to the inner procedure, which the code
> might depend on.  The optimization effectively removes this check.

Here's an updated patch that fixes both issues.

      Mark


diff --git a/module/language/tree-il/peval.scm b/module/language/tree-il/peval.scm
index 993fa0ad6..13b7d9bc4 100644
--- a/module/language/tree-il/peval.scm
+++ b/module/language/tree-il/peval.scm
@@ -1585,11 +1585,15 @@ top-level bindings from ENV and return the resulting expression."
          (and (not opt) rest (not kw)
               (match body
                 (($ <primcall> _ 'apply
-                    (($ <lambda> _ _ (and lcase ($ <lambda-case>)))
+                    (($ <lambda> _ _ (and lcase ($ <lambda-case> _ req1)))
                      ($ <lexical-ref> _ _ sym)
                      ...))
                  (and (equal? sym gensyms)
                       (not (lambda-case-alternate lcase))
+                      (<= (length req) (length req1))
+                      (every (lambda (s)
+                               (= (lexical-refcount s) 1))
+                             sym)
                       lcase))
                 (_ #f))))
        (let* ((vars (map lookup-var gensyms))





  reply	other threads:[~2017-12-05  2:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-01 12:08 bug#29520: Compilation error Stefan Israelsson Tampe
2017-12-03 22:05 ` bug#29520: peval leaves behind dangling lexical reference Mark H Weaver
2017-12-04  0:43   ` Mark H Weaver
2017-12-04  5:41     ` Mark H Weaver
2017-12-04 21:10       ` Mark H Weaver
2017-12-05  2:55         ` Mark H Weaver [this message]
2018-03-16  3:41           ` Mark H Weaver

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878tehvq7a.fsf@netris.org \
    --to=mhw@netris.org \
    --cc=29520@debbugs.gnu.org \
    --cc=stefan.itampe@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).