From debbugs-submit-bounces@debbugs.gnu.org Fri Dec 01 11:18:02 2017 Received: (at submit) by debbugs.gnu.org; 1 Dec 2017 16:18:02 +0000 Received: from localhost ([127.0.0.1]:40214 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eKo0n-0002Rr-On for submit@debbugs.gnu.org; Fri, 01 Dec 2017 11:18:01 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41680) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eKo0m-0002Rc-GR for submit@debbugs.gnu.org; Fri, 01 Dec 2017 11:18:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eKnyy-0007Qo-HW for submit@debbugs.gnu.org; Fri, 01 Dec 2017 11:17:53 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, DATE_IN_PAST_03_06, FREEMAIL_FROM, HTML_MESSAGE, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:45891) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eKnyy-0007QB-9T for submit@debbugs.gnu.org; Fri, 01 Dec 2017 11:16:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57217) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eKnxt-0001CH-Kf for bug-guile@gnu.org; Fri, 01 Dec 2017 11:16:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eKnwE-00025d-55 for bug-guile@gnu.org; Fri, 01 Dec 2017 11:15:01 -0500 Received: from mail-io0-x230.google.com ([2607:f8b0:4001:c06::230]:44671) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eKnwD-00022h-KN for bug-guile@gnu.org; Fri, 01 Dec 2017 11:13:17 -0500 Received: by mail-io0-x230.google.com with SMTP id w127so11733292iow.11 for ; Fri, 01 Dec 2017 08:13:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=tde+6Rqxa5aquqh1zHuTgFXoYktKtjdcNoBToWWnFpU=; b=MavN+WkgWP0KxRL6+aUwO9r8/g37GRk7F2N7zdBLJE/p9vcGPhvGj7pGjZUKIHv/fk NnU4c6vStTWbbtsA4upFWFeLmhr9gcdIKhzicOv8LG1N/JGO6teI5Gs5WAdga2vFEwW/ 5hiotIprtlCQJkCVoLJFJw+Pnl1v8rRtCioISv7FLjz9Xxpb2+10zyrolfVkLmNlahHR I6IpmcMFE9F/qk/lfUSe/xIrYcYJ3uJcZ993vbS1pTsqWvwKn/BDqvpMkRZoTAkrZPkb uzHheEhBdCHfWTZpTnsJqm2SnU8qfy2wibtIgGCK2iF9lpAGu/ssWj0oOR8aR3s6ydNN DMgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=tde+6Rqxa5aquqh1zHuTgFXoYktKtjdcNoBToWWnFpU=; b=n/7zb+IPnHP4bxRLU/H9+uu8z/bKmREbvsnKG+f0NNACP+D4JZK55DFiFy6E96Dc+g vg6P7mff8bUM4X7oTLk4gk/RvIVONuHMIcLYHaaL5O83yJSs9vkzAqsuqY9VCvrnHXNa 8enE3uEzJP3XmG9AcCJhFvAer0tLeHl8Q9t1EY9gvPu0CrPKtjcpPSSXyhFlyBbEvg/C IddBbuHT9yXkrPRKk80B5i14zPUnel7j3/FzfZ7fLRJx93pHrqNnie79KR7xAPXXah2D 9UgruKLALLXYxsp2KnEjHgpe3rCU/t7rJTs6KbgoXpGOrNJJ4cGCnar3Yv9QcfxgQZNd oTFg== X-Gm-Message-State: AJaThX4zXkr/BQA8wufDEKlxZkPzgSSJNBzdu0Eq0tXAg5CqN5wfFy3/ 3ynfP3PZ+vbBqeaDiq6Qn2lKymeaRwTe2/GPRtmdaA== X-Google-Smtp-Source: AGs4zMapMZkzmdGhmCNdcUPeXkwzcNEGdOfyNoxMXWSuYvNcSfgAkzrk9v6ySDlyYecnKeUw4p/gPsyWic4Jx0m7Tg0= X-Received: by 10.107.182.7 with SMTP id g7mr11812674iof.39.1512130126796; Fri, 01 Dec 2017 04:08:46 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.139.134 with HTTP; Fri, 1 Dec 2017 04:08:46 -0800 (PST) From: Stefan Israelsson Tampe Date: Fri, 1 Dec 2017 13:08:46 +0100 Message-ID: Subject: Compilation error. To: bug-guile@gnu.org Content-Type: multipart/alternative; boundary="001a114acb740fdb15055f463b3b" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -3.0 (---) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.0 (---) --001a114acb740fdb15055f463b3b Content-Type: text/plain; charset="UTF-8" Consider the code at the end of this post. un-commenting f-scope reveals the compiler error: ;;; ERROR: unbound lexical # But without it the globalified versoin f-scope2 comiles just fine indicating an error in the compiler. Regards Stefan (define-syntax-rule ( (c) code ...) (lambda (a b cc d c) code ...)) (define-syntax .. (syntax-rules () ((.. (f a ...)) (f x y z a ...)) ((.. (s ...) (f a ...)) (f x y z a ...)))) #; (define (f-scope f) (define (g f x3) (define (h x2 n m) (lambda xx (apply (f-skip n m) x2))) ( (c) (.. (c2) (f c)) (let ((n N) (m M)) (.. ((h x3 n m) c2))))) (lambda x (apply (g f x) x))) (define (h x2 n m) (lambda xx (apply (f-skip n m) x2))) (define (g f x3) ( (c) (.. (c2) (f c)) (let ((n N) (m M)) (.. ((h x3 n m) c2))))) (define (f-scope2 f) (lambda x (apply (g f x) x))) --001a114acb740fdb15055f463b3b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Consider the code at the end of this post. un-comment= ing f-scope reveals the compiler error:

