[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master b20866c4b3a 8/9: Better `sort` ignored-return-value warning
From: |
Mattias Engdegård |
Subject: |
master b20866c4b3a 8/9: Better `sort` ignored-return-value warning |
Date: |
Fri, 29 Mar 2024 06:55:18 -0400 (EDT) |
branch: master
commit b20866c4b3aa1446efda252bd5c3fa54f68c5d7f
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>
Better `sort` ignored-return-value warning
* lisp/emacs-lisp/bytecomp.el (byte-compile-form)
(bytecomp--actually-important-return-value-p):
Special handling of `sort` that takes into account that it may return
an important value depending on the :in-place keyword argument.
---
lisp/emacs-lisp/bytecomp.el | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 7af568cfe34..2b5eb34e571 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -3445,6 +3445,7 @@ lambda-expression."
((and (or sef (function-get (car form) 'important-return-value))
;; Don't warn for arguments to `ignore'.
(not (eq byte-compile--for-effect 'for-effect-no-warn))
+ (bytecomp--actually-important-return-value-p form)
(byte-compile-warning-enabled-p
'ignored-return-value (car form)))
(byte-compile-warn-x
@@ -3471,6 +3472,15 @@ lambda-expression."
(if byte-compile--for-effect
(byte-compile-discard)))))
+(defun bytecomp--actually-important-return-value-p (form)
+ "Whether FORM is really a call with a return value that should not go unused.
+This assumes the function has the `important-return-value' property."
+ (cond ((eq (car form) 'sort)
+ ;; For `sort', we only care about non-destructive uses.
+ (and (zerop (% (length form) 2)) ; new-style call
+ (not (plist-get (cddr form) :in-place))))
+ (t t)))
+
(let ((important-return-value-fns
'(
;; These functions are side-effect-free except for the
@@ -3478,9 +3488,11 @@ lambda-expression."
mapcar mapcan mapconcat
assoc plist-get plist-member
- ;; It's safe to ignore the value of `sort' and `nreverse'
+ ;; It's safe to ignore the value of `nreverse'
;; when used on arrays, but most calls pass lists.
- nreverse sort
+ nreverse
+
+ sort ; special handling (non-destructive calls only)
match-data
- master updated (c3684b97885 -> 2f0df93d8ca), Mattias Engdegård, 2024/03/29
- master 1232ab31c65 1/9: Add `value<` (bug#69709), Mattias Engdegård, 2024/03/29
- master cbd862865ff 7/9: Remove `sort-on` (bug#69709), Mattias Engdegård, 2024/03/29
- master 92d659ce6cd 6/9: Use new-style `sort` signature in Lisp manual examples, Mattias Engdegård, 2024/03/29
- master deae3112815 4/9: Speed up `sort` by special-casing the `value<` ordering, Mattias Engdegård, 2024/03/29
- master 2f0df93d8ca 9/9: ; * test/lisp/vc/vc-git-tests.el: bend doc string quote, Mattias Engdegård, 2024/03/29
- master a52f1121a35 2/9: Add back timsort key function handling (bug#69709), Mattias Engdegård, 2024/03/29
- master ae5f2c02bd2 3/9: New `sort` keyword arguments (bug#69709), Mattias Engdegård, 2024/03/29
- master b20866c4b3a 8/9: Better `sort` ignored-return-value warning,
Mattias Engdegård <=
- master 45941a62c79 5/9: Faster non-destructive list sorting, Mattias Engdegård, 2024/03/29