Subject: Re: [bug#67260] [PATCH emacs-team v9*] Test for AOT native-comp

From: Suhail <[email-masked]>
Date: Wed, 14 Feb 2024 08:41:30 +0000

So I wrote some code to make it easier to report on the state of
native-comp for some of the packages previously mentioned (the *.eln
files for these packages reside under the "preloaded" directory in a
non-Guix distribution).  I'm including below both the contents of the
script as well as the results.

First the results.  Assuming that the file
test-native-comp-p--preloaded.el exists, evaluating the below:

#+begin_src sh :results replace
  emacs -Q --batch \
        -l path/to/test-native-comp-p--preloaded.el \
        --eval "(princ (report/compilation-status/run))"
#+end_src

With a non-Guix Emacs results in:

#+RESULTS:
: [97/97] passed. Success!

Whereas with the latest patch-series it results in 41 failing cases:

#+RESULTS:
#+begin_example
[56/97] passed.  41 failing cases below:

((backquote-process . byte-compiled)
 (byte-run-strip-symbol-positions . byte-compiled)
 (cconv-convert . byte-compiled)
 (use-default-char-width-table . byte-compiled)
 (cl-generic-p . byte-compiled)
 (cl-struct-define . byte-compiled)
 (x-setup-function-keys . byte-compiled)
 (debug-early . byte-compiled)
 (easy-menu-item-present-p . byte-compiled)
 (eldoc-mode . byte-compiled)
 (elisp-mode-syntax-propertize . byte-compiled)
 (fill-region . byte-compiled)
 (fontset-plain-name . byte-compiled)
 (indian-compose-regexp . byte-compiled)
 (msdos-setup-keyboard . byte-compiled)
 (iso-transl-set-language . byte-compiled)
 (forward-sexp . byte-compiled)
 (lisp-string-in-doc-position-p . byte-compiled)
 (macroexp-compiling-p . byte-compiled)
 (map-y-or-n-p . byte-compiled)
 (egyptian-shape-grouping . byte-compiled)
 (convert-define-charset-argument . byte-compiled)
 (coding-system-change-eol-conversion . byte-compiled)
 (store-substring . byte-compiled)
 (advice-function-mapc . byte-compiled)
 (oclosure-type . byte-compiled)
 (forward-page . byte-compiled)
 (sentence-end . byte-compiled)
 (prog-context-menu . byte-compiled)
 (regexp-opt . byte-compiled)
 (read-multiple-choice . byte-compiled)
 (seq-first . byte-compiled)
 (hack-read-symbol-shorthands . byte-compiled)
 (syntax-propertize-multiline . byte-compiled)
 (tabulated-list-put-tag . byte-compiled)
 (text-mode . byte-compiled)
 (timer-activate . byte-compiled)
 (tty-color-desc . byte-compiled)
 (ucs-normalize-hfs-nfd-comp-p . byte-compiled)
 (vc-mode . byte-compiled)
 (x-handle-no-bitmap-icon . byte-compiled))
#+end_example

The content of test-native-comp-p--preloaded.el are as follows:

#+begin_src elisp :eval never
  (require 'help-fns)
  (defun report/compilation-status (fun &optional feature)
    "Report on the compilation status of function FUN.
  Optionally load FEATURE before reporting on compilation status."
    (when feature
      (require feature))
    (let ((descstr (substring-no-properties
                    (with-output-to-string
                      (help-fns-function-description-header fun)))))
      (cons fun
            (cond
             ((string-search " native-compiled" descstr) 'native-compiled)
             ((string-search " byte-compiled" descstr) 'byte-compiled)
             (t descstr)))))

  ;; [[/usr/share/emacs/29.2/lisp]]
  (defvar report/compilation-status/cases/preloaded nil
    "Functions that ought to be natively-compiled.")
  (setq report/compilation-status/cases/preloaded
        '((abbrev-mode)
          (backquote-process)
          (mode-line-widen)
          (buffer-menu)
          ;; burmese
          (button-mode)
          (byte-run-strip-symbol-positions)
          (case-table-get-table)
          (cconv-convert)
          ;; cham
          (use-default-char-width-table)
          ;; chinese
          (cl-generic-p)
          (cl-struct-define)
          (x-setup-function-keys)
          (encode-composition-rule)
          ;; cp51932
          (custom-declare-face)
          (minibuffer-prompt-properties--setter) ;; cus-start.el
          (custom-add-choice)
          ;; cyrillic
          ;; czech
          (debug-early)
          (display-table-slot disp-table) ;; disp-table.eln exists
          (dnd-open-file)
          (dos-mode25 dos-fns) ;; dos-fns.eln exists
          ;; dos-vars
          (find-file-text dos-w32) ;; dos-w32.eln exists
          (dynamic-setting-handle-config-changed-event)
          (easy-menu-item-present-p)
          ;; ediff-hook
          (eldoc-mode)
          (electric-indent-mode)
          (elisp-mode-syntax-propertize)
          ;; english
          (getenv)
          (epa-file-find-file-hook)
          ;; ethiopic
          ;; eucjp-ms
          ;; european
          (face-list)
          (find-file-noselect)
          (fill-region)
          ;; float-sup
          (font-lock-change-mode)
          (font-lock-add-keywords)
          (fontset-plain-name)
          (format-read)
          (frame-edges)
          (fringe-mode)
          ;; georgian
          ;; greek
          ;; haiku-win
          ;; hebrew
          (help-quick)
          (image-type)
          (indent-region)
          (indian-compose-regexp)
          ;; indonesian
          (msdos-setup-keyboard term/internal) ;; internal.eln exists
          (isearch-abort)
          (iso-transl-set-language)
          ;; japanese
          (jit-lock-mode)
          (jka-compr-build-file-regexp)
          (keymap-global-set)
          ;; khmer
          ;; korean
          ;; lao
          (forward-sexp)
          (lisp-string-in-doc-position-p)
          (ls-lisp-set-options ls-lisp) ;; ls-lisp.eln exists
          (macroexp-compiling-p)
          (map-y-or-n-p)
          (menu-find-file-existing)
          (completion-boundaries)
          (egyptian-shape-grouping)
          (mouse-double-click-time)
          (convert-define-charset-argument)
          (coding-system-change-eol-conversion)
          ;; mule-conf.eln
          (store-substring mule-util) ;; mule-util.eln exists
          (mouse-wheel-change-button)
          (advice-function-mapc)
          (comment-string-strip)
          ;; (ns-handle-nxopen term/ns-win)
          (obarray-make)
          (oclosure-type)
          (forward-page)
          (sentence-end)
          (show-paren-function)
          ;; (msdos-face-setup term/pc-win)
          (pgtk-dnd-init-frame pgtk-dnd) ;; pgtk-dnd.eln exists
          ;; (pgtk-drag-n-drop term/pgtk-win)
          ;; philippine
          (prog-context-menu)
          (regexp-opt)
          (get-register)
          (query-replace-descr)
          (rfn-eshadow-setup-minibuffer)
          (read-multiple-choice)
          ;; romanian
          (scroll-bar-scale)
          (gui-select-text)
          (seq-first)
          (hack-read-symbol-shorthands)
          (next-error-find-buffer)
          ;; sinhala
          ;; slovak
          (exit-splash-screen)
          (buffer-local-boundp)
          (syntax-propertize-multiline)
          (tab-bar-mode)
          (tabulated-list-put-tag)
          ;; tai-viet
          (text-mode)
          ;; thai
          ;; tibetan
          (timer-activate)
          (tool-bar-mode)
          (tooltip-mode)
          (tty-color-desc)
          (ucs-normalize-hfs-nfd-comp-p ucs-normalize) ;; ucs-normalize.eln exists
          (uniquify-item-p)
          ;; utf-8-lang.eln
          (vc-mode)
          (emacs-version)
          ;; vietnamese
          ;; (w32-shell-name)
          ;; w32-vars.eln
          ;; (w32-handle-dropped-file 'term/w32-win)
          (define-widget)
          (window-right)
          (x-dnd-init-frame)
          (x-handle-no-bitmap-icon)))

  (defun report/compilation-status/run ()
    "Run all cases and report those that aren't native-compiled."
    (let* ((results (mapcar (lambda (args) (apply #'report/compilation-status args))
                            report/compilation-status/cases/preloaded))
           (failing (seq-filter (lambda (x) (not (eq (cdr x) 'native-compiled)))
                                results))
           (numtotal (seq-length results))
           (numfailing (seq-length failing))
           (numpassing (- numtotal numfailing)))
      (concat (format "[%s/%s] passed."
                      numpassing numtotal)
              (if failing
                  (concat (format "  %s failing cases below:\n\n" numfailing)
                          (pp-to-string failing))
                " Success!"))))
#+end_src

Hope this helps!

-- 
Suhail