emacs-devel
[Top][All Lists]
Advanced

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

Re: Byte compiler and eval-when-compile


From: David Engster
Subject: Re: Byte compiler and eval-when-compile
Date: Mon, 15 Oct 2012 21:26:37 +0200
User-agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.2.50 (gnu/linux)

Stefan Monnier writes:
>> Somehow the byte compiler got smart during the last days (I think it's
>> the change in rev. 110510).
>
> Actually, it just recovered the smartness I added many years ago and
> which got broken years ago as well.

Just to make sure I understand this right: the byte-compiler will now
bark if you're using functions (instead of just macros and defsubsts)
from eval-when-compile'd required packages?

>> I used to circumvent that problem by simply doing
>> (eval-when-compile
>>   (require 'eldoc))
>> Before you scream at me: I *know* this is not what `eval-when-compile'
>> is for, but it has worked until a few days ago.  It seems the
>> byte-compiler now sees that I'm actually using a function from eldoc,
>> but he still doesn't see that I'm requiring the package it in the
>> function body.
>
> If you both do the (eval-when-compile (require 'eldoc)) and the
> `require', the byte-compiler could be smarter indeed: when it sees the
> inner `require' call, it could check load-history and mark all functions
> defined therein as being fine for the current scope.

Well, that would be more or less a legalization of the little hack I did
so far.

>> Do I now really have to use `declare-function' for all those cases?
>
> Currently, yes (or use an fboundp test, which you probably won't like
> any better).

Indeed. I will just declare the functions. :-)

> I think a good solution to such cases would be to add a `lazy-require':
> when interpreted, it works like `require', but the byte-compiler will
> turn it into a bunch of autoloads.

That would be neat, yes.

> A simpler solution might be to provide a new (funcall-require PACKAGE
> FUNCTION &rest ARGS), so you'd do
>
>    (funcall-require 'eldoc #'eldoc-function-argstring '("foo" "bar"))
>
> but the compiler could still be taught to check that
> eldoc-function-argstring indeed exists in eldoc and accepts being called
> with a single argument.

That's pretty much a combination of declare-function and require, isn't
it? At least it wouldn't save me any typing. :-)

-David



reply via email to

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