GNU bug report logs - #55137
Different result when interpreted and when evaluating byte-compiled code

Previous Next

Package: emacs;

Reported by: Paul Pogonyshev <pogonyshev <at> gmail.com>

Date: Tue, 26 Apr 2022 22:18:01 UTC

Severity: normal

Full log


Message #17 received at 55137 <at> debbugs.gnu.org (full text, mbox):

From: Paul Pogonyshev <pogonyshev <at> gmail.com>
To: Phil Sainty <psainty <at> orcon.net.nz>
Cc: 55137 <at> debbugs.gnu.org
Subject: Re: bug#55137: Different result when interpreted and when evaluating
 byte-compiled code
Date: Wed, 27 Apr 2022 13:33:57 +0200
[Message part 1 (text/plain, inline)]
I understand what's happening, I just find this extremely confusing. Can
byte-compilation not notice that there is a `defvar' form and thus count
the variable as special also during compilation?

> Try this:

This cannot be done in the real cases where things break, because they
(`iter-defun', for example) _need_ to know if the variable is special at
the time macro gets expanded (they call internal helper functions that call
`special-variable-p' in turn).

The only workaround I'm aware of is putting `defvar' into an
`eval-and-compile' form (or into a different file, as `require' implicitly
does that). I consider this a workaround rather than a proper solution
since it is very confusing and not even apparent to many users (pretty much
to most of those who never stumbled into this issue). Also, resulting
errors are not self-explanatory and can be anything, including
incomprehensible and seemingly unrelated failures at runtime .
Additionally, you need to know if said variable is going to be used in a
macro that uses `special-variable-p' in its expansion code; in particular,
you need to know the list of such macros (I currently know two related
real-word examples: `iter-defun' and friends from the standard feature
`generator' and `iter2-defun' and friends from library `iter2'). Normally,
you don't even think about putting `defvar' into an `eval-and-compile'.

As mentioned, I think that byte-compilation should be improved to mark
variables as special during compilation time too, so that there is no need
in `eval-and-compile'. I.e. even if this is not considered a bug, it should
count as a feature request.

Paul

On Wed, 27 Apr 2022 at 13:20, Phil Sainty <psainty <at> orcon.net.nz> wrote:

> On 2022-04-27 10:16, Paul Pogonyshev wrote:
> >     (defmacro is-special-as-macro ()
> >       (special-variable-p 'special-variable))
>
> This macro does not expand to code which calls `special-variable-p'.
> Rather it calls `special-variable-p' at expansion time, and expands
> to the return value of that call (nil or t).
>
> If you byte-compile your code without loading it, then your would-be
> `special-variable' doesn't exist, and hence your macro was expanding
> to nil rather than t.
>
> Try this:
>
>       (defmacro is-special-as-macro ()
>         '(special-variable-p 'special-variable))
>
>
> -Phil
>
>
[Message part 2 (text/html, inline)]

This bug report was last modified 2 years and 275 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.