GNU bug report logs -
#67568
Emacs master: Bug in byte compiler when there's an unused parameter.
Previous Next
Reported by: Alan Mackenzie <acm <at> muc.de>
Date: Fri, 1 Dec 2023 12:51:01 UTC
Severity: normal
Done: Stefan Monnier <monnier <at> iro.umontreal.ca>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 67568 in the body.
You can then email your comments to 67568 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org
:
bug#67568
; Package
emacs
.
(Fri, 01 Dec 2023 12:51:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Alan Mackenzie <acm <at> muc.de>
:
New bug report received and forwarded. Copy sent to
monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org
.
(Fri, 01 Dec 2023 12:51:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Hello, Emacs.
On a recent Emacs master:
(i) emacs -Q
(ii) In *scratch* enter the following:
(byte-compile (lambda (x) "doc" "foo"))
.
(iii) Enter C-u C-x C-e to evaluate the form. The result looks like:
#[257 "\300\207" [nil] 2 "doc
(fn X)"]
. This is incorrect. The only form in the constants vector is nil.
It should be "foo".
(iv) Note that this only happens with the unused parameter x. Without
it, the form compiles correctly.
--
Alan Mackenzie (Nuremberg, Germany).
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#67568
; Package
emacs
.
(Fri, 01 Dec 2023 13:07:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 67568 <at> debbugs.gnu.org (full text, mbox):
On 01/12/2023 14:49, Alan Mackenzie wrote:
> On a recent Emacs master:
>
> (i) emacs -Q
> (ii) In*scratch* enter the following:
>
> (byte-compile (lambda (x) "doc" "foo"))
>
> .
> (iii) Enter C-u C-x C-e to evaluate the form. The result looks like:
>
> #[257 "\300\207" [nil] 2 "doc
>
> (fn X)"]
>
> . This is incorrect. The only form in the constants vector is nil.
> It should be "foo".
>
> (iv) Note that this only happens with the unused parameter x. Without
> it, the form compiles correctly.
Might be a bug in the interpreter too?
(funcall (lambda (x) "doc" "foo") 2)
;; => nil
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#67568
; Package
emacs
.
(Fri, 01 Dec 2023 14:18:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 67568 <at> debbugs.gnu.org (full text, mbox):
Hello, Dmitry.
On Fri, Dec 01, 2023 at 15:06:23 +0200, Dmitry Gutov wrote:
> On 01/12/2023 14:49, Alan Mackenzie wrote:
> > On a recent Emacs master:
> > (i) emacs -Q
> > (ii) In*scratch* enter the following:
> > (byte-compile (lambda (x) "doc" "foo"))
> > .
> > (iii) Enter C-u C-x C-e to evaluate the form. The result looks like:
> > #[257 "\300\207" [nil] 2 "doc
> > (fn X)"]
> > . This is incorrect. The only form in the constants vector is nil.
> > It should be "foo".
> > (iv) Note that this only happens with the unused parameter x. Without
> > it, the form compiles correctly.
> Might be a bug in the interpreter too?
> (funcall (lambda (x) "doc" "foo") 2)
> ;; => nil
Outch! Thanks for spotting that, it might make the bug easier to solve.
--
Alan Mackenzie (Nuremberg, Germany).
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#67568
; Package
emacs
.
(Fri, 01 Dec 2023 15:23:01 GMT)
Full text and
rfc822 format available.
Message #14 received at 67568 <at> debbugs.gnu.org (full text, mbox):
Hello again, Dmitry.
On Fri, Dec 01, 2023 at 15:06:23 +0200, Dmitry Gutov wrote:
> On 01/12/2023 14:49, Alan Mackenzie wrote:
> > On a recent Emacs master:
> > (i) emacs -Q
> > (ii) In*scratch* enter the following:
> > (byte-compile (lambda (x) "doc" "foo"))
> > .
> > (iii) Enter C-u C-x C-e to evaluate the form. The result looks like:
> > #[257 "\300\207" [nil] 2 "doc
> > (fn X)"]
> > . This is incorrect. The only form in the constants vector is nil.
> > It should be "foo".
> > (iv) Note that this only happens with the unused parameter x. Without
> > it, the form compiles correctly.
> Might be a bug in the interpreter too?
> (funcall (lambda (x) "doc" "foo") 2)
> ;; => nil
I have a candidate for the buggy function, namely macroexp-parse-body.
It'd doc string reads "Parse a function BODY into (DECLARATIONS . EXPS).",
but it's vague about what precisely a BODY is. It's not clear, either,
what exactly is meant by DECLARATIONS.
What the function does is move strings (or :documentation forms) from the
head of BODY into DECLS. So maybe DECLARATIONS is intended to be any
number of consecutive doc strings. Exceptionally, if there is precisely
one string, it is not moved into DECLS.
When BODY is ("doc" "foo") as is the case here, both "doc" and "foo" get
moved from BODY to DECLS, leaving an empty BODY and a wrong DECLS. The
return value is here (("doc" "foo") . nil), which is clearly wrong. It
probably should be (("doc") . ("foo")).
--
Alan Mackenzie (Nuremberg, Germany).
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#67568
; Package
emacs
.
(Fri, 01 Dec 2023 15:42:01 GMT)
Full text and
rfc822 format available.
Message #17 received at 67568 <at> debbugs.gnu.org (full text, mbox):
> I have a candidate for the buggy function, namely macroexp-parse-body.
Duh!
I think the patch below should fix it.
Stefan
diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el
index 6eb670d6dc1..6ed3e0c4896 100644
--- a/lisp/emacs-lisp/macroexp.el
+++ b/lisp/emacs-lisp/macroexp.el
@@ -540,7 +540,9 @@ macroexp-parse-body
(while
(and body
(let ((e (car body)))
- (or (stringp e)
+ (or (and (stringp e)
+ ;; Only the first string can be a docstring.
+ (not (delq nil (mapcar #'stringp decls))))
(memq (car-safe e)
'(:documentation declare interactive cl-declare)))))
(push (pop body) decls)))
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#67568
; Package
emacs
.
(Fri, 01 Dec 2023 16:35:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 67568 <at> debbugs.gnu.org (full text, mbox):
Hello, Stefan.
On Fri, Dec 01, 2023 at 10:40:55 -0500, Stefan Monnier wrote:
> > I have a candidate for the buggy function, namely macroexp-parse-body.
> Duh!
> I think the patch below should fix it.
It certainly will in the test case, yes.
I think I understand the function better now, thanks.
Are you going to commit your patch, or should I? :-)
> Stefan
> diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el
> index 6eb670d6dc1..6ed3e0c4896 100644
> --- a/lisp/emacs-lisp/macroexp.el
> +++ b/lisp/emacs-lisp/macroexp.el
> @@ -540,7 +540,9 @@ macroexp-parse-body
> (while
> (and body
> (let ((e (car body)))
> - (or (stringp e)
> + (or (and (stringp e)
> + ;; Only the first string can be a docstring.
> + (not (delq nil (mapcar #'stringp decls))))
> (memq (car-safe e)
> '(:documentation declare interactive cl-declare)))))
> (push (pop body) decls)))
--
Alan Mackenzie (Nuremberg, Germany).
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#67568
; Package
emacs
.
(Sun, 03 Dec 2023 15:57:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 67568 <at> debbugs.gnu.org (full text, mbox):
>> I think the patch below should fix it.
> It certainly will in the test case, yes.
> I think I understand the function better now, thanks.
> Are you going to commit your patch, or should I? :-)
I'm wondering whether it should go to `emacs-29` or to `master`.
I'm leaning toward `emacs-29` because it's rather embarrassing (and
perplexing for the user) and the patch is simple.
Eli? Stefan?
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#67568
; Package
emacs
.
(Sun, 03 Dec 2023 16:22:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 67568 <at> debbugs.gnu.org (full text, mbox):
> Cc: Dmitry Gutov <dmitry <at> gutov.dev>, 67568 <at> debbugs.gnu.org
> Date: Sun, 03 Dec 2023 10:55:56 -0500
> From: Stefan Monnier via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>
> >> I think the patch below should fix it.
> > It certainly will in the test case, yes.
> > I think I understand the function better now, thanks.
> > Are you going to commit your patch, or should I? :-)
>
> I'm wondering whether it should go to `emacs-29` or to `master`.
> I'm leaning toward `emacs-29` because it's rather embarrassing (and
> perplexing for the user) and the patch is simple.
> Eli? Stefan?
No objections from me.
Thanks.
Reply sent
to
Stefan Monnier <monnier <at> iro.umontreal.ca>
:
You have taken responsibility.
(Sun, 03 Dec 2023 19:26:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Alan Mackenzie <acm <at> muc.de>
:
bug acknowledged by developer.
(Sun, 03 Dec 2023 19:26:02 GMT)
Full text and
rfc822 format available.
Message #31 received at 67568-done <at> debbugs.gnu.org (full text, mbox):
>> I'm wondering whether it should go to `emacs-29` or to `master`.
>> I'm leaning toward `emacs-29` because it's rather embarrassing (and
>> perplexing for the user) and the patch is simple.
>> Eli? Stefan?
> No objections from me.
It turns out the bug is not present in `emacs-29`, it was introduced on
master by:
commit f616edb4ccce5b9d60e3ff42806bd2131989cd1e
Author: Mattias EngdegÄrd <mattiase <at> acm.org>
Date: Mon Sep 25 14:40:11 2023 +0200
macroexp-parse-body: correct parsing of empty body (bug#66136)
* lisp/emacs-lisp/macroexp.el (macroexp-parse-body):
Return an empty body even when there are declarations present.
Previously, the last declaration was considered part of the body,
which is only correct if the input consists of a single string.
Reported by Jens Schmidt.
So I pushed a better fix, on master.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#67568
; Package
emacs
.
(Sun, 03 Dec 2023 19:29:02 GMT)
Full text and
rfc822 format available.
Message #34 received at 67568-done <at> debbugs.gnu.org (full text, mbox):
> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
> Cc: acm <at> muc.de, 67568-done <at> debbugs.gnu.org, dmitry <at> gutov.dev
> Date: Sun, 03 Dec 2023 14:24:44 -0500
>
> >> I'm wondering whether it should go to `emacs-29` or to `master`.
> >> I'm leaning toward `emacs-29` because it's rather embarrassing (and
> >> perplexing for the user) and the patch is simple.
> >> Eli? Stefan?
> > No objections from me.
>
> It turns out the bug is not present in `emacs-29`, it was introduced on
> master by:
>
> commit f616edb4ccce5b9d60e3ff42806bd2131989cd1e
> Author: Mattias EngdegÄrd <mattiase <at> acm.org>
> Date: Mon Sep 25 14:40:11 2023 +0200
>
> macroexp-parse-body: correct parsing of empty body (bug#66136)
>
> * lisp/emacs-lisp/macroexp.el (macroexp-parse-body):
> Return an empty body even when there are declarations present.
> Previously, the last declaration was considered part of the body,
> which is only correct if the input consists of a single string.
>
> Reported by Jens Schmidt.
>
> So I pushed a better fix, on master.
Great, thanks.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Mon, 01 Jan 2024 12:24:09 GMT)
Full text and
rfc822 format available.
This bug report was last modified 1 year and 131 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.