]> git.eshelyaron.com Git - emacs.git/commitdiff
(primitive-function): New type
authorStefan Monnier <monnier@iro.umontreal.ca>
Sun, 17 Mar 2024 21:29:02 +0000 (17:29 -0400)
committerEshel Yaron <me@eshelyaron.com>
Mon, 18 Mar 2024 15:45:50 +0000 (16:45 +0100)
The type hierarchy and `cl-type-of` code assumed that `subr-primitive`
only applies to functions, but since it also accepts special-forms it makes
it an unsuitable choice since it can't be a subtype of `compiled-function`.
So, use a new type `primitive-function` instead.

* lisp/subr.el (subr-primitive-p): Fix docstring (bug#69832).
(primitive-function-p): New function.

* lisp/emacs-lisp/cl-preloaded.el (primitive-function): Rename
from `subr-primitive` since `subr-primitive-p` means something else.

* src/data.c (Fcl_type_of): Return `primitive-function` instead
of `subr-primitive` for C functions.
(syms_of_data): Adjust accordingly.

* test/src/data-tests.el (data-tests--cl-type-of): Remove workaround.

(cherry picked from commit e624bc62752ceb2e60940c5fd9cb6e70611df71c)

etc/NEWS
lisp/emacs-lisp/cl-preloaded.el
lisp/subr.el
src/data.c
test/src/data-tests.el

index 7d90e0aca4edbe9618f1ad4157ecdcdc6f700f34..58c348679a199e0dff5440a3dfd809b890445753 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1790,6 +1790,10 @@ This function is like 'type-of' except that it sometimes returns
 a more precise type.  For example, for nil and t it returns 'null'
 and 'boolean' respectively, instead of just 'symbol'.
 
+** New function `primitive-function-p`.
+This is like `subr-primitive-p` except that it returns t only if the
+argument is a function rather than a special-form.
+
 ** Built-in types have now corresponding classes.
 At the Lisp level, this means that things like (cl-find-class 'integer)
 will now return a class object, and at the UI level it means that
index 3e89afea45238e710fe6d79fd254f3d0e066bd68..d11c97a3e3adb1b2f5903bd0db5ff5389e61a08c 100644 (file)
@@ -436,7 +436,7 @@ For this build of Emacs it's %dbit."
   "Type of the core syntactic elements of the Emacs Lisp language.")
 (cl--define-built-in-type subr-native-elisp (subr compiled-function)
   "Type of functions that have been compiled by the native compiler.")
-(cl--define-built-in-type subr-primitive (subr compiled-function)
+(cl--define-built-in-type primitive-function (subr compiled-function)
   "Type of functions hand written in C.")
 
 (unless (cl--class-parents (cl--find-class 'cl-structure-object))
index dd149210fd0e84e3d6660c1581ee0d3ec6933645..45bd924c1bafadb2b8ac52a3c7a75c46aa10048c 100644 (file)
@@ -312,11 +312,20 @@ value of last one, or nil if there are none."
                               cond '(empty-body unless) t)))
 
 (defsubst subr-primitive-p (object)
-  "Return t if OBJECT is a built-in primitive function."
+  "Return t if OBJECT is a built-in primitive written in C.
+Such objects can be functions or special forms."
   (declare (side-effect-free error-free))
   (and (subrp object)
        (not (subr-native-elisp-p object))))
 
+(defsubst primitive-function-p (object)
+  "Return t if OBJECT is a built-in primitive function.
+This excludes special forms, since they are not functions."
+  (declare (side-effect-free error-free))
+  (and (subrp object)
+       (not (or (subr-native-elisp-p object)
+                (eq (cdr (subr-arity object)) 'unevalled)))))
+
 (defsubst xor (cond1 cond2)
   "Return the boolean exclusive-or of COND1 and COND2.
 If only one of the arguments is non-nil, return it; otherwise
index 5d6b6e0ba9d785e5881a2c424ca5bdd65d64378a..69b990bed7600c78ca2df07e762f7c391499b7a0 100644 (file)
@@ -248,7 +248,7 @@ a fixed set of types.  */)
         case PVEC_SUBR:
           return XSUBR (object)->max_args == UNEVALLED ? Qspecial_form
                  : SUBR_NATIVE_COMPILEDP (object) ? Qsubr_native_elisp
-                 : Qsubr_primitive;
+                 : Qprimitive_function;
         case PVEC_COMPILED: return Qcompiled_function;
         case PVEC_BUFFER: return Qbuffer;
         case PVEC_CHAR_TABLE: return Qchar_table;
@@ -4245,7 +4245,7 @@ syms_of_data (void)
   DEFSYM (Qwindow, "window");
   DEFSYM (Qsubr, "subr");
   DEFSYM (Qspecial_form, "special-form");
-  DEFSYM (Qsubr_primitive, "subr-primitive");
+  DEFSYM (Qprimitive_function, "primitive-function");
   DEFSYM (Qsubr_native_elisp, "subr-native-elisp");
   DEFSYM (Qcompiled_function, "compiled-function");
   DEFSYM (Qbuffer, "buffer");
index 9d76c58224d3b443aa691a97d9c8de0ef85a5246..daa49e671b5f581a70898f95d48e124834bc3182 100644 (file)
@@ -869,9 +869,7 @@ comparing the subr with a much slower Lisp implementation."
                              tree-sitter-node tree-sitter-parser
                              ;; `functionp' also matches things of type
                              ;; `symbol' and `cons'.
-                             ;; FIXME: `subr-primitive-p' also matches
-                             ;; special-forms.
-                             function subr-primitive))
+                             function))
               (should-not (cl-typep val subtype)))))))))