GNU bug report logs - #60081
29.0.60; compiler-macros in keymap.el accept wrong number of arguments

Previous Next

Package: emacs;

Reported by: Zehao Hu <huzehao1998 <at> gmail.com>

Date: Thu, 15 Dec 2022 07:43:01 UTC

Severity: normal

Found in version 29.0.60

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: Zehao Hu <huzehao1998 <at> gmail.com>
To: 60081 <at> debbugs.gnu.org
Subject: bug#60081: 29.0.60; compiler-macros in keymap.el accept wrong number of arguments
Date: Thu, 15 Dec 2022 16:54:26 +0800
[Message part 1 (text/plain, inline)]
Hi all,

I'm sure that this is the same bug as bug #50043, #58148, #58396

In bug #58356,
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>Lars Ingebrigtsen [2022-10-11 20:27:42] wrote:
>> Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>>> Because that's the sort of error you can get if you try to macro-expand
>>> code that's syntactically invalid.  E.g. try to compile a file with
>>>
>>>     (add-to-list x)
>>>
>>> and you should see a similar error.  For `elisp--local-variables`,
>>> syntactically invalid code is the normal case (more or less) both
>>> because it's used when we're in the middle of writing the code, and also
>>> because of how it works (it takes the code from beginning-of-defun up
>>> to point and throws away whatever follows, just adding enough closing
>>> parens that the resutling string is `read`able).
>>
>> I see.
>>
>> Shouldn't this function then be suppressing all errors while it's doing
>> this exploratory macro-expansion stuff?
>
>Yes (plus silence the messages plus avoid compiler macros).

Here is a simple workaround:

(require 'loadhist)

(defun cmacro-ignore-elisp-witness (oldfn form &rest args)
  "Add this advicing function around compiler macros to ignore
`elisp--witness--lisp'"
  (unless (eq 'elisp--witness--lisp (car args))
    (apply oldfn form args)))

(defun cmacro-add-advice (file-or-entry)
  "Add `cmacro-ignore-elisp-witness' to compiler macros in FILE or in ENTRY
from `load-history'"
  (let ((entry (if (stringp file-or-entry)
                   (file-loadhist-lookup file-or-entry)
                 file-or-entry)))
    (dolist (cell (cdr entry))
      (when-let*
          (((consp cell))
           ((eq 'defun (car cell)))
           (symbol
            (cdr cell))
           ((symbolp symbol))
           (cmacro
            (get symbol 'compiler-macro))
           ((not (advice-member-p #'cmacro-ignore-elisp-witness symbol))))
        (advice-add cmacro :around #'cmacro-ignore-elisp-witness)))))

;; Advicing existing compiler macros
(dolist (entry load-history)
  (cmacro-add-advice entry))

;; And the ones in the future
(add-hook 'after-load-functions #'cmacro-add-advice)
(dolist (entry load-history)
  (cmacro-add-advice entry))

(add-hook 'after-load-functions #'cmacro-add-advice)

Or maybe edit `byte-run--set-compiler-macro', to change the `*--anon-cmacro'
and to advice the `compiler-function'.
[Message part 2 (text/html, inline)]

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

Previous Next


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