= ;;; = ERROR: unbound lexical #<tree-il (lexical x #{x 190}#)>

But without it = the globalified versoin f-scope2 comiles just fine indicating an error in t= he compiler.

Regards
Stefan

=


(define-syntax-rule (<p-lambda> (c= ) code ...) (lambda (a b cc d c) code ...))
(define-syntax ..
=C2=A0 (syntax-rules ()
=C2=A0 =C2=A0 ((.. (f a ...)) (f x= y z a ...))
=C2=A0 =C2=A0 ((.. (s ...) (f a ...))
=C2= =A0 =C2=A0 =C2=A0(f x y z a ...))))
#;
(define (f-scope= f)
=C2=A0 (define (g f x3)
=C2=A0 =C2=A0 (define (h x2= n m)
=C2=A0 =C2=A0 =C2=A0 (lambda xx (apply (f-skip n m) x2)))
=C2=A0 =C2=A0 (<p-lambda> (c)
=C2=A0 =C2=A0 =C2=A0= (.. (c2) (f c))
=C2=A0 =C2=A0 =C2=A0 (let ((n N) (m M))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (.. ((h x3 n m) c2)))))

<= div>=C2=A0 (lambda x (apply (g f x) x)))

(define (= h x2 n m)
=C2=A0 (lambda xx (apply (f-skip n m) x2)))
<= br>
(define (g f x3)
=C2=A0 (<p-lambda> (c)
=
=C2=A0 =C2=A0 (.. (c2) (f c))
=C2=A0 =C2=A0 (let ((n N) (m M= ))
=C2=A0 =C2=A0 =C2=A0 (.. ((h x3 n m) c2)))))

(define (f-scope2 f)
=C2=A0 (lambda x (apply (g f x) x)))=

