Subject: Re: bug#79353: 31.0.50; Eager macro expansion errors when building master

From: "J.D. Smith" <[email-masked]>
Date: Sun, 31 Aug 2025 09:19:38 -0400

Gerd Möllmann <[email-masked]> writes:

> I am seeing errors while producing autoloads when building master from
> git clean -xdf.
>
>     INFO     Scraping 1518 files for loaddefs...70% 
>   loaddefs-gen: loading file tramp-adb (for tramp--with-startup)
>   Loading /Users/gerd/emacs/github/master/lisp/net/tramp-adb.el (source)...
>   Warning (emacs): loaddefs-gen: load error
>           (error Eager macro-expansion failure: (error "Eager macro-expansion failure: (void-function cl-subseq)"))
>
> Bisected to (in CC):
>
>   1f4e2e82649bb2a122b1406caf645ea06a933dc6 is the first bad commit
>   commit 1f4e2e82649bb2a122b1406caf645ea06a933dc6
>   Author: JD Smith <[email-masked]>
>   Date:   Sun Aug 10 17:17:47 2025 -0400
>       Adapt tramp to new autoload-macro expand
>
>       Bug #78995.
>
>       * lisp/net/tramp-compat.el (tramp-loaddefs): suppress error on requiring
>       tramp-loaddef.
>       * lisp/net/tramp.el (tramp--with-startup): declare autoload-macro
>       expand, and suppress warnings about this declare form on older versions
>       of Emacs.
>    lisp/net/tramp-compat.el | 2 +-
>    lisp/net/tramp.el        | 7 +++++++
>    2 files changed, 8 insertions(+), 1 deletion(-)

This warning arises from the new dynamic `autoload-macro expand'
capability Stefan M. and I added.  I believe the chain of events is as
follows:

1. tramp-adb declares:

  ;;;###tramp-autoload
  (tramp--with-startup
  ...

2. During initial autoload generation, this macro is unknown.  So the
file tramp-adb.el is /loaded/, to give it a chance to define the macro.

3. The macro `tramp--with-startup' is indeed defined in tramp.el, which
tramp-adb requires.  So far so good.  But during the loading of
tramp.el, some other package it loads uses `cl-subseq' at the top level
without first requiring cl-extra.

5. Why has this not been an issue before?  The macro `cl-subseq' is
/itself/ an autoload in cl-extra.el.  Since the CL-specific loadefs file
`cl-loaddefs.el' does not yet exist (remember this is during autoload
generation), this causes the (handled) warning you see.

*Question*:

In the lisp/net/tramp-loaddefs.el file which was generated during this
build, what do you see under:

  ;;; Generated autoloads from tramp-adb.el

Can you try a build again with `make bootstrap' and see whether the
warning disappears and if that section of lisp/net/tramp-loaddefs.el
changes?  My guess is this is a harmless warning.

On a related issue, we still need to revert Po's commit e9800cabffa
which restored one of the hard-coded macro lists the autoload-macro
expand feature intentionally removed, possibly in an attempt to fix a
similar issue with recentf. Po, reminder to check that again with `make
bootstrap'.

I would like to use this report to test various flavors of "from
scratch" builds and see if there are any approaches to mitigate these
warnings (that's why I'm reporting them!).  Loading during autoload
generation should be rare, but is essential for external package authors
to request macro expansion during package install (think: modes which
provide custom convenience macros to wrap `define-minor-mode').