Move lisp function arg type declarations to the functions itself
authorAndrea Corallo <acorallo@gnu.org>
Wed, 10 Apr 2024 20:07:16 +0000 (22:07 +0200)
committerAndrea Corallo <acorallo@gnu.org>
Mon, 29 Apr 2024 17:27:28 +0000 (19:27 +0200)
* lisp/emacs-lisp/comp-common.el (comp-primitive-type-specifiers):
Remove type declaration of lisp functions.
* lisp/window.el (get-lru-window, get-largest-window)
(one-window-p): Declare type.
* lisp/subr.el (ignore, error, zerop, fixnump, bignump, lsh)
(last, eventp, mouse-movement-p, log10, memory-limit)
(interactive-p): Likewise.
* lisp/simple.el (count-lines, mark, lax-plist-get): Likewise.
* lisp/files.el (parse-colon-path): Likewise.
* lisp/env.el (getenv): Likewise.
* lisp/emacs-lisp/regexp-opt.el (regexp-opt): Likewise.
* lisp/emacs-lisp/lisp.el (buffer-end): Likewise.
* lisp/emacs-lisp/comp.el (comp-hint-fixnum, comp-hint-cons): Likewise.
* lisp/custom.el (custom-variable-p): Likewise.

lisp/custom.el
lisp/emacs-lisp/comp-common.el
lisp/emacs-lisp/comp.el
lisp/emacs-lisp/lisp.el
lisp/emacs-lisp/regexp-opt.el
lisp/env.el
lisp/files.el
lisp/simple.el
lisp/subr.el
lisp/window.el

index a19b14aaf8a0788fe2471d886c2882aa1ac01566..6f2aa18ba1dab545e538f8d513494524323a82c2 100644 (file)
@@ -667,7 +667,8 @@ If NOSET is non-nil, don't bother autoloading LOAD when setting the variable."
 A customizable variable is either (i) a variable whose property
 list contains a non-nil `standard-value' or `custom-autoload'
 property, or (ii) an alias for another customizable variable."
