GNU bug report logs - #69832
30.0.50; Should `subr-primitive-p` apply to special-forms?

Previous Next

Package: emacs;

Reported by: Stefan Monnier <monnier <at> iro.umontreal.ca>

Date: Sat, 16 Mar 2024 19:32:01 UTC

Severity: normal

Found in version 30.0.50

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#69832: closed (30.0.50; Should `subr-primitive-p` apply to
 special-forms?)
Date: Sun, 17 Mar 2024 21:05:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Sun, 17 Mar 2024 17:03:59 -0400
with message-id <jwv1q88efmp.fsf-monnier+emacs <at> gnu.org>
and subject line Re: bug#69832: 30.0.50; Should `subr-primitive-p` apply to special-forms?
has caused the debbugs.gnu.org bug report #69832,
regarding 30.0.50; Should `subr-primitive-p` apply to special-forms?
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
69832: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=69832
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: bug-gnu-emacs <at> gnu.org
Subject: 30.0.50; Should `subr-primitive-p` apply to special-forms?
Date: Sat, 16 Mar 2024 15:30:01 -0400
Package: Emacs
Version: 30.0.50


Currently (subr-primitive-p (symbol-function 'if)) returns t.
Its docstring disagrees:

    Return t if OBJECT is a built-in primitive function.

because `if` is indeed a "built-in primitive" but not a "function" (you
can't `funcall` it and it is rejected by `functionp`: it's a special
form instead).

For ELisp's type hierarchy/DAG we need a type for "a built-in primitive
which is also a function".  Originally, based on the docstring,
I thought I could use `subr-primitive`.
But it turns out that the code doesn't quite match the docstring.

I can see two ways to fix that:

- Introduce a new type, says `subr-function(-p)` which returns non-nil
  if and only if the argument is a built-in primitive *and* a function.

- Change the implementation of `subr-primitive-p` to match its docstring.

The patch below does the second (including changing the only place
I found that wants the current semantics.

Comments?  Objections?


        Stefan


diff --git a/lisp/emacs-lisp/find-func.el b/lisp/emacs-lisp/find-func.el
index 411602ef166..3458ace1c08 100644
--- a/lisp/emacs-lisp/find-func.el
+++ b/lisp/emacs-lisp/find-func.el
@@ -552,7 +552,7 @@ find-function-library
     (cons function
           (cond
            ((autoloadp def) (nth 1 def))
-           ((subr-primitive-p def)
+           ((or (subr-primitive-p def) (special-form-p def))
             (if lisp-only
                 (error "%s is a built-in function" function))
             (help-C-file-name def 'subr))
diff --git a/lisp/subr.el b/lisp/subr.el
index 38a3f6edb34..f403369f534 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -315,7 +315,8 @@ subr-primitive-p
   "Return t if OBJECT is a built-in primitive function."
   (declare (side-effect-free error-free))
   (and (subrp object)
-       (not (subr-native-elisp-p object))))
+       (not (or (subr-native-elisp-p object)
+                (special-form-p object)))))
 
 (defsubst xor (cond1 cond2)
   "Return the boolean exclusive-or of COND1 and COND2.



[Message part 3 (message/rfc822, inline)]
From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 69832-done <at> debbugs.gnu.org
Subject: Re: bug#69832: 30.0.50; Should `subr-primitive-p` apply to
 special-forms?
Date: Sun, 17 Mar 2024 17:03:59 -0400
> Well, you asked for opinions, and here you have mine.  I stand by it.

Fair enough.  I'll go with a new `primitive-function-p`, then.
I'll include it in the `cl-type-of` patch(es).


        Stefan



This bug report was last modified 1 year and 64 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.