From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.bugs Subject: bug#29520: peval leaves behind dangling lexical reference Date: Sun, 03 Dec 2017 19:43:45 -0500 Message-ID: <87mv2zxqym.fsf@netris.org> References: <87shcrxyat.fsf@netris.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1512348313 28433 195.159.176.226 (4 Dec 2017 00:45:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 4 Dec 2017 00:45:13 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) Cc: 29520@debbugs.gnu.org To: Stefan Israelsson Tampe Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Mon Dec 04 01:45:08 2017 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eLesb-0006xk-N2 for guile-bugs@m.gmane.org; Mon, 04 Dec 2017 01:45:05 +0100 Original-Received: from localhost ([::1]:40676 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eLesi-0001qy-Ud for guile-bugs@m.gmane.org; Sun, 03 Dec 2017 19:45:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eLesd-0001qj-Hm for bug-guile@gnu.org; Sun, 03 Dec 2017 19:45:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eLesY-0004Oh-KN for bug-guile@gnu.org; Sun, 03 Dec 2017 19:45:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:35341) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eLesY-0004Oa-GB for bug-guile@gnu.org; Sun, 03 Dec 2017 19:45:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eLesY-0008KD-9l for bug-guile@gnu.org; Sun, 03 Dec 2017 19:45:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Mark H Weaver Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Mon, 04 Dec 2017 00:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 29520 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 29520-submit@debbugs.gnu.org id=B29520.151234825331930 (code B ref 29520); Mon, 04 Dec 2017 00:45:02 +0000 Original-Received: (at 29520) by debbugs.gnu.org; 4 Dec 2017 00:44:13 +0000 Original-Received: from localhost ([127.0.0.1]:44022 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eLerl-0008Iw-29 for submit@debbugs.gnu.org; Sun, 03 Dec 2017 19:44:13 -0500 Original-Received: from world.peace.net ([50.252.239.5]:60278) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eLerh-0008Ih-M6 for 29520@debbugs.gnu.org; Sun, 03 Dec 2017 19:44:10 -0500 Original-Received: from pool-72-93-29-217.bstnma.east.verizon.net ([72.93.29.217] helo=jojen) by world.peace.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1eLerb-0007zg-GP; Sun, 03 Dec 2017 19:44:03 -0500 In-Reply-To: <87shcrxyat.fsf@netris.org> (Mark H. Weaver's message of "Sun, 03 Dec 2017 17:05:14 -0500") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.org gmane.lisp.guile.bugs:8924 Archived-At: Mark H Weaver 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