From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#61730: 30.0.50; Compiler warnings for delq and delete Date: Fri, 24 Feb 2023 16:52:36 +0100 Message-ID: <80023A0E-9C1C-4559-9152-23CDD64181E6@gmail.com> References: <670D8E4A-333D-4E2D-97CC-86728965989D@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.14\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_FE12AF39-C843-46B6-8196-95E753F3668B" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31461"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 61730@debbugs.gnu.org, Stefan Monnier To: Michael Heerdegen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Feb 24 16:53:14 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pVaNl-0007zo-PA for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 24 Feb 2023 16:53:13 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVaNe-0003zU-65; Fri, 24 Feb 2023 10:53:06 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pVaNa-0003vI-FM for bug-gnu-emacs@gnu.org; Fri, 24 Feb 2023 10:53:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pVaNa-00056i-6r for bug-gnu-emacs@gnu.org; Fri, 24 Feb 2023 10:53:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pVaNa-0001uu-3A for bug-gnu-emacs@gnu.org; Fri, 24 Feb 2023 10:53:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 24 Feb 2023 15:53:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61730 X-GNU-PR-Package: emacs Original-Received: via spool by 61730-submit@debbugs.gnu.org id=B61730.16772539657336 (code B ref 61730); Fri, 24 Feb 2023 15:53:02 +0000 Original-Received: (at 61730) by debbugs.gnu.org; 24 Feb 2023 15:52:45 +0000 Original-Received: from localhost ([127.0.0.1]:37986 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pVaNJ-0001uF-CO for submit@debbugs.gnu.org; Fri, 24 Feb 2023 10:52:45 -0500 Original-Received: from mail-lf1-f54.google.com ([209.85.167.54]:40799) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pVaNH-0001u0-Hi for 61730@debbugs.gnu.org; Fri, 24 Feb 2023 10:52:43 -0500 Original-Received: by mail-lf1-f54.google.com with SMTP id k14so17471805lfj.7 for <61730@debbugs.gnu.org>; Fri, 24 Feb 2023 07:52:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:sender:from:to:cc:subject:date:message-id:reply-to; bh=AZY4UrL23cCpYybjY3vMWhOPeX6ZptZodkgiZkuYcWo=; b=BNESq0i5AJe2o6OdyHz0G7/XAUoW/iVzWOLYLg0PHGxX9HzxpUPHNnFIzKmGTc4Zr9 5MjkvParKmgDcn1jD9oYOZkiyvNBy/XFpiQ4zn6x9fB0Zzio2VLurGdmzpU45Jvqqu6A 3Hejj+zyOkDhkaABrfeEqtX60srnuLe1gACHOdVsbncggQgc1dM7iqbVhed6zpYMtOti xjr2999mBMTsT4Rb634A8zvtpBmQ85ebj5YmX9bSmQh9i9oL/tedPYoEbW2gEoVt31j1 0k7vlD1BCNcAmXdhSqlSlICYyUyGTgqHglYvvlhZyVciLQWjo3LC05/Y3xtmHdhKB6OW n3+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AZY4UrL23cCpYybjY3vMWhOPeX6ZptZodkgiZkuYcWo=; b=NI+OGTw02HdVak8AM1E2j1632TEfXrzHTRWfuVGR9u+1JOrq+nrLNDq9pWaK5xi325 IYSZFuAWBvVIaVp+3pVys7RTNtgidQXFhaoxleuR9JBhY0E84FwXpzZNGCDytf+EHxY/ otYzDDmv8UfVqMnKrxmEbQYYtCC5KZpLgcwwZYuBFwPvlNyJBKLms0vVQVmG0PdCooAw RSXmGDjlQ6sP5KNmb29Rtcgb/VDOeYsz6H2gJMXAVV9cWad3deQyjbn32zqjMjx5FnOB WQgwA8AubF7ReVmsBYuv7YuGeknnJDfvX7bvzYWCcgf9/6SPZmTuOsWgW9JPbIzMHIn1 0liA== X-Gm-Message-State: AO0yUKUUX2Vn6cy5MyzeFn+ju3DHSm6jGyQJjztw3uRq4i590VXLLtvh VaihfQoZ81WM3LTfwaPmZ6Y= X-Google-Smtp-Source: AK7set/I3F6TJF3XjjS2ZNcP5VBiL/8e6UD2gYU4+IgnQuBJrH0N6clndV4rG881m0N7oJD56yOsnA== X-Received: by 2002:a05:6512:244:b0:4db:d6a:dea9 with SMTP id b4-20020a056512024400b004db0d6adea9mr6293650lfo.68.1677253957321; Fri, 24 Feb 2023 07:52:37 -0800 (PST) Original-Received: from smtpclient.apple (c188-150-171-209.bredband.tele2.se. [188.150.171.209]) by smtp.gmail.com with ESMTPSA id a28-20020ac2521c000000b004d34238ca44sm1707879lfl.214.2023.02.24.07.52.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Feb 2023 07:52:36 -0800 (PST) In-Reply-To: <670D8E4A-333D-4E2D-97CC-86728965989D@gmail.com> X-Mailer: Apple Mail (2.3654.120.0.1.14) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:256623 Archived-At: --Apple-Mail=_FE12AF39-C843-46B6-8196-95E753F3668B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii As promised, here is a first draft. The false positive rate seems indeed = to be quite low. --Apple-Mail=_FE12AF39-C843-46B6-8196-95E753F3668B Content-Disposition: attachment; filename=warn-ignored-return-value.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="warn-ignored-return-value.diff" Content-Transfer-Encoding: 7bit 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 () --Apple-Mail=_FE12AF39-C843-46B6-8196-95E753F3668B--