all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* incorrect warning when byte compiling?
@ 2012-06-24 18:54 Richard Hansen
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Hansen @ 2012-06-24 18:54 UTC (permalink / raw)
  To: help-gnu-emacs

Hi all,

I'm getting a warning when byte compiling that I think shouldn't be a 
warning.

I'm using Emacs 23.3.1 on Linux.  If I put the following in foo.el:

     (defun whitespace-redraw ()
       (eval-when-compile (require 'whitespace nil t))
       (when (require 'whitespace nil t)
         (if whitespace-mode
             (whitespace-mode 0))
         (whitespace-mode 1)))

and then byte compile it:

     emacs -Q --batch --eval '(byte-compile-file "foo.el")'

I get the following warning:

     In end of data:
     foo.el:7:1:Warning: the function `whitespace-mode' might not be 
defined at
         runtime.
     Wrote foo.elc

Yes, whitespace-mode can be undefined at runtime, but only if the 
whitespace feature isn't available.  If whitespace is NOT available, the 
body of the 'when' will not execute, so it won't try to execute the 
undefined whitespace-mode function.  If whitespace IS available, 
whitespace-mode is guaranteed to be defined.  Either way, there's no way 
Emacs will try to execute an undefined whitespace-mode function.

So why is Emacs printing the warning?

Is this a bug/limitation in the Emacs byte compiler?  Or is there a 
subtle bug in my code?

It's easy enough to silence this warning (e.g., with (when (fboundp 
'whitespace-mode) ...)), but I want to know why Emacs thinks this is a 
problem.

Thanks,
Richard



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: incorrect warning when byte compiling?
       [not found] <mailman.3395.1340564211.855.help-gnu-emacs@gnu.org>
@ 2012-06-25  7:20 ` John Wiegley
  2012-06-25 22:55 ` Stefan Monnier
  1 sibling, 0 replies; 3+ messages in thread
From: John Wiegley @ 2012-06-25  7:20 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> Richard Hansen <rhansen@bbn.com> writes:

> Yes, whitespace-mode can be undefined at runtime, but only if the whitespace
> feature isn't available.  If whitespace is NOT available, the body of the
> when' will not execute, so it won't try to execute the undefined
> whitespace-mode function.  If whitespace IS available, whitespace-mode is
> guaranteed to be defined.  Either way, there's no way Emacs will try to
> execute an undefined whitespace-mode function.

The byte-compiler doesn't do as much code-flow analysis as you're expecting
here.  Since the call to `require' is inside a function definition, it doesn't
actually need to invoke the `require' to byte-compile the function.  So it
doesn't know if the function is going to get pulled in by the require or not.

You can try moving your require outside the function.

> Is this a bug/limitation in the Emacs byte compiler?  Or is there a subtle
> bug in my code?

> It's easy enough to silence this warning (e.g., with (when (fboundp
> whitespace-mode) ...)), but I want to know why Emacs thinks this is a
> problem.

A better way to wrap the code with:

    (with-no-warnings ...)

John


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: incorrect warning when byte compiling?
       [not found] <mailman.3395.1340564211.855.help-gnu-emacs@gnu.org>
  2012-06-25  7:20 ` incorrect warning when byte compiling? John Wiegley
@ 2012-06-25 22:55 ` Stefan Monnier
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2012-06-25 22:55 UTC (permalink / raw)
  To: help-gnu-emacs

> Is this a bug/limitation in the Emacs byte compiler?

Bug, no, limitation, yes.

> It's easy enough to silence this warning (e.g., with (when (fboundp
> whitespace-mode) ...)), but I want to know why Emacs thinks this
> is a problem.

Doing "(eval-when-compile (require 'whitespace nil t))" and
then "(when (require 'whitespace nil t)" is very unusual so the
byte-compiler does not try to handle this kind of circumstance cleverly.

Really, (eval-when-compile (require 'whitespace nil t)) is meant for the
case where `whitespace' defines functions or macros which will be called
during byte-compilation; it's not meant to silence compiler warnings.

Rather than fboundp, you can also use `declare-function', whose purpose
is specifically to silence compiler warnings.


        Stefan


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-06-25 22:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.3395.1340564211.855.help-gnu-emacs@gnu.org>
2012-06-25  7:20 ` incorrect warning when byte compiling? John Wiegley
2012-06-25 22:55 ` Stefan Monnier
2012-06-24 18:54 Richard Hansen

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.