emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Do we need C's extern in Emacs Lisp?


From: Alan Mackenzie
Subject: Re: Do we need C's extern in Emacs Lisp?
Date: Thu, 31 Mar 2022 20:59:36 +0000

Hello, Stefan.

On Tue, Mar 29, 2022 at 17:09:10 -0400, Stefan Monnier wrote:
> > For example, if

> >     (defvar foo)

> > is in a Lisp file, then subsequent use of foo will generate an unknown
> > variable warning.

> That's not my experience.  Do you have a recipe?

This happened in an attempt to fix bug #21466, a bug you opened in 2015
proposing to replace cc-bytecomp-defun and cc-bytecomp-defvar by
(declare-function foo nil) and (defvar foo).

I was wrong about the "subsequent use ... generate an unknown variable
warning.".  Sorry.  The problem happened during a more unusual
compilation situation best explained by the following comment from
cc-fonts.el:

    ;; Need to declare these local symbols during compilation since
    ;; they're referenced from lambdas in `byte-compile' calls that are
    ;; executed at compile time.  They don't need to have the proper
    ;; definitions, though, since the generated functions aren't called
    ;; during compilation.

The "need to declare" means "need to give the value/function cell of the
symbol a binding", because the byte compiler seems to use boundp and
fboundp to check whether to emit "not known" warnings.

> > For example(2), if in the Lisp file there is

> >     (declare-function foo nil)

> > , this generates a warning when the function foo is later defined.

> I haven't verified that it's indeed the case, but it sounds likely,
> indeed.  We could consider silencing this warning, but I wonder why
> you'd put such a `declare-function` in the same file where you define
> `foo`, since it's redundant anyway.

In the above cc-fonts.el scenario, foo needs a function binding at the
time the `byte-compile' form processes it, which happens to be before it
gets defined in the file.

> Do you have a good use-case for it?

See above.  ;-)  It may well be that such facilities would enable me to
dismantle large parts of cc-bytecomp.el sooner rather than later.

"This variable/function is defined somewhere" is a natural thing to want
to say.  The (defvar foo) and (declare-function foo nil) don't say this,
exactly.

>         Stefan

-- 
Alan Mackenzie (Nuremberg, Germany).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]