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: Sun, 03 Dec 2017 19:43:45 -0500	[thread overview]
Message-ID: <87mv2zxqym.fsf@netris.org> (raw)
In-Reply-To: <87shcrxyat.fsf@netris.org> (Mark H. Weaver's message of "Sun, 03 Dec 2017 17:05:14 -0500")

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

> So, peval is optimizing this:
>
>   (define (f-scope f)
>     (define (g f x3)
>       (define (h x2 n m)
>         (lambda xx (apply (f-skip n m) x2)))
>       (lambda (a b cc d c)
>         (f x y z c)
>         (let ((n N) (m M)) ((h x3 n m) x y z c2))))
>     (lambda x (apply (g f x) x)))
>
> into this:
>
>   (define (f-scope f)
>     (lambda (a b cc d c)
>       (f x y z c)
>       (let ((n N) (m M))
>         (begin x y z c2 (if #f #f))
>         (apply (f-skip n m) x-1))))

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.

Assuming for the moment that it fails to do this check, here's an
example sequence of transformations that could lead to this situation:

Starting with:

  (define (f-scope f)
    (define (g f x3)
      (define (h x2 n m)
        (lambda xx (apply (f-skip n m) x2)))
      (lambda (a b cc d c)
        (f x y z c)
        (let ((n N) (m M))
          ((h x3 n m) x y z c2))))
    (lambda x (apply (g f x) x)))

inline the call to h:

  (define (f-scope f)
    (define (g f x3)
      (lambda (a b cc d c)
        (f x y z c)
        (let ((n N) (m M))
          ((lambda xx (apply (f-skip n m) x3))
           x y z c2))))
    (lambda x (apply (g f x) x)))

inline the call to (lambda xx ...):

  (define (f-scope f)
    (define (g f x3)
      (lambda (a b cc d c)
        (f x y z c)
        (let ((n N) (m M))
          (begin x y z c2 (if #f #f))
          (apply (f-skip n m) x3))))
    (lambda x (apply (g f x) x)))

alpha-rename the 'x' to 'x-1' in the final lambda above:

  (define (f-scope f)
    (define (g f x3)
      (lambda (a b cc d c)
        (f x y z c)
        (let ((n N) (m M))
          (begin x y z c2 (if #f #f))
          (apply (f-skip n m) x3))))
    (lambda x-1 (apply (g f x-1) x-1)))

inline the call to g:

  (define (f-scope f)
    (lambda x-1
      (apply (lambda (a b cc d c)
               (f x y z c)
               (let ((n N) (m M))
                 (begin x y z c2 (if #f #f))
                 (apply (f-skip n m) x-1)))
             x-1)))

if we erroneously replace (lambda x-1 (apply FOO x-1)) with FOO here
(even though FOO contains a reference to x-1) then we would get:

  (define (f-scope f)
    (lambda (a b cc d c)
      (f x y z c)
      (let ((n N) (m M))
        (begin x y z c2 (if #f #f))
        (apply (f-skip n m) x-1))))

which is what 'peval' returns, although I don't know if these were the
exact steps taken.

      Mark





  reply	other threads:[~2017-12-04  0:43 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 [this message]
2017-12-04  5:41     ` Mark H Weaver
2017-12-04 21:10       ` Mark H Weaver
2017-12-05  2:55         ` Mark H Weaver
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=87mv2zxqym.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).