GNU bug report logs - #15326
24.3; Incorrect "variable not left unused" in destructuring cl-loop

Previous Next

Package: emacs;

Reported by: Christopher Wellons <wellons <at> nullprogram.com>

Date: Tue, 10 Sep 2013 18:27:01 UTC

Severity: minor

Found in version 24.3

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 15326 in the body.
You can then email your comments to 15326 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#15326; Package emacs. (Tue, 10 Sep 2013 18:27:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Christopher Wellons <wellons <at> nullprogram.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 10 Sep 2013 18:27:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Christopher Wellons <wellons <at> nullprogram.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3; Incorrect "variable not left unused" in destructuring cl-loop
Date: Tue, 10 Sep 2013 14:25:33 -0400
The byte compiler emits an invalid warning about used "_" lexical
variables in cl-loop destructuring bindings. This was casually mentioned
in bug#8711, where destructuring-bind was fixed (presumably, since it's
fine now) but not loop.

Create a source file like so,

    ;;; -*- lexical-binding: t; -*-
    (require 'cl-lib)
    (cl-loop for (_ value) in '((a 1) (b 2))
             collect value)

Then compile,

    $ emacs -Q -batch -f batch-byte-compile tmp.el
    In toplevel form:
    tmp.el:3:1:Warning: variable `_' not left unused
    Wrote /tmp/tmp.elc

In the macro expansion, the _ is declared in a `let', then later set
with `setq', "using" it.


In GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.8.2)
 of 2013-06-25 on sochi, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.11204000
System Description:	Debian GNU/Linux unstable (sid)

Configured using:
 `configure '--build' 'x86_64-linux-gnu' '--build' 'x86_64-linux-gnu'
 '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib'
 '--localstatedir=/var/lib' '--infodir=/usr/share/info'
 '--mandir=/usr/share/man' '--with-pop=yes'
 '--enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.3/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.3/site-lisp:/usr/share/emacs/site-lisp'
 '--with-crt-dir=/usr/lib/x86_64-linux-gnu' '--with-x=yes'
 '--with-x-toolkit=gtk3' '--with-toolkit-scroll-bars'
 'build_alias=x86_64-linux-gnu' 'CFLAGS=-g -O2 -fstack-protector
 --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall'
 'LDFLAGS=-Wl,-z,relro' 'CPPFLAGS=-D_FORTIFY_SOURCE=2''




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15326; Package emacs. (Tue, 10 Sep 2013 21:06:02 GMT) Full text and rfc822 format available.

Message #8 received at 15326 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Christopher Wellons <wellons <at> nullprogram.com>
Cc: 15326 <at> debbugs.gnu.org
Subject: Re: bug#15326: 24.3;
 Incorrect "variable not left unused" in destructuring cl-loop
Date: Tue, 10 Sep 2013 17:05:52 -0400
> In the macro expansion, the _ is declared in a `let', then later set
> with `setq', "using" it.

A `setq' does not *use* a variable.  It just sets it, affecting
later uses.  If there's no later uses, the setq is just a no-op.

Fixing this will require someone to dig into the `cl-loop' macro.


        Stefan "who suspects it's not really fixed in
                destructuring-bind either"




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15326; Package emacs. (Wed, 11 Sep 2013 04:49:02 GMT) Full text and rfc822 format available.

Message #11 received at 15326 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Wellons <wellons <at> nullprogram.com>
To: 15326 <at> debbugs.gnu.org
Subject: Re: bug#15326: 24.3;
 Incorrect "variable not left unused" in destructuring cl-loop
Date: Wed, 11 Sep 2013 00:47:54 -0400
Stefan Monnier <monnier <at> IRO.UMontreal.CA> writes:
> A `setq' does not *use* a variable.  It just sets it, affecting
> later uses.

I mean that the compiler counts the setq as a use even in this simple
expression:

    (let (_)
      (setq _ t))
    ;; Warning: variable `_' not left unused

> If there's no later uses, the setq is just a no-op.

Without bothering to dig into the bytecode for it, it seems that the
compiler is still emitting code for the setq:

    (defun foo ()
      (let (_)
        (setq _ t)))

    (defun bar ()
      (let (_)))

    (equal (byte-compile 'foo)
           (byte-compile 'bar))
    ;; => nil

Maybe I'm not understanding what you mean by "no-op" here.




Reply sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
You have taken responsibility. (Sat, 28 Sep 2013 01:09:03 GMT) Full text and rfc822 format available.

Notification sent to Christopher Wellons <wellons <at> nullprogram.com>:
bug acknowledged by developer. (Sat, 28 Sep 2013 01:09:05 GMT) Full text and rfc822 format available.

Message #16 received at 15326-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Christopher Wellons <wellons <at> nullprogram.com>
Cc: 15326-done <at> debbugs.gnu.org
Subject: Re: bug#15326: 24.3;
 Incorrect "variable not left unused" in destructuring cl-loop
Date: Fri, 27 Sep 2013 21:08:53 -0400
I have just installed a patch into trunk which changes the code
generated by `cl-loop' such that this warning should not appear
any more.


        Stefan




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 26 Oct 2013 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 240 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.