GNU bug report logs - #15122
24.3.50; [PATCH] byte-compiler warnings about destructive functions

Previous Next

Package: emacs;

Reported by: Drew Adams <drew.adams <at> oracle.com>

Date: Sun, 18 Aug 2013 05:27:01 UTC

Severity: wishlist

Tags: wontfix

Found in version 24.3.50

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

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 15122 in the body.
You can then email your comments to 15122 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#15122; Package emacs. (Sun, 18 Aug 2013 05:27:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Drew Adams <drew.adams <at> oracle.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 18 Aug 2013 05:27:02 GMT) Full text and rfc822 format available.

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

From: Drew Adams <drew.adams <at> oracle.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3.50; [PATCH] byte-compiler warnings about destructive functions
Date: Sat, 17 Aug 2013 22:26:16 -0700 (PDT)
[Message part 1 (text/plain, inline)]
This StackOverflow entry suggested that the Emacs-Lisp byte compiler be
able to warn about the use of functions that are destructive, i.e., can
modify data structures in place:

http://stackoverflow.com/questions/17610046/elisp-destructive-operation-warning

Attached is a patch that provides this, at least a start.

It covers the basic functions that can perform in-place data structure 
modification: lists, strings, vectors and other arrays, symbol properties.
These are generally the functions identified as destructive or modifying
in the Elisp manual.

