1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-09 07:40:39 -08:00

bytecomp.el: Rework the message when the macro is not recognized

The "Macro %s unrecognized, won't work in file" message
happened only for macros defined to `nil`, and the code handling
"unrecognized" code was split with the function part is
`byte-compile-file-form-defmumble` and the macro part in
`byte-compile-file-form-defalias`, so straighten it out
and simplify a bit.

* lisp/emacs-lisp/bytecomp.el (byte-compile-file-form-defmumble):
Don't modify `byte-compile-*-environment` here.
(byte-compile-file-form-defalias): Do it here instead.
Use `macroexp-quote`.  Merge the two "unrecognized macro" warnings.
This commit is contained in:
Stefan Monnier 2025-07-26 18:35:00 -04:00
parent 547525176f
commit f6d314dfe5

View file

@ -1104,7 +1104,7 @@ CONST2 may be evaluated multiple times."
hash-table)
(dolist (elt alist)
(puthash (car elt) (cdr elt) hash-table))))
(let ((bytecode (apply 'unibyte-string (nreverse bytes))))
(let ((bytecode (apply #'unibyte-string (nreverse bytes))))
(when byte-native-compiling
;; Spill LAP for the native compiler here.
(puthash bytecode (make-byte-to-native-lambda :lap lap)
@ -2858,13 +2858,8 @@ not to take responsibility for the actual compilation of the code."
(if (not (listp body))
;; The precise definition requires evaluation to find out, so it
;; will only be known at runtime.
;; For a macro, that means we can't use that macro in the same file.
(progn
(unless macro
(push (cons bare-name (if (listp arglist) `(declared ,arglist) t))
byte-compile-function-environment))
;; Tell the caller that we didn't compile it yet.
nil)
;; Tell the caller that we didn't compile it yet.
nil
(let ((code (byte-compile-lambda `(lambda ,arglist . ,body))))
(if this-one
@ -5168,7 +5163,8 @@ binding slots have been popped."
(pcase-let*
;; `macro' is non-nil if it defines a macro.
;; `fun' is the function part of `arg' (defaults to `arg').
(((or (and (or `(cons 'macro ,fun) `'(macro . ,(app (list 'quote) fun)))
(((or (and (or `(cons 'macro ,fun)
`'(macro . ,(app macroexp-quote fun)))
(let macro t))
(and (let fun arg) (let macro nil)))
arg)
@ -5184,14 +5180,13 @@ binding slots have been popped."
lam))
(unless (byte-compile-file-form-defmumble
name macro arglist body rest)
(when macro
(if (null fun)
(byte-compile-warn-x
name "Macro %s unrecognized, won't work in file" name)
(byte-compile-warn-x
name "Macro %s partly recognized, trying our luck" name)
(push (cons name (eval fun lexical-binding))
byte-compile-macro-environment)))
(if (not macro)
(push (cons name (if (listp arglist) `(declared ,arglist) t))
byte-compile-function-environment)
(byte-compile-warn-x
name "Definition of macro %s not fully recognized" name)
(push (cons name (eval fun lexical-binding))
byte-compile-macro-environment))
(byte-compile-keep-pending form))))
;; We used to just do: (byte-compile-normal-call form)