From: "Mattias Engdegård" <mattias.engdegard@gmail.com>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: 61730@debbugs.gnu.org, Stefan Monnier <monnier@iro.umontreal.ca>
Subject: bug#61730: 30.0.50; Compiler warnings for delq and delete
Date: Fri, 24 Feb 2023 16:52:36 +0100 [thread overview]
Message-ID: <80023A0E-9C1C-4559-9152-23CDD64181E6@gmail.com> (raw)
In-Reply-To: <670D8E4A-333D-4E2D-97CC-86728965989D@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 93 bytes --]
As promised, here is a first draft. The false positive rate seems indeed to be quite low.
[-- Attachment #2: warn-ignored-return-value.diff --]
[-- Type: application/octet-stream, Size: 4612 bytes --]
diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el
index 9345665eea8..fd9913d1be8 100644
--- a/lisp/emacs-lisp/byte-run.el
+++ b/lisp/emacs-lisp/byte-run.el
@@ -650,11 +650,8 @@ with-suppressed-warnings
`byte-compile-warnings' for a fuller explanation of the warning
types. The types that can be suppressed with this macro are
`free-vars', `callargs', `redefine', `obsolete',
-`interactive-only', `lexical', `mapcar', `constants',
-`suspicious' and `empty-body'.
-
-For the `mapcar' case, only the `mapcar' function can be used in
-the symbol list."
+`interactive-only', `lexical', `ignored-return-value', `constants',
+`suspicious' and `empty-body'."
;; Note: during compilation, this definition is overridden by the one in
;; byte-compile-initial-macro-environment.
(declare (debug (sexp body)) (indent 1))
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 095468ad978..5f428b8e1f9 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -317,7 +317,9 @@ byte-compile-warnings
lexical-dynamic
lexically bound variable declared dynamic elsewhere
make-local calls to `make-variable-buffer-local' that may be incorrect.
- mapcar mapcar called for effect.
+ ignored-return-value
+ function called without using the return value where this
+ is likely to be a mistake
not-unused warning about using variables with symbol names starting with _.
constants let-binding of, or assignment to, constants/nonvariables.
docstrings docstrings that are too wide (longer than
@@ -330,7 +332,7 @@ byte-compile-warnings
empty-body body argument to a special form or macro is empty.
If the list begins with `not', then the remaining elements specify warnings to
-suppress. For example, (not mapcar) will suppress warnings about mapcar.
+suppress. For example, (not free-vars) will suppress the `free-vars' warning.
The t value means \"all non experimental warning types\", and
excludes the types in `byte-compile--emacs-build-warning-types'.
@@ -3485,11 +3487,35 @@ byte-compile-normal-call
(byte-compile-callargs-warn form))
(if byte-compile-generate-call-tree
(byte-compile-annotate-call-tree form))
- (when (and byte-compile--for-effect (eq (car form) 'mapcar)
- (byte-compile-warning-enabled-p 'mapcar 'mapcar))
+
+ ;; We warn about ignored return values for two categories of functions:
+ ;; * Ones like `mapcar' that are side-effect-free themselves but call a
+ ;; user-supplied function.
+ ;; * Ones like `delq' that mutate a list but whose return argument is
+ ;; essential to use in case the start of the list has changed.
+ (when (and byte-compile--for-effect
+ (memq (car form)
+ ;; FIXME: Maybe we should use a property instead of
+ ;; this list.
+ '( mapcar mapcan mapconcat
+ assoc assoc-default
+ delq delete delete-dups delete-consecutive-dups
+ nconc sort
+ cl-delete cl-delete-if cl-delete-if-not
+ cl-delete-duplicates
+ cl-nsubst cl-nsubst-if cl-nsubst-if-not
+ cl-nsubstitute cl-nsubstitute-if cl-nsubstitute-if-not
+ cl-nunion cl-nintersection
+ cl-nset-difference cl-nset-exclusive-or
+ cl-nreconc cl-nsublis
+ cl-sort))
+ (byte-compile-warning-enabled-p 'ignored-return-value (car form)))
(byte-compile-warn-x
(car form)
- "`mapcar' called for effect; use `mapc' or `dolist' instead"))
+ "value from call to `%s' is unused%s"
+ (car form)
+ (cond ((eq (car form) 'mapcar) "; use `mapc' or `dolist' instead")
+ (t ""))))
(byte-compile-push-constant (car form))
(mapc 'byte-compile-form (cdr form)) ; wasteful, but faster.
(byte-compile-out 'byte-call (length (cdr form))))
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el
index 4b0a714e52d..6dce3087e40 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -1420,8 +1420,8 @@ bytecomp-test--with-suppressed-warnings
'(defun zot ()
(mapcar #'list '(1 2 3))
nil)
- '((mapcar mapcar))
- "Warning: .mapcar. called for effect")
+ '((ignored-return-value mapcar))
+ "Warning: value from call to `mapcar' is unused; use `mapc' or `dolist' instead")
(test-suppression
'(defun zot ()
next prev parent reply other threads:[~2023-02-24 15:52 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-23 10:29 bug#61730: 30.0.50; Compiler warnings for delq and delete Michael Heerdegen
2023-02-24 3:59 ` Richard Stallman
2023-02-24 13:43 ` Mattias Engdegård
2023-02-24 13:56 ` Eli Zaretskii
2023-02-24 15:11 ` Michael Heerdegen
2023-02-24 15:29 ` Eli Zaretskii
2023-02-24 15:45 ` Michael Heerdegen
2023-02-24 15:48 ` Eli Zaretskii
2023-02-24 16:17 ` Michael Heerdegen
2023-02-24 16:45 ` Michael Heerdegen
2023-02-24 19:33 ` Mattias Engdegård
2023-02-24 20:20 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-25 9:40 ` Mattias Engdegård
2023-02-25 4:15 ` Richard Stallman
2023-02-25 8:11 ` Eli Zaretskii
2023-02-25 12:34 ` Michael Heerdegen
2023-02-25 13:25 ` Eli Zaretskii
2023-02-25 15:09 ` Michael Heerdegen
2023-02-25 15:29 ` Michael Heerdegen
2023-02-25 15:48 ` Eli Zaretskii
2023-02-27 3:22 ` Richard Stallman
2023-02-27 10:37 ` Michael Heerdegen
2023-02-27 11:37 ` Eli Zaretskii
2023-02-27 3:24 ` Richard Stallman
2023-02-27 11:44 ` Eli Zaretskii
2023-02-24 15:52 ` Mattias Engdegård [this message]
2023-02-24 16:37 ` Michael Heerdegen
2023-04-09 16:41 ` Mattias Engdegård
2023-05-01 16:06 ` Mattias Engdegård
2023-05-20 1:57 ` Michael Heerdegen
2023-05-20 9:14 ` Mattias Engdegård
2023-05-21 0:56 ` Michael Heerdegen
2023-05-21 3:01 ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-21 3:57 ` Michael Heerdegen
2023-05-21 5:55 ` Eli Zaretskii
2023-05-21 8:42 ` Mattias Engdegård
2023-05-31 14:38 ` Mattias Engdegård
2023-06-01 0:48 ` Michael Heerdegen
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/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=80023A0E-9C1C-4559-9152-23CDD64181E6@gmail.com \
--to=mattias.engdegard@gmail.com \
--cc=61730@debbugs.gnu.org \
--cc=michael_heerdegen@web.de \
--cc=monnier@iro.umontreal.ca \
/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.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).