Subject: bug#69290: declare-function doesn't work when combined with --eval and -batch

From: Konstantin Kharlamov <[email-masked]>
Date: Tue, 20 Feb 2024 23:31:53 +0300

On Tue, 2024-02-20 at 22:20 +0200, Eli Zaretskii wrote:
> > From: Konstantin Kharlamov <[email-masked]>
> > Cc: [email-masked]
> > Date: Tue, 20 Feb 2024 23:13:27 +0300
> > 
> > > Does --eval '(declare-function hello nil)' tell anything to the
> > > byte-compiler?
> > 
> > Well, I can guess by the way you're asking that the answer is "no",
> > but
> > I have no idea why so. It should.
> 
> How can it?  The declare-function form is evaluated by the startup
> code, and only after that the byte-compiler is invoked to compile
> test.el.  At least this is my analysis of what happens here.
> 
> > It is the same as if you pop up Emacs, evaluate a (defun hello())
> > and then call `byte-compile-file` over the `test.el`. There won't
> > be
> > a warning, despite that `(defun hello ())` was never byte-compiled
> > (AFAIK Emacs does note byte-compile evaluated code).
> 
> For the declare-function form to take effect, the byte-compiler needs
> to evaluate the form.  By contrast, defun is evaluated by the Lisp
> interpreter and the result is stored in the global state.

Oh, thank you for explanation, I see. It's doesn't seem to be obvious
to a bystander, because from the side it seems like in Emacs byte-
compiler and interpreter should work in a tandem, as in the example
with evaluating (defun hello()). In Emacs context the doc-string that
says `Tell the byte-compiler that function FN is defined` would read to
me as "modify global state, which later will be read by byte-compiler
to deem FN as defined". IOW, to me as a bystander the documentation
string does not explain the difference, which is why we just had this
somewhat long discussion before I understood why `declare-function`
works this way.

I guess the bug can be closed, sorry for the noise.