--001a114acb740fdb15055f463b3b-- From debbugs-submit-bounces@debbugs.gnu.org Sun Dec 03 17:05:44 2017 Received: (at 29520) by debbugs.gnu.org; 3 Dec 2017 22:05:44 +0000 Received: from localhost ([127.0.0.1]:43900 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eLcOO-0000o5-9q for submit@debbugs.gnu.org; Sun, 03 Dec 2017 17:05:44 -0500 Received: from world.peace.net ([50.252.239.5]:60062) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eLcOI-0000ng-W1; Sun, 03 Dec 2017 17:05:39 -0500 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 1eLcOC-0007RG-Ev; Sun, 03 Dec 2017 17:05:32 -0500 From: Mark H Weaver To: Stefan Israelsson Tampe Subject: Re: bug#29520: peval leaves behind dangling lexical reference References: Date: Sun, 03 Dec 2017 17:05:14 -0500 In-Reply-To: (Stefan Israelsson Tampe's message of "Fri, 1 Dec 2017 13:08:46 +0100") Message-ID: <87shcrxyat.fsf@netris.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 29520 Cc: 29520@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) retitle 29520 peval leaves behind dangling lexical reference thanks Stefan Israelsson Tampe writes: > Consider the code at the end of this post. un-commenting f-scope > reveals the compiler error: > > ;;; ERROR: unbound lexical # Indeed, I can confirm that 'peval' has a faulty optimization that leaves behind a dangling lexical reference to 'x' with no definition. Here's the relevant excerpt of Stefan's example code, indented: (define-syntax-rule ( (c) code ...) (lambda (a b cc d c) code .= ..)) (define-syntax .. (syntax-rules () ((.. (f a ...)) (f x y z a ...)) ((.. (s ...) (f a ...)) (f x y z a ...)))) =20=20 (define (f-scope f) (define (g f x3) (define (h x2 n m) (lambda xx (apply (f-skip n m) x2))) ( (c) (.. (c2) (f c)) (let ((n N) (m M)) (.. ((h x3 n m) c2))))) =20=20 (lambda x (apply (g f x) x))) When 'peval' optimizes 'f-scope', it inlines the calls to 'g' and 'h', but somewhere along the way the binding for 'x' gets lost, although a reference to 'x' still remains within the inlined instances of 'g' and 'h'. This error in the result of 'peval' is detected by 'verify-tree-il'. See below for a debugging transcript. --8<---------------cut here---------------start------------->8--- mhw@jojen ~$ guile GNU Guile 2.2.2 Copyright (C) 1995-2017 Free Software Foundation, Inc. Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'. This program is free software, and you are welcome to redistribute it under certain conditions; type `,show c' for details. Enter `,help' for help. scheme@(guile-user)> (define-syntax-rule ( (c) code ...) (lambda = (a b cc d c) code ...)) scheme@(guile-user)> (define-syntax .. (syntax-rules () ((.. (f a ...)) (f x y z a ...)) ((.. (s ...) (f a ...)) (f x y z a ...)))) scheme@(guile-user)> (define (f-scope f) (define (g f x3) (define (h x2 n m) (lambda xx (apply (f-skip n m) x2))) ( (c) (.. (c2) (f c)) (let ((n N) (m M)) (.. ((h x3 n m) c2))))) =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 (lambda x (apply (g f x) x))) ;;; :11:45: warning: possibly unbound variable `f-skip' ;;; :13:37: warning: possibly unbound variable `x' ;;; :13:37: warning: possibly unbound variable `y' ;;; :13:37: warning: possibly unbound variable `z' ;;; :14:37: warning: possibly unbound variable `N' ;;; :14:37: warning: possibly unbound variable `M' ;;; :15:39: warning: possibly unbound variable `x' ;;; :15:39: warning: possibly unbound variable `y' ;;; :15:39: warning: possibly unbound variable `z' ;;; :15:39: warning: possibly unbound variable `c2' While compiling expression: ERROR: unbound lexical # scheme@(guile-user)> (use-modules (system base compile) (language tree-il) (language tree-il primitives) (language tree-il peval) (language tree-il debug)) scheme@(guile-user)> (compile '(define (f-scope f) (define (g f x3) (define (h x2 n m) (lambda xx (apply (f-skip n m) x2))) ( (c) (.. (c2) (f c)) (let ((n N) (m M)) (.. ((h x3 n m) c2))))) =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20 (lambda x (apply (g f x) x))) #:to 'tree-il #:env (current-module)) $1 =3D # scheme@(guile-user)> (expand-primitives (resolve-primitives $1 (current-mod= ule))) $2 =3D # scheme@(guile-user)> ,pp (decompile $2 #:env (current-module)) $3 =3D (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))) $4 =3D # scheme@(guile-user)> (peval $2) $5 =3D # scheme@(guile-user)> (verify-tree-il $5) ERROR: In procedure scm-error: ERROR: unbound lexical # Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. scheme@(guile-user) [1]> ,q scheme@(guile-user)> (make-let #f '(x) '(#{x 945}#) (list (make-const #f 'D= UMMY)) $5) $6 =3D # scheme@(guile-user)> (verify-tree-il $6) $7 =3D # scheme@(guile-user)> ,pp (decompile $6 #:env (current-module)) $8 =3D (let ((x-1 'DUMMY)) (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))))) $9 =3D # scheme@(guile-user)>=20 --8<---------------cut here---------------end--------------->8--- Above, I wrapped the faulty code with an extra 'let' to bind the dangling reference, to allow the decompiler to run. 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)))) To be continued... Mark From debbugs-submit-bounces@debbugs.gnu.org Sun Dec 03 19:44:13 2017 Received: (at 29520) by debbugs.gnu.org; 4 Dec 2017 00:44:13 +0000 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 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 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 From: Mark H Weaver To: Stefan Israelsson Tampe Subject: Re: bug#29520: peval leaves behind dangling lexical reference References: <87shcrxyat.fsf@netris.org> Date: Sun, 03 Dec 2017 19:43:45 -0500 In-Reply-To: <87shcrxyat.fsf@netris.org> (Mark H. Weaver's message of "Sun, 03 Dec 2017 17:05:14 -0500") Message-ID: <87mv2zxqym.fsf@netris.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 29520 Cc: 29520@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) 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 From debbugs-submit-bounces@debbugs.gnu.org Mon Dec 04 00:41:28 2017 Received: (at 29520) by debbugs.gnu.org; 4 Dec 2017 05:41:28 +0000 Received: from localhost ([127.0.0.1]:44176 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eLjVQ-0002u0-17 for submit@debbugs.gnu.org; Mon, 04 Dec 2017 00:41:28 -0500 Received: from world.peace.net ([50.252.239.5]:60870) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eLjVO-0002sX-BG for 29520@debbugs.gnu.org; Mon, 04 Dec 2017 00:41:26 -0500 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 1eLjVH-0003f4-Li; Mon, 04 Dec 2017 00:41:19 -0500 From: Mark H Weaver To: Stefan Israelsson Tampe Subject: Re: bug#29520: peval leaves behind dangling lexical reference References: <87shcrxyat.fsf@netris.org> <87mv2zxqym.fsf@netris.org> Date: Mon, 04 Dec 2017 00:41:01 -0500 In-Reply-To: <87mv2zxqym.fsf@netris.org> (Mark H. Weaver's message of "Sun, 03 Dec 2017 19:43:45 -0500") Message-ID: <878tejxd76.fsf@netris.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 29520 Cc: 29520@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Mark H Weaver 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." ($ _ _ sym) ...)) (and (equal? sym gensyms) + (every (lambda (s) + (= (lexical-refcount s) 1)) + sym) (not (lambda-case-alternate lcase)) lcase)) (_ #f)))) From debbugs-submit-bounces@debbugs.gnu.org Mon Dec 04 16:10:26 2017 Received: (at 29520) by debbugs.gnu.org; 4 Dec 2017 21:10:26 +0000 Received: from localhost ([127.0.0.1]:46008 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eLy0Q-0007A7-IY for submit@debbugs.gnu.org; Mon, 04 Dec 2017 16:10:26 -0500 Received: from world.peace.net ([50.252.239.5]:35550) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eLy0P-00079v-2Y for 29520@debbugs.gnu.org; Mon, 04 Dec 2017 16:10:25 -0500 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 1eLy0J-0008Q8-2I; Mon, 04 Dec 2017 16:10:19 -0500 From: Mark H Weaver To: Stefan Israelsson Tampe Subject: Re: bug#29520: peval leaves behind dangling lexical reference References: <87shcrxyat.fsf@netris.org> <87mv2zxqym.fsf@netris.org> <878tejxd76.fsf@netris.org> Date: Mon, 04 Dec 2017 16:10:00 -0500 In-Reply-To: <878tejxd76.fsf@netris.org> (Mark H. Weaver's message of "Mon, 04 Dec 2017 00:41:01 -0500") Message-ID: <87wp22w66v.fsf@netris.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 29520 Cc: 29520@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Mark H Weaver writes: > Mark H Weaver 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. 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. I'll look into how to fix this. Mark From debbugs-submit-bounces@debbugs.gnu.org Mon Dec 04 21:55:47 2017 Received: (at 29520) by debbugs.gnu.org; 5 Dec 2017 02:55:47 +0000 Received: from localhost ([127.0.0.1]:46221 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eM3Od-00043Z-BI for submit@debbugs.gnu.org; Mon, 04 Dec 2017 21:55:47 -0500 Received: from world.peace.net ([50.252.239.5]:36854) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eM3Oc-00043M-4O for 29520@debbugs.gnu.org; Mon, 04 Dec 2017 21:55:46 -0500 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 1eM3OV-00025j-So; Mon, 04 Dec 2017 21:55:40 -0500 From: Mark H Weaver To: Stefan Israelsson Tampe Subject: Re: bug#29520: peval leaves behind dangling lexical reference References: <87shcrxyat.fsf@netris.org> <87mv2zxqym.fsf@netris.org> <878tejxd76.fsf@netris.org> <87wp22w66v.fsf@netris.org> Date: Mon, 04 Dec 2017 21:55:21 -0500 In-Reply-To: <87wp22w66v.fsf@netris.org> (Mark H. Weaver's message of "Mon, 04 Dec 2017 16:10:00 -0500") Message-ID: <878tehvq7a.fsf@netris.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 29520 Cc: 29520@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Mark H Weaver 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 (($ _ 'apply - (($ _ _ (and lcase ($ ))) + (($ _ _ (and lcase ($ _ req1))) ($ _ _ 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)) From debbugs-submit-bounces@debbugs.gnu.org Thu Mar 15 23:42:36 2018 Received: (at 29520-done) by debbugs.gnu.org; 16 Mar 2018 03:42:36 +0000 Received: from localhost ([127.0.0.1]:35615 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ewgGK-0008W0-2K for submit@debbugs.gnu.org; Thu, 15 Mar 2018 23:42:36 -0400 Received: from world.peace.net ([50.252.239.5]:47756) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ewgGI-0008Vn-H1 for 29520-done@debbugs.gnu.org; Thu, 15 Mar 2018 23:42:34 -0400 Received: from pool-72-93-30-18.bstnma.east.verizon.net ([72.93.30.18] helo=yeeloong) by world.peace.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1ewgGC-00037I-Jw; Thu, 15 Mar 2018 23:42:28 -0400 From: Mark H Weaver To: Stefan Israelsson Tampe Subject: Re: bug#29520: peval leaves behind dangling lexical reference References: <87shcrxyat.fsf@netris.org> <87mv2zxqym.fsf@netris.org> <878tejxd76.fsf@netris.org> <87wp22w66v.fsf@netris.org> <878tehvq7a.fsf@netris.org> Date: Thu, 15 Mar 2018 23:41:32 -0400 In-Reply-To: <878tehvq7a.fsf@netris.org> (Mark H. Weaver's message of "Mon, 04 Dec 2017 21:55:21 -0500") Message-ID: <871sgk661f.fsf@netris.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 29520-done Cc: 29520-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Mark H Weaver writes: > 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 > (($ _ 'apply > - (($ _ _ (and lcase ($ ))) > + (($ _ _ (and lcase ($ _ req1))) > ($ _ _ 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)) Applied in commit b56e084c77914a7fde558e8fd28a218759a4ddd7 on the stable-2.2 branch. I'm closing this bug now, but feel free to reopen if you still see related problems. Thanks! Mark From unknown Thu Aug 21 12:11:43 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Fri, 13 Apr 2018 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator