From ea9831bb3cb4878273f6f848051c9b8c3c76d5f1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= Date: Wed, 12 Apr 2023 10:17:01 +0200 Subject: [PATCH] Better compilation of arguments to `ignore` * lisp/emacs-lisp/bytecomp.el (byte-compile-form) (byte-compile-ignore): Instead of compiling each `ignore` argument for value which is then immediately discarded, compile it for effect but suppress ignore-return-value warnings by passing the special value `for-effect-no-warn` as for-effect parameter. Proposed by Stefan Monnier. --- lisp/emacs-lisp/bytecomp.el | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 1b28fcd5093..c84c70971b3 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -3563,6 +3563,8 @@ lambda-expression." ;;delq delete cl-delete ;;nconc plist-put ))) + ;; Don't warn for arguments to `ignore'. + (not (eq byte-compile--for-effect 'for-effect-no-warn)) (byte-compile-warning-enabled-p 'ignored-return-value (car form))) (byte-compile-warn-x @@ -4446,11 +4448,8 @@ This function is never called when `lexical-binding' is nil." (defun byte-compile-ignore (form) (dolist (arg (cdr form)) - ;; Compile args for value (to avoid warnings about unused values), - ;; emit a discard after each, and trust the LAP peephole optimiser - ;; to annihilate useless ops. - (byte-compile-form arg) - (byte-compile-discard)) + ;; Compile each argument for-effect but suppress unused-value warnings. + (byte-compile-form arg 'for-effect-no-warn)) (byte-compile-form nil)) ;; Return the list of items in CONDITION-PARAM that match PRED-LIST. -- 2.39.2