all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Pogonyshev <pogonyshev@gmail.com>
To: Phil Sainty <psainty@orcon.net.nz>
Cc: 55137@debbugs.gnu.org
Subject: bug#55137: Different result when interpreted and when evaluating byte-compiled code
Date: Wed, 27 Apr 2022 13:33:57 +0200	[thread overview]
Message-ID: <CAG7BpaqgRu95FpLCkC=-T9bkUASY7R71h64QF381FSsEJZhNJQ@mail.gmail.com> (raw)
In-Reply-To: <8ddae25aa2488d550ca63e396015002e@webmail.orcon.net.nz>

[-- Attachment #1: Type: text/plain, Size: 2327 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 2915 bytes --]

  reply	other threads:[~2022-04-27 11:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-26 22:16 bug#55137: Different result when interpreted and when evaluating byte-compiled code Paul Pogonyshev
2022-04-27  2:27 ` Eli Zaretskii
2022-04-27  9:19   ` Paul Pogonyshev
2022-04-27 11:20 ` Phil Sainty
2022-04-27 11:33   ` Paul Pogonyshev [this message]
2022-11-08  2:37     ` Michael Heerdegen

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='CAG7BpaqgRu95FpLCkC=-T9bkUASY7R71h64QF381FSsEJZhNJQ@mail.gmail.com' \
    --to=pogonyshev@gmail.com \
    --cc=55137@debbugs.gnu.org \
    --cc=psainty@orcon.net.nz \
    /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.