A comment in the code identifies some other possible candidates that
occurred to me while browsing the manual.  Modify the list of functions
as you see fit (variable `byte-compile-destructive-functions').

I'm no expert on some of the data structure implementations, and the
manual is sometimes not so clear about whether destructive modification
occurs.  And perhaps there are cases where although the modification is
destructive at an implementation level the user need not be concerned
about that level, so such functions should not be included.  Dunno.

Perhaps also something could be done in the future wrt recognition of
particular cases for `setf' modification.

In GNU Emacs 24.3.50.1 (i686-pc-mingw32)
 of 2013-08-07 on ODIEONE
Bzr revision: 113750 lekktu <at> gmail.com-20130808011911-0jzpc9xuncegg6x9
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
 `configure --prefix=/c/Devel/emacs/binary --enable-checking=yes,glyphs
 CFLAGS=-O0 -g3 LDFLAGS=-Lc:/Devel/emacs/lib
 CPPFLAGS=-Ic:/Devel/emacs/include'
[bytecomp-2013-08-17a.patch (application/octet-stream, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15122; Package emacs. (Sun, 18 Aug 2013 18:40:02 GMT) Full text and rfc822 format available.

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

From: Richard Stallman <rms <at> gnu.org>
To: Drew Adams <drew.adams <at> oracle.com>
Cc: 15122 <at> debbugs.gnu.org
Subject: Re: bug#15122: 24.3.50;
 [PATCH] byte-compiler warnings about destructive functions
Date: Sun, 18 Aug 2013 14:38:53 -0400
        [ To any NSA and FBI agents reading my email: please consider
        [ whether defending the US Constitution against all enemies,
        [ foreign or domestic, requires you to follow Snowden's example.

    It covers the basic functions that can perform in-place data structure 
    modification: lists, strings, vectors and other arrays, symbol properties.

Why cater to such a weird style preference?  It would require
continuing work to maintain.  Someone who wants to do this
can easily write a function to search for the function names he wants
to avoid using.

-- 
Dr Richard Stallman
President, Free Software Foundation
51 Franklin St
Boston MA 02110
USA
www.fsf.org  www.gnu.org
Skype: No way! That's nonfree (freedom-denying) software.
  Use Ekiga or an ordinary phone call.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15122; Package emacs. (Mon, 19 Aug 2013 03:00:03 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Drew Adams <drew.adams <at> oracle.com>
Cc: 15122 <at> debbugs.gnu.org
Subject: Re: bug#15122: 24.3.50;
 [PATCH] byte-compiler warnings about destructive functions
Date: Sun, 18 Aug 2013 22:59:51 -0400
> This StackOverflow entry suggested that the Emacs-Lisp byte compiler be
> able to warn about the use of functions that are destructive, i.e., can
> modify data structures in place:
> http://stackoverflow.com/questions/17610046/elisp-destructive-operation-warning
> Attached is a patch that provides this, at least a start.

All of those functions are used on a regular basis in perfectly
correct code.  So just flagging every call is not going to fly.  We need
to have some further analysis so that we don't flag all calls, but only
those that "could be dangerous".

As it stands, your code would just flood you with false positives,
so it wouldn't really help you find the problematic uses.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15122; Package emacs. (Mon, 19 Aug 2013 05:08:02 GMT) Full text and rfc822 format available.

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

From: Drew Adams <drew.adams <at> oracle.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 15122 <at> debbugs.gnu.org
Subject: RE: bug#15122: 24.3.50; [PATCH] byte-compiler warnings about
 destructive functions
Date: Sun, 18 Aug 2013 22:07:14 -0700 (PDT)
> > This StackOverflow entry suggested that the Emacs-Lisp byte compiler be
> > able to warn about the use of functions that are destructive, i.e., can
> > modify data structures in place:
> > http://stackoverflow.com/questions/17610046/elisp-destructive-operation-
> > warning Attached is a patch that provides this, at least a start.
> 
> All of those functions are used on a regular basis in perfectly
> correct code.  So just flagging every call is not going to fly.  We need
> to have some further analysis so that we don't flag all calls, but only
> those that "could be dangerous".
> 
> As it stands, your code would just flood you with false positives,
> so it wouldn't really help you find the problematic uses.

That was not the aim.  The question was not whether particular code that
uses a destructive operation is correct.  The question was whether
particular code uses a destructive operation at all.  That's all.

See the OP, which spoke of an "elisp-newbie-mode".  He requested a
feature that "adds warnings about destructive operations being used".
Not being used wrongly or problematically, just being used.

Anyway, I would agree that warning about use of a destructive function
should be turned off by default.  It's also fine with me if you ignore
the patch altogether.

I can see a use for such a warning, as I expect there are a fair number
of people who want to avoid using destructive operations in general and
might not be aware of when they might be doing so.  I mentioned Scheme's
explicit choice to name all such functions in a noticeable way.  Drawing
attention to (all) use of destructive operations is not necessarily a
useless thing, depending on the user and context.

That was the point of the patch.  It was not to detect uses that are
"problematic", such as where you forget to use `setq' after `delq' to
store the result back into the source variable, or similar.  (Yes, it
is true that the OP example was such a case.)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15122; Package emacs. (Tue, 20 Aug 2013 05:08:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Drew Adams <drew.adams <at> oracle.com>
Cc: 15122 <at> debbugs.gnu.org
Subject: Re: bug#15122: 24.3.50;
 [PATCH] byte-compiler warnings about destructive functions
Date: Tue, 20 Aug 2013 01:07:12 -0400
> might not be aware of when they might be doing so.  I mentioned Scheme's
> explicit choice to name all such functions in a noticeable way.  Drawing
> attention to (all) use of destructive operations is not necessarily a
> useless thing, depending on the user and context.

Yes, I like Scheme's convention.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15122; Package emacs. (Tue, 20 Aug 2013 14:08:02 GMT) Full text and rfc822 format available.

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

From: Drew Adams <drew.adams <at> oracle.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 15122 <at> debbugs.gnu.org
Subject: RE: bug#15122: 24.3.50; [PATCH] byte-compiler warnings about
 destructive functions
Date: Tue, 20 Aug 2013 07:07:36 -0700 (PDT)
> > might not be aware of when they might be doing so.  I mentioned Scheme's
> > explicit choice to name all such functions in a noticeable way.  Drawing
> > attention to (all) use of destructive operations is not necessarily a
> > useless thing, depending on the user and context.
> 
> Yes, I like Scheme's convention.

Then consider adding (subtle, optional) font-lock highlighting of such.
That would anyway be better than compiler warnings.  The list of fns
I came up with is a start.  You might even consider putting a recognizable
property on the function symbols, as well.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15122; Package emacs. (Tue, 20 Aug 2013 14:40:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Drew Adams <drew.adams <at> oracle.com>
Cc: 15122 <at> debbugs.gnu.org
Subject: Re: bug#15122: 24.3.50;
 [PATCH] byte-compiler warnings about destructive functions
Date: Tue, 20 Aug 2013 10:39:54 -0400
>> > might not be aware of when they might be doing so.  I mentioned Scheme's
>> > explicit choice to name all such functions in a noticeable way.  Drawing
>> > attention to (all) use of destructive operations is not necessarily a
>> > useless thing, depending on the user and context.
>> Yes, I like Scheme's convention.
> Then consider adding (subtle, optional) font-lock highlighting of such.
> That would anyway be better than compiler warnings.  The list of fns
> I came up with is a start.  You might even consider putting a recognizable
> property on the function symbols, as well.

Font-lock might be a good idea, indeed.
We could also additionally start to introduce Scheme-style names, like
sort!, reverse!, butlast!, ...


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15122; Package emacs. (Tue, 20 Aug 2013 15:16:02 GMT) Full text and rfc822 format available.

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

From: Drew Adams <drew.adams <at> oracle.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 15122 <at> debbugs.gnu.org
Subject: RE: bug#15122: 24.3.50; [PATCH] byte-compiler warnings about
 destructive functions
Date: Tue, 20 Aug 2013 08:15:51 -0700 (PDT)
> >> Yes, I like Scheme's convention.
> > Then consider adding (subtle, optional) font-lock highlighting of such.
> > That would anyway be better than compiler warnings.  The list of fns
> > I came up with is a start.  You might even consider putting a recognizable
> > property on the function symbols, as well.
> 
> Font-lock might be a good idea, indeed.
> We could also additionally start to introduce Scheme-style names, like
> sort!, reverse!, butlast!, ...

I would vote against that.  We should aim to be closer to Common Lisp (in
behavior and in naming, wrt new or changed names), not closer to Scheme.

Optional font-locking is an appropriate Emacs response to this need.
Scheme naming is not, IMO.  This indication should be optional and off by
default.

Just one opinion.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15122; Package emacs. (Wed, 21 Aug 2013 01:01:01 GMT) Full text and rfc822 format available.

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

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 15122 <at> debbugs.gnu.org, Drew Adams <drew.adams <at> oracle.com>
Subject: Re: bug#15122: 24.3.50;
 [PATCH] byte-compiler warnings about destructive functions
Date: Wed, 21 Aug 2013 09:00:06 +0800
On 2013-08-20 22:39 +0800, Stefan Monnier wrote:
> Font-lock might be a good idea, indeed.
> We could also additionally start to introduce Scheme-style names, like
> sort!, reverse!, butlast!, ...

But one would desperately want lisp-1.

Leo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15122; Package emacs. (Wed, 21 Aug 2013 04:25:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 15122 <at> debbugs.gnu.org, Drew Adams <drew.adams <at> oracle.com>
Subject: Re: bug#15122: 24.3.50;
 [PATCH] byte-compiler warnings about destructive functions
Date: Wed, 21 Aug 2013 00:24:37 -0400
>> Font-lock might be a good idea, indeed.
>> We could also additionally start to introduce Scheme-style names, like
>> sort!, reverse!, butlast!, ...
> But one would desperately want lisp-1.

We'll get that when we switch to Emacs-Guile.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15122; Package emacs. (Wed, 21 Aug 2013 16:55:02 GMT) Full text and rfc822 format available.

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

From: Richard Stallman <rms <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 15122 <at> debbugs.gnu.org, sdl.web <at> gmail.com
Subject: Re: bug#15122: 24.3.50;
 [PATCH] byte-compiler warnings about destructive functions
Date: Wed, 21 Aug 2013 12:54:15 -0400
        [ To any NSA and FBI agents reading my email: please consider
        [ whether defending the US Constitution against all enemies,
        [ foreign or domestic, requires you to follow Snowden's example.

Changing text in a buffer is a very important part of Emacs.
Thus, I think applying a naming convention to all functions
with side effects is absurd in the context of Emacs.

-- 
Dr Richard Stallman
President, Free Software Foundation
51 Franklin St
Boston MA 02110
USA
www.fsf.org  www.gnu.org
Skype: No way! That's nonfree (freedom-denying) software.
  Use Ekiga or an ordinary phone call.





bug closed, send any further explanations to 15122 <at> debbugs.gnu.org and Drew Adams <drew.adams <at> oracle.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Wed, 24 Feb 2016 04:32:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 23 Mar 2016 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 9 years and 94 days ago.

Previous Next


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