Subject: 29.1; Byte compiler interaction with cl-lib function objects, removes symbol-function

From: Eric Marsden <[email-masked]>
Date: Wed, 2 Aug 2023 12:28:24 +0200

The byte-compiler seems to erroneously remove the symbol-function for 
equal in the
code show below.

--- file "perturb.el" ---
(require 'cl-lib)

(defun foo ()
   (cl-flet ((bar (v) (list v)))
     (make-hash-table :test #'equal)))
---

--- file "use.el" ---
(require 'cl-lib)
(require 'ert)

(defun test ()
   (cl-flet ((foo (x) (list x)))
     (should (equal nil 42))))
---

% emacs -Q --batch --eval '(byte-compile-file "perturb.el")' -l use.el 
-f test
Error: invalid-function (#<symbol equal at 95>)
   mapbacktrace(#f(compiled-function (evald func args flags) #<bytecode 
-0x84e95e6e2517821>))
   debug-early-backtrace()
   debug-early(error (invalid-function #<symbol equal at 95>))
   #<symbol equal at 95>(nil 42)
   apply(#<symbol equal at 95> (nil 42))
   (setq value-2 (apply fn-0 args-1))
   (unwind-protect (setq value-2 (apply fn-0 args-1)) (setq 
form-description-4 (nconc (list '(should (equal nil 42))) (list :form 
(cons fn-0 args-1)) (if (eql value-2 'ert-form-evaluation-aborted-3) nil 
(list :value value-2)) (if (eql value-2 'ert-form-evaluation-aborted-3) 
nil (let* ((-explainer- (and t (ert--get-explainer 'equal)))) (if 
-explainer- (list :explanation (apply -explainer- args-1)) nil))))) 
(ert--signal-should-execution form-description-4))
   (if (unwind-protect (setq value-2 (apply fn-0 args-1)) (setq 
form-description-4 (nconc (list '(should (equal nil 42))) (list :form 
(cons fn-0 args-1)) (if (eql value-2 'ert-form-evaluation-aborted-3) nil 
(list :value value-2)) (if (eql value-2 'ert-form-evaluation-aborted-3) 
nil (let* ((-explainer- (and t (ert--get-explainer 'equal)))) (if 
-explainer- (list :explanation (apply -explainer- args-1)) nil))))) 
(ert--signal-should-execution form-description-4)) nil (ert-fail 
form-description-4))
   (let (form-description-4) (if (unwind-protect (setq value-2 (apply 
fn-0 args-1)) (setq form-description-4 (nconc (list '(should (equal nil 
42))) (list :form (cons fn-0 args-1)) (if (eql value-2 
'ert-form-evaluation-aborted-3) nil (list :value value-2)) (if (eql 
value-2 'ert-form-evaluation-aborted-3) nil (let* ((-explainer- (and t 
(ert--get-explainer 'equal)))) (if -explainer- (list :explanation (apply 
-explainer- args-1)) nil))))) (ert--signal-should-execution 
form-description-4)) nil (ert-fail form-description-4)))
   (let ((value-2 'ert-form-evaluation-aborted-3)) (let 
(form-description-4) (if (unwind-protect (setq value-2 (apply fn-0 
args-1)) (setq form-description-4 (nconc (list '(should (equal nil 42))) 
(list :form (cons fn-0 args-1)) (if (eql value-2 
'ert-form-evaluation-aborted-3) nil (list :value value-2)) (if (eql 
value-2 'ert-form-evaluation-aborted-3) nil (let* ((-explainer- (and t 
(ert--get-explainer 'equal)))) (if -explainer- (list :explanation (apply 
-explainer- args-1)) nil))))) (ert--signal-should-execution 
form-description-4)) nil (ert-fail form-description-4))) value-2)
   (let* ((fn-0 #'#<symbol equal at 95>) (args-1 (condition-case err 
(let ((signal-hook-function #'ert--should-signal-hook)) (list nil 42)) 
(error (progn (setq fn-0 #'signal) (list (car err) (cdr err))))))) (let 
((value-2 'ert-form-evaluation-aborted-3)) (let (form-description-4) (if 
(unwind-protect (setq value-2 (apply fn-0 args-1)) (setq 
form-description-4 (nconc (list '(should (equal nil 42))) (list :form 
(cons fn-0 args-1)) (if (eql value-2 'ert-form-evaluation-aborted-3) nil 
(list :value value-2)) (if (eql value-2 'ert-form-evaluation-aborted-3) 
nil (let* ((-explainer- (and t (ert--get-explainer 'equal)))) (if 
-explainer- (list :explanation (apply -explainer- args-1)) nil))))) 
(ert--signal-should-execution form-description-4)) nil (ert-fail 
form-description-4))) value-2))
   (progn (let* ((fn-0 #'#<symbol equal at 95>) (args-1 (condition-case 
err (let ((signal-hook-function #'ert--should-signal-hook)) (list nil 
42)) (error (progn (setq fn-0 #'signal) (list (car err) (cdr err))))))) 
(let ((value-2 'ert-form-evaluation-aborted-3)) (let 
(form-description-4) (if (unwind-protect (setq value-2 (apply fn-0 
args-1)) (setq form-description-4 (nconc (list '(should (equal nil 42))) 
(list :form (cons fn-0 args-1)) (if (eql value-2 
'ert-form-evaluation-aborted-3) nil (list :value value-2)) (if (eql 
value-2 'ert-form-evaluation-aborted-3) nil (let* ((-explainer- (and t 
(ert--get-explainer 'equal)))) (if -explainer- (list :explanation (apply 
-explainer- args-1)) nil))))) (ert--signal-should-execution 
form-description-4)) nil (ert-fail form-description-4))) value-2)))
   (let* ((--cl-foo-- #'(lambda (x) (list x)))) (progn (let* ((fn-0 
#'#<symbol equal at 95>) (args-1 (condition-case err (let 
((signal-hook-function #'ert--should-signal-hook)) (list nil 42)) (error 
(progn (setq fn-0 #'signal) (list (car err) (cdr err))))))) (let 
((value-2 'ert-form-evaluation-aborted-3)) (let (form-description-4) (if 
(unwind-protect (setq value-2 (apply fn-0 args-1)) (setq 
form-description-4 (nconc (list '(should (equal nil 42))) (list :form 
(cons fn-0 args-1)) (if (eql value-2 'ert-form-evaluation-aborted-3) nil 
(list :value value-2)) (if (eql value-2 'ert-form-evaluation-aborted-3) 
nil (let* ((-explainer- (and t (ert--get-explainer 'equal)))) (if 
-explainer- (list :explanation (apply -explainer- args-1)) nil))))) 
(ert--signal-should-execution form-description-4)) nil (ert-fail 
form-description-4))) value-2))))
   test()
   command-line-1(("--eval" "(byte-compile-file \"perturb.el\")" "-l" 
"use.el" "-f" "test"))
   command-line()
   normal-top-level()
Invalid function: #<symbol equal at 95>

The byte-compiler seems to have erroneously removed the symbol-function 
for equal.

In GNU Emacs 29.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.38,
  cairo version 1.16.0) of 2023-08-01, modified by Debian built on
  x86-ubc-02
Windowing system distributor 'The X.Org Foundation', version 11.0.12201009
System Description: Debian GNU/Linux trixie/sid

Configured using:
  'configure --build x86_64-linux-gnu --prefix=/usr
  --sharedstatedir=/var/lib --libexecdir=/usr/libexec
  --localstatedir=/var/lib --infodir=/usr/share/info
  --mandir=/usr/share/man --with-libsystemd --with-pop=yes
  --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/29.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/29.1/site-lisp:/usr/share/emacs/site-lisp
  --with-sound=alsa --without-gconf --with-mailutils
  --with-native-compilation --build x86_64-linux-gnu --prefix=/usr
  --sharedstatedir=/var/lib --libexecdir=/usr/libexec
  --localstatedir=/var/lib --infodir=/usr/share/info
  --mandir=/usr/share/man --with-libsystemd --with-pop=yes
  --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/29.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/29.1/site-lisp:/usr/share/emacs/site-lisp
  --with-sound=alsa --without-gconf --with-mailutils
  --with-native-compilation --with-cairo --with-x=yes
  --with-x-toolkit=gtk3 --with-toolkit-scroll-bars 'CFLAGS=-g -O2
  -ffile-prefix-map=/build/reproducible-path/emacs-29.1+1=.
  -fstack-protector-strong -Wformat -Werror=format-security -Wall'
  'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' LDFLAGS=-Wl,-z,relro'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES
NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3
THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINPUT2
XPM GTK3 ZLIB