-  (declare (side-effect-free t))
+  (declare (type (function (symbol) t))
+           (side-effect-free t))
   (when (symbolp variable)
     (setq variable (indirect-variable variable))
     (or (get variable 'standard-value)
index cfaf843a3fd0ebce2f0461a8e776afdee98b2c8b..dea7af66a0cf38e2ab0a72025129e0aeee536b84 100644 (file)
@@ -68,7 +68,7 @@ Used to modify the compiler environment."
   :risky t
   :version "28.1")
 
-(defconst comp-known-type-specifiers
+(defconst comp-primitive-type-specifiers
   `(
     ;; Functions we can trust not to be redefined, or, if redefined,
     ;; to expose the same type.  The vast majority of these are
@@ -97,7 +97,6 @@ Used to modify the compiler environment."
     (assq (function (t list) list))
     (atan (function (number &optional number) float))
     (atom (function (t) boolean))
-    (bignump (function (t) boolean))
     (bobp (function () boolean))
     (bolp (function () boolean))
     (bool-vector-count-consecutive
@@ -107,7 +106,6 @@ Used to modify the compiler environment."
     (bool-vector-p (function (t) boolean))
     (bool-vector-subsetp (function (bool-vector bool-vector) boolean))
     (boundp (function (symbol) boolean))
-    (buffer-end (function ((or number marker)) integer))
     (buffer-file-name (function (&optional buffer) (or string null)))
     (buffer-list (function (&optional frame) list))
     (buffer-local-variables (function (&optional buffer) list))
@@ -157,8 +155,6 @@ Used to modify the compiler environment."
     (copy-sequence (function (sequence) sequence))
     (copysign (function (float float) float))
     (cos (function (number) float))
-    (count-lines
-     (function ((or integer marker) (or integer marker) &optional t) integer))
     (current-buffer (function () buffer))
     (current-global-map (function () cons))
     (current-indentation (function () integer))
@@ -171,7 +167,6 @@ Used to modify the compiler environment."
     (current-time-zone (function (&optional (or number list)
                                             (or symbol string cons integer))
                                  cons))
-    (custom-variable-p (function (symbol) t))
     (decode-char (function (cons t) (or fixnum null)))
     (decode-time (function (&optional (or number list)
                                       (or symbol string cons integer)
@@ -179,7 +174,6 @@ Used to modify the compiler environment."
                            cons))
     (default-boundp (function (symbol) boolean))
     (default-value (function (symbol) t))
-    (degrees-to-radians (function (number) float))
     (documentation
      (function ((or function symbol subr) &optional t) (or null string)))
     (downcase (function ((or fixnum string)) (or fixnum string)))
@@ -192,7 +186,6 @@ Used to modify the compiler environment."
     (eql (function (t t) boolean))
     (equal (function (t t) boolean))
     (error-message-string (function (list) string))
-    (eventp (function (t) boolean))
     (exp (function (number) float))
     (expt (function (number number) number))
     (fboundp (function (symbol) boolean))
@@ -207,7 +200,6 @@ Used to modify the compiler environment."
     (file-readable-p (function (string) boolean))
     (file-symlink-p (function (string) (or boolean string)))
     (file-writable-p (function (string) boolean))
-    (fixnump (function (t) boolean))
     (float (function (number) float))
     (float-time (function (&optional (or number list)) float))
     (floatp (function (t) boolean))
@@ -230,18 +222,12 @@ Used to modify the compiler environment."
      (function (&optional (or buffer string) (or symbol (integer 0 0)))
                (or null window)))
     (get-file-buffer (function (string) (or null buffer)))
-    (get-largest-window (function (&optional t t t) (or window null)))
-    (get-lru-window (function (&optional t t t) (or window null)))
-    (getenv (function (string &optional frame) (or null string)))
     (gethash (function (t hash-table &optional t) t))
     (hash-table-count (function (hash-table) integer))
     (hash-table-p (function (t) boolean))
     (identity (function (t) t))
-    (ignore (function (&rest t) null))
-    (int-to-string (function (number) string))
     (integer-or-marker-p (function (t) boolean))
     (integerp (function (t) boolean))
-    (interactive-p (function () boolean))
     (intern-soft (function ((or string symbol) &optional (or obarray vector))
                            symbol))
     (invocation-directory (function () string))
@@ -250,8 +236,6 @@ Used to modify the compiler environment."
     (keymap-parent (function (cons) (or cons null)))
     (keymapp (function (t) boolean))
     (keywordp (function (t) boolean))
-    (last (function (list &optional integer) list))
-    (lax-plist-get (function (list t) t))
     (ldexp (function (number integer) float))
     (length (function (t) (integer 0 *)))
     (length< (function (sequence fixnum) boolean))
@@ -265,7 +249,6 @@ Used to modify the compiler environment."
     (local-variable-p (function (symbol &optional buffer) boolean))
     (locale-info (function ((member codeset days months paper)) (or null string)))
     (log (function (number number) float))
-    (log10 (function (number) float))
     (logand (function (&rest (or integer marker)) integer))
     (logb (function (number) integer))
     (logcount (function (integer) integer))
@@ -273,7 +256,6 @@ Used to modify the compiler environment."
     (lognot (function (integer) integer))
     (logxor (function (&rest (or integer marker)) integer))
     ;; (lsh (function ((integer ,most-negative-fixnum *) integer) integer)) ?
-    (lsh (function (integer integer) integer))
     (make-byte-code
      (function ((or fixnum list) string vector integer &optional string t
                 &rest t)
@@ -282,14 +264,12 @@ Used to modify the compiler environment."
     (make-marker (function () marker))
     (make-string (function (integer fixnum &optional t) string))
     (make-symbol (function (string) symbol))
-    (mark (function (&optional t) (or integer null)))
     (mark-marker (function () marker))
     (marker-buffer (function (marker) (or buffer null)))
     (markerp (function (t) boolean))
     (max (function ((or number marker) &rest (or number marker)) number))
     (max-char (function (&optional t) fixnum))
     (member (function (t list) list))
-    (memory-limit (function () integer))
     (memq (function (t list) list))
     (memql (function (t list) list))
     (min (function ((or number marker) &rest (or number marker)) number))
@@ -298,7 +278,6 @@ Used to modify the compiler environment."
     (mod
      (function ((or number marker) (or number marker))
                (or (integer 0 *) (float 0 *))))
-    (mouse-movement-p (function (t) boolean))
     (multibyte-char-to-unibyte (function (fixnum) fixnum))
     (natnump (function (t) boolean))
     (next-window (function (&optional window t t) window))
@@ -310,9 +289,7 @@ Used to modify the compiler environment."
     (number-or-marker-p (function (t) boolean))
     (number-to-string (function (number) string))
     (numberp (function (t) boolean))
-    (one-window-p (function (&optional t t) boolean))
     (overlayp (function (t) boolean))
-    (parse-colon-path (function (string) list))
     (plist-get (function (list t &optional t) t))
     (plist-member (function (list t &optional t) list))
     (point (function () integer))
@@ -325,13 +302,11 @@ Used to modify the compiler environment."
     (processp (function (t) boolean))
     (proper-list-p (function (t) (or fixnum null)))
     (propertize (function (string &rest t) string))
-    (radians-to-degrees (function (number) float))
     (rassoc (function (t list) list))
     (rassq (function (t list) list))
     (read-from-string (function (string &optional integer integer) cons))
     (recent-keys (function (&optional (or cons null)) vector))
     (recursion-depth (function () integer))
-    (regexp-opt (function (list) string))
     (regexp-quote (function (string) string))
     (region-beginning (function () integer))
     (region-end (function () integer))
@@ -387,7 +362,6 @@ Used to modify the compiler environment."
     (upcase (function ((or fixnum string)) (or fixnum string)))
     (user-full-name (function (&optional integer) (or string null)))
     (user-login-name (function (&optional integer) (or string null)))
-    (user-original-login-name (function (&optional integer) (or string null)))
     (user-real-login-name (function () string))
     (user-real-uid (function () integer))
     (user-uid (function () integer))
@@ -400,13 +374,8 @@ Used to modify the compiler environment."
     (window-live-p (function (t) boolean))
     (window-valid-p (function (t) boolean))
     (windowp (function (t) boolean))
-    (zerop (function (number) boolean))
-    ;; Type hints
-    (comp-hint-fixnum (function (t) fixnum))
-    (comp-hint-cons (function (t) cons))
     ;; Non returning functions
     (throw (function (t t) nil))
-    (error (function (string &rest t) nil))
     (signal (function (symbol t) nil)))
   "Alist used for type propagation.")
 
@@ -536,11 +505,11 @@ This function returns a cons cell whose car is the function specifier,
 and cdr is a symbol, either `inferred' or `declared'.  If the symbol is
 `inferred', the type specifier is automatically inferred from the code
 itself by the native compiler; if it is `declared', the type specifier
-comes from `comp-known-type-specifiers' or the function type declaration
+comes from `comp-primitive-type-specifiers' or the function type declaration
 itself."
   (let ((kind 'declared)
         type-spec)
-    (when-let ((res (assoc function comp-known-type-specifiers)))
+    (when-let ((res (assoc function comp-primitive-type-specifiers)))
       ;; Declared primitive
       (setf type-spec (cadr res)))
     (let ((f (and (symbolp function)
index a7d4c71dc26d7eaa70df70b7e3fa514fa0acd351..b37af4c8dc279b1712bbc926690ab62ca16902c4 100644 (file)
@@ -3309,11 +3309,13 @@ Prepare every function for final compilation and drive the C back-end."
 ;; are assumed just to be true. Use with extreme caution...
 
 (defun comp-hint-fixnum (x)
-  (declare (gv-setter (lambda (val) `(setf ,x ,val))))
+  (declare (type (function (t) fixnum))
+           (gv-setter (lambda (val) `(setf ,x ,val))))
   x)
 
 (defun comp-hint-cons (x)
-  (declare (gv-setter (lambda (val) `(setf ,x ,val))))
+  (declare (type (function (t) cons))
+           (gv-setter (lambda (val) `(setf ,x ,val))))
   x)
 
 \f
index 7e6db51b1d5cfb482c30249594d395632a9ea9b9..9edc11ad1324b4073a4d9f4fe42284fe4378d582 100644 (file)
@@ -534,7 +534,8 @@ major mode's decisions about context.")
   "Return the \"far end\" position of the buffer, in direction ARG.
 If ARG is positive, that's the end of the buffer.
 Otherwise, that's the beginning of the buffer."
-  (declare (side-effect-free error-free))
+  (declare (type (function ((or number marker)) integer))
+           (side-effect-free error-free))
   (if (> arg 0) (point-max) (point-min)))
 
 (defun end-of-defun (&optional arg interactive)
index 59c1b7d8e103c6c40a16ee3b45566afc06d50363..076232bc613faf33b877cdcf888d3a8b0396eafc 100644 (file)
@@ -130,7 +130,8 @@ usually more efficient than that of a simplified version:
      (concat (car parens)
              (mapconcat \\='regexp-quote strings \"\\\\|\")
              (cdr parens))))"
-  (declare (pure t) (side-effect-free t))
+  (declare (type (function (list) string))
+           (pure t) (side-effect-free t))
   (save-match-data
     ;; Recurse on the sorted list.
     (let* ((max-lisp-eval-depth 10000)
index e0a8df8476c11cc4f8ad989f7e34d8193ccfcc7f..7d0c7dd0126705518ddc102ed9eb443e3af00f07 100644 (file)
@@ -207,7 +207,8 @@ parameter.
 Otherwise, this function searches `process-environment' for
 VARIABLE.  If it is not found there, then it continues the search
 in the environment list of the selected frame."
-  (declare (side-effect-free t))
+  (declare (type (function (string &optional frame) (or null string)))
+           (side-effect-free t))
   (interactive (list (read-envvar-name "Get environment variable: " t)))
   (let ((value (getenv-internal (if (multibyte-string-p variable)
                                    (encode-coding-string
index 7dec67c5cf05942e5494aee057b5f900309391ba..57f3042e4dac81d1e626f6947997cfed3f298fc4 100644 (file)
@@ -862,6 +862,7 @@ GNU and Unix systems).  Substitute environment variables into the
 resulting list of directory names.  For an empty path element (i.e.,
 a leading or trailing separator, or two adjacent separators), return
 nil (meaning `default-directory') as the associated list element."
+  (declare (type (function (string) list)))
   (when (stringp search-path)
     (let ((spath (substitute-env-vars search-path))
           (double-slash-special-p
index be64f3574e0385661d420036bdb8d657ca26cde9..a459f6ecfd2a5749ec3dea01c8d4d9e8eef52def 100644 (file)
@@ -1762,7 +1762,9 @@ not at the start of a line.
 
 When IGNORE-INVISIBLE-LINES is non-nil, invisible lines are not
 included in the count."
-  (declare (side-effect-free t))
+  (declare (type (function ((or integer marker) (or integer marker) &optional t)
+                           integer))
+           (side-effect-free t))
   (save-excursion
     (save-restriction
       (narrow-to-region start end)
@@ -6882,7 +6884,8 @@ is active, and returns an integer or nil in the usual way.
 
 If you are using this in an editing command, you are most likely making
 a mistake; see the documentation of `set-mark'."
-  (declare (side-effect-free t))
+  (declare (type (function (&optional t) (or integer null)))
+           (side-effect-free t))
   (if (or force (not transient-mark-mode) mark-active mark-even-if-inactive)
       (marker-position (mark-marker))
     (signal 'mark-inactive nil)))
@@ -11163,7 +11166,8 @@ killed."
 
 (defun lax-plist-get (plist prop)
   "Extract a value from a property list, comparing with `equal'."
-  (declare (pure t) (side-effect-free t) (obsolete plist-get "29.1"))
+  (declare (type (function (list t) t))
+           (pure t) (side-effect-free t) (obsolete plist-get "29.1"))
   (plist-get plist prop #'equal))
 
 (defun lax-plist-put (plist prop val)
index 352ecc315ef52fff6ce490a05d2ba87bcb79b74b..92d1e50ab2c8c133b2b623e065ae0a3ab1438479 100644 (file)
@@ -451,7 +451,8 @@ This function accepts any number of arguments in ARGUMENTS.
 Also see `always'."
   ;; Not declared `side-effect-free' because we don't want calls to it
   ;; elided; see `byte-compile-ignore'.
-  (declare (pure t) (completion ignore))
+  (declare (type (function (&rest t) null))
+           (pure t) (completion ignore))
   (interactive)
   nil)
 
@@ -480,7 +481,8 @@ for the sake of consistency.
 
 To alter the look of the displayed error messages, you can use
 the `command-error-function' variable."
-  (declare (advertised-calling-convention (string &rest args) "23.1"))
+  (declare (type (function (string &rest t) nil))
+           (advertised-calling-convention (string &rest args) "23.1"))
   (signal 'error (list (apply #'format-message args))))
 
 (defun user-error (format &rest args)
@@ -545,19 +547,22 @@ 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 (pure t) (side-effect-free t)
+  (declare (type (function (number) boolean))
+           (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))
+  (declare (type (function (t) boolean))
+           (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))
+  (declare (type (function (t) boolean))
+           (side-effect-free error-free))
   (and (integerp object) (not (fixnump object))))
 
 (defun lsh (value count)
@@ -570,7 +575,8 @@ Most uses of this function turn out to be mistakes.  We recommend
 to use `ash' instead, unless COUNT could ever be negative, and
 if, when COUNT is negative, your program really needs the special
 treatment of negative COUNT provided by this function."
-  (declare (compiler-macro
+  (declare (type (function (integer integer) integer))
+           (compiler-macro
             (lambda (form)
               (macroexp-warn-and-return
                (format-message "avoid `lsh'; use `ash' instead")
@@ -748,7 +754,8 @@ treatment of negative COUNT provided by this function."
 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 (pure t) (side-effect-free t))    ; pure up to mutation
+  (declare (type (function (list &optional integer) list))
+           (pure t) (side-effect-free t))    ; pure up to mutation
   (if n
       (and (>= n 0)
            (let ((m (safe-length list)))
@@ -1585,7 +1592,8 @@ 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))
+  (declare (type (function (t) boolean))
+           (pure t) (side-effect-free error-free))
   (or (integerp object)
       (and (if (consp object)
                (setq object (car object))
@@ -1652,7 +1660,8 @@ 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))
+  (declare (type (function (t) boolean))
+           (side-effect-free error-free))
   (eq (car-safe object) 'mouse-movement))
 
 (defun mouse-event-p (object)
@@ -1961,7 +1970,8 @@ 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 (side-effect-free t) (obsolete log "24.4"))
+  (declare (type (function (number) float))
+           (side-effect-free t) (obsolete log "24.4"))
   (log x 10))
 
 (set-advertised-calling-convention
@@ -3245,7 +3255,8 @@ 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))
+  (declare (type (function () integer))
+           (side-effect-free error-free))
   (let ((default-directory temporary-file-directory))
     (or (cdr (assq 'vsize (process-attributes (emacs-pid)))) 0)))
 
@@ -6467,7 +6478,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 (type (function () boolean))
+           (obsolete called-interactively-p "23.2")
            (side-effect-free error-free))
   (called-interactively-p 'interactive))
 
index cdc6f690bab015cefab54833a02e8387693dbd98..639090752be0dbf13cf6e5c8b9c06afeee081dad 100644 (file)
@@ -2515,7 +2515,8 @@ have special meanings:
 
 Any other value of ALL-FRAMES means consider all windows on the
 selected frame and no others."
-  (declare (side-effect-free error-free))
+  (declare (type (function (&optional t t t) (or window null)))
+           (side-effect-free error-free))
   (let ((windows (window-list-1 nil 'nomini all-frames))
         best-window best-time second-best-window second-best-time time)
     (dolist (window windows)
@@ -2594,7 +2595,8 @@ have special meanings:
 
 Any other value of ALL-FRAMES means consider all windows on the
 selected frame and no others."
-  (declare (side-effect-free error-free))
+  (declare (type (function (&optional t t t) (or window null)))
+           (side-effect-free error-free))
   (let ((best-size 0)
        best-window size)
     (dolist (window (window-list-1 nil 'nomini all-frames))
@@ -4089,7 +4091,8 @@ with a special meaning are:
 
 Anything else means consider all windows on the selected frame
 and no others."
-  (declare (side-effect-free error-free))
+  (declare (type (function (&optional t t) boolean))
+           (side-effect-free error-free))
   (let ((base-window (selected-window)))
     (if (and nomini (eq base-window (minibuffer-window)))
        (setq base-window (next-window base-window)))