From f478d2d1b935f609b6c390c0ef961c00b295bbd7 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Wed, 12 Feb 2025 18:05:11 +0100 Subject: [PATCH] Declare caar, cadr, etc. as side-effect-free * lisp/subr.el (caar, cadr, cdar, cddr, caaar, caadr, cadar, caddr) (cdaar, cdadr, cddar, cdddr, caaaar, caaadr, caadar, caaddr, cadaar) (cadadr, caddar, cadddr, cdaaar, cdaadr, cdadar, cdaddr, cddaar) (cddadr, cdddar, cddddr): Declare side-effect-free. * lisp/emacs-lisp/cl-macs.el: Remove redundant declarations of compatibility aliases for the above functions as side-effect-free. --- lisp/emacs-lisp/cl-macs.el | 10 +---- lisp/subr.el | 84 +++++++++++++++++++++++++------------- 2 files changed, 57 insertions(+), 37 deletions(-) diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index 7559c58e77a..2cf2b3b06e9 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el @@ -3731,15 +3731,7 @@ macro that returns its `&whole' argument." (dolist (y '(cl-first cl-second cl-third cl-fourth cl-fifth cl-sixth cl-seventh cl-eighth cl-ninth cl-tenth - cl-rest cl-endp cl-plusp cl-minusp - cl-caaar cl-caadr cl-cadar - cl-caddr cl-cdaar cl-cdadr - cl-cddar cl-cdddr cl-caaaar - cl-caaadr cl-caadar cl-caaddr - cl-cadaar cl-cadadr cl-caddar - cl-cadddr cl-cdaaar cl-cdaadr - cl-cdadar cl-cdaddr cl-cddaar - cl-cddadr cl-cdddar cl-cddddr)) + cl-rest cl-endp cl-plusp cl-minusp)) (put y 'side-effect-free t)) ;;; Things that are inline. diff --git a/lisp/subr.el b/lisp/subr.el index 12f4ec38b78..cda33ba6a29 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -609,142 +609,170 @@ treatment of negative COUNT provided by this function." (defun caar (x) "Return the car of the car of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (car (car x))) (defun cadr (x) "Return the car of the cdr of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (car (cdr x))) (defun cdar (x) "Return the cdr of the car of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (cdr (car x))) (defun cddr (x) "Return the cdr of the cdr of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (cdr (cdr x))) (defun caaar (x) "Return the `car' of the `car' of the `car' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (car (car (car x)))) (defun caadr (x) "Return the `car' of the `car' of the `cdr' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (car (car (cdr x)))) (defun cadar (x) "Return the `car' of the `cdr' of the `car' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (car (cdr (car x)))) (defun caddr (x) "Return the `car' of the `cdr' of the `cdr' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (car (cdr (cdr x)))) (defun cdaar (x) "Return the `cdr' of the `car' of the `car' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (cdr (car (car x)))) (defun cdadr (x) "Return the `cdr' of the `car' of the `cdr' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (cdr (car (cdr x)))) (defun cddar (x) "Return the `cdr' of the `cdr' of the `car' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (cdr (cdr (car x)))) (defun cdddr (x) "Return the `cdr' of the `cdr' of the `cdr' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (cdr (cdr (cdr x)))) (defun caaaar (x) "Return the `car' of the `car' of the `car' of the `car' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (car (car (car (car x))))) (defun caaadr (x) "Return the `car' of the `car' of the `car' of the `cdr' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (car (car (car (cdr x))))) (defun caadar (x) "Return the `car' of the `car' of the `cdr' of the `car' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (car (car (cdr (car x))))) (defun caaddr (x) "Return the `car' of the `car' of the `cdr' of the `cdr' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (car (car (cdr (cdr x))))) (defun cadaar (x) "Return the `car' of the `cdr' of the `car' of the `car' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (car (cdr (car (car x))))) (defun cadadr (x) "Return the `car' of the `cdr' of the `car' of the `cdr' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (car (cdr (car (cdr x))))) (defun caddar (x) "Return the `car' of the `cdr' of the `cdr' of the `car' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (car (cdr (cdr (car x))))) (defun cadddr (x) "Return the `car' of the `cdr' of the `cdr' of the `cdr' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (car (cdr (cdr (cdr x))))) (defun cdaaar (x) "Return the `cdr' of the `car' of the `car' of the `car' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (cdr (car (car (car x))))) (defun cdaadr (x) "Return the `cdr' of the `car' of the `car' of the `cdr' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (cdr (car (car (cdr x))))) (defun cdadar (x) "Return the `cdr' of the `car' of the `cdr' of the `car' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (cdr (car (cdr (car x))))) (defun cdaddr (x) "Return the `cdr' of the `car' of the `cdr' of the `cdr' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (cdr (car (cdr (cdr x))))) (defun cddaar (x) "Return the `cdr' of the `cdr' of the `car' of the `car' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (cdr (cdr (car (car x))))) (defun cddadr (x) "Return the `cdr' of the `cdr' of the `car' of the `cdr' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (cdr (cdr (car (cdr x))))) (defun cdddar (x) "Return the `cdr' of the `cdr' of the `cdr' of the `car' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (cdr (cdr (cdr (car x))))) (defun cddddr (x) "Return the `cdr' of the `cdr' of the `cdr' of the `cdr' of X." - (declare (compiler-macro internal--compiler-macro-cXXr)) + (declare (side-effect-free t) + (compiler-macro internal--compiler-macro-cXXr)) (cdr (cdr (cdr (cdr x))))) (defun last (list &optional n)