* bug#52147: Eager macro-expansion is not performed in `eval-and-compile' functions
@ 2021-11-27 19:37 Paul Pogonyshev
2021-11-28 10:30 ` Michael Heerdegen
0 siblings, 1 reply; 8+ messages in thread
From: Paul Pogonyshev @ 2021-11-27 19:37 UTC (permalink / raw)
To: 52147
[-- Attachment #1: Type: text/plain, Size: 515 bytes --]
Simple code to demonstrate this:
;; -*- lexical-binding: t -*-
(defmacro my-macro (x)
`,x)
(eval-and-compile
(defun my-func-eac (what)
(my-macro what)))
(defun my-func-normal (what)
(my-macro what))
(print (symbol-function 'my-func-eac))
(print (symbol-function 'my-func-normal))
`eval-and-compile' is advertised in Elisp manual to make byte-compilation
of certain macros without prior loading possible. Looks strange that at the
same time it can worsen performance of non-byte-compiled code.
Paul
[-- Attachment #2: Type: text/html, Size: 669 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#52147: Eager macro-expansion is not performed in `eval-and-compile' functions
2021-11-27 19:37 bug#52147: Eager macro-expansion is not performed in `eval-and-compile' functions Paul Pogonyshev
@ 2021-11-28 10:30 ` Michael Heerdegen
2021-11-28 21:53 ` Paul Pogonyshev
0 siblings, 1 reply; 8+ messages in thread
From: Michael Heerdegen @ 2021-11-28 10:30 UTC (permalink / raw)
To: Paul Pogonyshev; +Cc: 52147
Hello Paul,
> (eval-and-compile
> (defun my-func-eac (what)
> (my-macro what)))
>
> (defun my-func-normal (what)
> (my-macro what))
>
> (print (symbol-function 'my-func-eac))
> (print (symbol-function 'my-func-normal))
>
> `eval-and-compile' is advertised in Elisp manual to make
> byte-compilation of certain macros without prior loading
> possible. Looks strange that at the same time it can worsen
> performance of non-byte-compiled code.
Is the issue you want to draw attention to that an interpreted
`eval-and-compile' form doesn't macroexpand its body?
Michael.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#52147: Eager macro-expansion is not performed in `eval-and-compile' functions
2021-11-28 10:30 ` Michael Heerdegen
@ 2021-11-28 21:53 ` Paul Pogonyshev
2021-11-29 15:44 ` Lars Ingebrigtsen
0 siblings, 1 reply; 8+ messages in thread
From: Paul Pogonyshev @ 2021-11-28 21:53 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: 52147
[-- Attachment #1: Type: text/plain, Size: 845 bytes --]
That's what the subject says. I know that it works regardless, but the
performance suffers, especially if the used macros are complex.
Paul
On Sun, 28 Nov 2021 at 11:30, Michael Heerdegen <michael_heerdegen@web.de>
wrote:
> Hello Paul,
>
> > (eval-and-compile
> > (defun my-func-eac (what)
> > (my-macro what)))
> >
> > (defun my-func-normal (what)
> > (my-macro what))
> >
> > (print (symbol-function 'my-func-eac))
> > (print (symbol-function 'my-func-normal))
> >
> > `eval-and-compile' is advertised in Elisp manual to make
> > byte-compilation of certain macros without prior loading
> > possible. Looks strange that at the same time it can worsen
> > performance of non-byte-compiled code.
>
> Is the issue you want to draw attention to that an interpreted
> `eval-and-compile' form doesn't macroexpand its body?
>
> Michael.
>
[-- Attachment #2: Type: text/html, Size: 1306 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#52147: Eager macro-expansion is not performed in `eval-and-compile' functions
2021-11-28 21:53 ` Paul Pogonyshev
@ 2021-11-29 15:44 ` Lars Ingebrigtsen
2021-11-29 19:14 ` Michael Heerdegen
0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2021-11-29 15:44 UTC (permalink / raw)
To: Paul Pogonyshev; +Cc: Michael Heerdegen, 52147
Paul Pogonyshev <pogonyshev@gmail.com> writes:
> Is the issue you want to draw attention to that an interpreted
> `eval-and-compile' form doesn't macroexpand its body?
> That's what the subject says.
Well, not exactly -- it doesn't say anything about the code being
interpreted.
> I know that it works regardless, but the
> performance suffers, especially if the used macros are complex.
We usually don't stress a lot about the performance of interpreted
(i.e., uncompiled) code. Does this have a performance impact on
byte-compiled code?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#52147: Eager macro-expansion is not performed in `eval-and-compile' functions
2021-11-29 15:44 ` Lars Ingebrigtsen
@ 2021-11-29 19:14 ` Michael Heerdegen
2022-01-15 13:10 ` Lars Ingebrigtsen
0 siblings, 1 reply; 8+ messages in thread
From: Michael Heerdegen @ 2021-11-29 19:14 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 52147, Paul Pogonyshev
Lars Ingebrigtsen <larsi@gnus.org> writes:
> We usually don't stress a lot about the performance of interpreted
> (i.e., uncompiled) code.
Well we do, a bit,
(info "(elisp) How Programs Do Loading")
says that loading a file performs eager macro expansion and that does
speed up the resulting code. `eval', `eval-when-compile' and
`eval-and-compile' don't perform eager macro expansion. I don't know to
what degree this is on purpose. But if a macro is defined later in the
file or in another file that has not yet been loaded this may not be
possible anyway.
Michael.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#52147: Eager macro-expansion is not performed in `eval-and-compile' functions
2021-11-29 19:14 ` Michael Heerdegen
@ 2022-01-15 13:10 ` Lars Ingebrigtsen
2022-01-15 15:09 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2022-01-15 13:10 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: 52147, Paul Pogonyshev, Stefan Monnier
Michael Heerdegen <michael_heerdegen@web.de> writes:
> Well we do, a bit,
>
> (info "(elisp) How Programs Do Loading")
>
> says that loading a file performs eager macro expansion and that does
> speed up the resulting code. `eval', `eval-when-compile' and
> `eval-and-compile' don't perform eager macro expansion. I don't know to
> what degree this is on purpose. But if a macro is defined later in the
> file or in another file that has not yet been loaded this may not be
> possible anyway.
It sounds to me like things are basically working as designed.
Perhaps Stefan has some comments; added to the CCs.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#52147: Eager macro-expansion is not performed in `eval-and-compile' functions
2022-01-15 13:10 ` Lars Ingebrigtsen
@ 2022-01-15 15:09 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-20 9:50 ` Lars Ingebrigtsen
0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-01-15 15:09 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: Michael Heerdegen, 52147, Paul Pogonyshev
>>> We usually don't stress a lot about the performance of interpreted
>>> (i.e., uncompiled) code.
Indeed.
>> Well we do, a bit,
>>
>> (info "(elisp) How Programs Do Loading")
>>
>> says that loading a file performs eager macro expansion and that does
>> speed up the resulting code. `eval', `eval-when-compile' and
>> `eval-and-compile' don't perform eager macro expansion. I don't know to
>> what degree this is on purpose. But if a macro is defined later in the
>> file or in another file that has not yet been loaded this may not be
>> possible anyway.
>
> It sounds to me like things are basically working as designed.
>
> Perhaps Stefan has some comments; added to the CCs.
AFAIK the exact time of macro expansion is left underspecified
on purpose. Whether eager-macroexpansion is used or not should be an
implementation detail. A piece of code which relies on macro-expansion
being done lazily is a bug, AFAIC. Usually those bugs become apparent
when byte-compiling the file (where macro-expansion is necessarily
eager), except for those cases that occur during bootstrap.
Both `eval-when-compile` and `eval-and-compile` currently defer to
`eval`, but they should arguably do the macro-expansion eagerly, indeed.
`eval` currently doesn't use eager macro-expansion because I haven't
done the work needed to check/ensure that the resulting potential
slowdown is negligible. But I think `eval` should also eagerly
macro-expand its argument.
Stefan
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#52147: Eager macro-expansion is not performed in `eval-and-compile' functions
2022-01-15 15:09 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-01-20 9:50 ` Lars Ingebrigtsen
0 siblings, 0 replies; 8+ messages in thread
From: Lars Ingebrigtsen @ 2022-01-20 9:50 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Michael Heerdegen, 52147, Paul Pogonyshev
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> Both `eval-when-compile` and `eval-and-compile` currently defer to
> `eval`, but they should arguably do the macro-expansion eagerly, indeed.
OK; I'll leave this bug report open as a wishlist item.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-01-20 9:50 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-27 19:37 bug#52147: Eager macro-expansion is not performed in `eval-and-compile' functions Paul Pogonyshev
2021-11-28 10:30 ` Michael Heerdegen
2021-11-28 21:53 ` Paul Pogonyshev
2021-11-29 15:44 ` Lars Ingebrigtsen
2021-11-29 19:14 ` Michael Heerdegen
2022-01-15 13:10 ` Lars Ingebrigtsen
2022-01-15 15:09 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-20 9:50 ` Lars Ingebrigtsen
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.