summaryrefslogtreecommitdiff
path: root/lisp/subr.el
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2023-02-17 14:38:50 +0100
committerMattias EngdegÄrd <mattiase@acm.org>2023-02-17 14:52:54 +0100
commitd5bf26f488b7968feed9f43e612a90da2aab15a8 (patch)
treef31f3a743eef072012597f812fd2e5635c170de7 /lisp/subr.el
parent7ab6c6ac8334f80a2effcb9d66d2c57810c9a73e (diff)
downloademacs-d5bf26f488b7968feed9f43e612a90da2aab15a8.tar.gz
Move side-effect-free and pure declarations to function definitions
Some Lisp functions still had their `side-effect-free` and `pure` properties declared in byte-opt.el; do it at their definition instead. The lists in byte-opt.el now only contain functions implemented in C and function aliases. * lisp/emacs-lisp/byte-opt.el (side-effect-free-fns) (side-effect-and-error-free-fns, pure-fns): Remove functions whose properties are now declared elsewhere and some obsolete entries. * lisp/custom.el (custom-variable-p): * lisp/emacs-lisp/lisp.el (buffer-end): * lisp/emacs-lisp/regexp-opt.el (regexp-opt): * lisp/env.el (getenv): * lisp/simple.el (count-lines, mark, string-empty-p, lax-plist-get): * lisp/subr.el (ignore, always, zerop, fixnump, bignump, lsh, last) (eventp, mouse-movement-p, log10, memory-limit, string-greaterp) (interactive-p): * lisp/window.el (get-lru-window, get-largest-window, (window-edges) (window-body-edges, window-pixel-edges, window-body-pixel-edges) (window-absolute-pixel-edges, window-absolute-body-pixel-edges) (one-window-p): Declare functions `side-effect-free` and/or `pure` as appropriate.
Diffstat (limited to 'lisp/subr.el')
-rw-r--r--lisp/subr.el24
1 files changed, 18 insertions, 6 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index a1397fa6781..819d2a51101 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -422,7 +422,9 @@ PREFIX is a string, and defaults to \"g\"."
"Do nothing and return nil.
This function accepts any number of ARGUMENTS, but ignores them.
Also see `always'."
- (declare (completion ignore))
+ ;; Not declared `side-effect-free' because we don't want calls to it
+ ;; elided; see `byte-compile-ignore'.
+ (declare (pure t) (completion ignore))
(interactive)
nil)
@@ -430,6 +432,7 @@ Also see `always'."
"Do nothing and return t.
This function accepts any number of ARGUMENTS, but ignores them.
Also see `ignore'."
+ (declare (pure t) (side-effect-free error-free))
t)
;; Signal a compile-error if the first arg is missing.
@@ -509,16 +512,19 @@ was called."
"Return t if NUMBER is zero."
;; Used to be in C, but it's pointless since (= 0 n) is faster anyway because
;; = has a byte-code.
- (declare (compiler-macro (lambda (_) `(= 0 ,number))))
+ (declare (pure t) (side-effect-free t)
+ (compiler-macro (lambda (_) `(= 0 ,number))))
(= 0 number))
(defun fixnump (object)
"Return t if OBJECT is a fixnum."
+ (declare (side-effect-free error-free))
(and (integerp object)
(<= most-negative-fixnum object most-positive-fixnum)))
(defun bignump (object)
"Return t if OBJECT is a bignum."
+ (declare (side-effect-free error-free))
(and (integerp object) (not (fixnump object))))
(defun lsh (value count)
@@ -533,7 +539,8 @@ instead."
(lambda (form)
(macroexp-warn-and-return
(format-message "avoid `lsh'; use `ash' instead")
- form '(suspicious lsh) t form))))
+ form '(suspicious lsh) t form)))
+ (side-effect-free t))
(when (and (< value 0) (< count 0))
(when (< value most-negative-fixnum)
(signal 'args-out-of-range (list value count)))
@@ -706,7 +713,7 @@ instead."
If LIST is nil, return nil.
If N is non-nil, return the Nth-to-last link of LIST.
If N is bigger than the length of LIST, return LIST."
- (declare (side-effect-free t))
+ (declare (pure t) (side-effect-free t)) ; pure up to mutation
(if n
(and (>= n 0)
(let ((m (safe-length list)))
@@ -1525,6 +1532,7 @@ See also `current-global-map'.")
(defun eventp (object)
"Return non-nil if OBJECT is an input event or event object."
+ (declare (pure t) (side-effect-free error-free))
(or (integerp object)
(and (if (consp object)
(setq object (car object))
@@ -1587,6 +1595,7 @@ in the current Emacs session, then this function may return nil."
(defsubst mouse-movement-p (object)
"Return non-nil if OBJECT is a mouse movement event."
+ (declare (side-effect-free error-free))
(eq (car-safe object) 'mouse-movement))
(defun mouse-event-p (object)
@@ -1859,7 +1868,7 @@ be a list of the form returned by `event-start' and `event-end'."
(defun log10 (x)
"Return (log X 10), the log base 10 of X."
- (declare (obsolete log "24.4"))
+ (declare (side-effect-free t) (obsolete log "24.4"))
(log x 10))
(set-advertised-calling-convention
@@ -2983,6 +2992,7 @@ It can be retrieved with `(process-get PROCESS PROPNAME)'."
(defun memory-limit ()
"Return an estimate of Emacs virtual memory usage, divided by 1024."
+ (declare (side-effect-free error-free))
(let ((default-directory temporary-file-directory))
(or (cdr (assq 'vsize (process-attributes (emacs-pid)))) 0)))
@@ -5544,6 +5554,7 @@ consisting of STR followed by an invisible left-to-right mark
"Return non-nil if STRING1 is greater than STRING2 in lexicographic order.
Case is significant.
Symbols are also allowed; their print names are used instead."
+ (declare (pure t) (side-effect-free t))
(string-lessp string2 string1))
@@ -6187,7 +6198,8 @@ To test whether a function can be called interactively, use
`commandp'."
;; Kept around for now. See discussion at:
;; https://lists.gnu.org/r/emacs-devel/2020-08/msg00564.html
- (declare (obsolete called-interactively-p "23.2"))
+ (declare (obsolete called-interactively-p "23.2")
+ (side-effect-free error-free))
(called-interactively-p 'interactive))
(defun internal-push-keymap (keymap symbol)