all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: emacs-devel@gnu.org
Subject: Re: Byte compiler and eval-when-compile
Date: Mon, 15 Oct 2012 14:41:26 -0400	[thread overview]
Message-ID: <jwvfw5fip3x.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87a9vn7lhv.fsf@engster.org> (David Engster's message of "Mon, 15 Oct 2012 18:23:08 +0200")

> 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.

> I now get a lot more 'function X might not be defined at runtime'
> warnings than before.

That's expected.

> In CEDET, we often use `require' statements in function bodies, like
> this:

> (defun test()
>   (require 'eldoc)
>   (message "%s" (eldoc-function-argstring '("foo" "bar"))))

> The reason is simply to only do the require when it is actually needed,
> so that startup time is reduced.
> Still, if you byte-compile the above, you'll get a 'might not be
> defined at runtime' warning for `eldoc-function-argstring'.

Yes, that's an annoying case.

> 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.

> 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).

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.

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.

   
-- Stefan



  reply	other threads:[~2012-10-15 18:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-15 16:23 Byte compiler and eval-when-compile David Engster
2012-10-15 18:41 ` Stefan Monnier [this message]
2012-10-15 19:26   ` David Engster
2012-10-16  0:58     ` Stefan Monnier
2012-10-18 18:55       ` David Engster
2012-10-18 19:53         ` Glenn Morris
2012-10-18 20:07           ` David Engster
2012-10-18 20:11           ` Glenn Morris
2012-10-18 20:15             ` David Engster
2012-10-19  0:38         ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvfw5fip3x.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.