all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#67568: Emacs master: Bug in byte compiler when there's an unused parameter.
@ 2023-12-01 12:49 Alan Mackenzie
  2023-12-01 13:06 ` Dmitry Gutov
  0 siblings, 1 reply; 10+ messages in thread
From: Alan Mackenzie @ 2023-12-01 12:49 UTC (permalink / raw
  To: 67568; +Cc: Stefan Monnier

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





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#67568: Emacs master: Bug in byte compiler when there's an unused parameter.
  2023-12-01 12:49 bug#67568: Emacs master: Bug in byte compiler when there's an unused parameter Alan Mackenzie
@ 2023-12-01 13:06 ` Dmitry Gutov
  2023-12-01 14:16   ` Alan Mackenzie
  2023-12-01 15:22   ` Alan Mackenzie
  0 siblings, 2 replies; 10+ messages in thread
From: Dmitry Gutov @ 2023-12-01 13:06 UTC (permalink / raw
  To: Alan Mackenzie, 67568; +Cc: Stefan Monnier

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





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#67568: Emacs master: Bug in byte compiler when there's an unused parameter.
  2023-12-01 13:06 ` Dmitry Gutov
@ 2023-12-01 14:16   ` Alan Mackenzie
  2023-12-01 15:22   ` Alan Mackenzie
  1 sibling, 0 replies; 10+ messages in thread
From: Alan Mackenzie @ 2023-12-01 14:16 UTC (permalink / raw
  To: Dmitry Gutov; +Cc: Stefan Monnier, 67568

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





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#67568: Emacs master: Bug in byte compiler when there's an unused parameter.
  2023-12-01 13:06 ` Dmitry Gutov
  2023-12-01 14:16   ` Alan Mackenzie
@ 2023-12-01 15:22   ` Alan Mackenzie
  2023-12-01 15:40     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 1 reply; 10+ messages in thread
From: Alan Mackenzie @ 2023-12-01 15:22 UTC (permalink / raw
  To: Dmitry Gutov; +Cc: acm, Stefan Monnier, 67568

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





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#67568: Emacs master: Bug in byte compiler when there's an unused parameter.
  2023-12-01 15:22   ` Alan Mackenzie
@ 2023-12-01 15:40     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-12-01 16:34       ` Alan Mackenzie
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-12-01 15:40 UTC (permalink / raw
  To: Alan Mackenzie; +Cc: Dmitry Gutov, 67568

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






^ permalink raw reply related	[flat|nested] 10+ messages in thread

* bug#67568: Emacs master: Bug in byte compiler when there's an unused parameter.
  2023-12-01 15:40     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-12-01 16:34       ` Alan Mackenzie
  2023-12-03 15:55         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 10+ messages in thread
From: Alan Mackenzie @ 2023-12-01 16:34 UTC (permalink / raw
  To: Stefan Monnier; +Cc: Dmitry Gutov, acm, 67568

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





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#67568: Emacs master: Bug in byte compiler when there's an unused parameter.
  2023-12-01 16:34       ` Alan Mackenzie
@ 2023-12-03 15:55         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-12-03 16:21           ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-12-03 15:55 UTC (permalink / raw
  To: Alan Mackenzie; +Cc: Dmitry Gutov, 67568

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






^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#67568: Emacs master: Bug in byte compiler when there's an unused parameter.
  2023-12-03 15:55         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-12-03 16:21           ` Eli Zaretskii
  2023-12-03 19:24             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2023-12-03 16:21 UTC (permalink / raw
  To: Stefan Monnier; +Cc: acm, 67568, dmitry

> Cc: Dmitry Gutov <dmitry@gutov.dev>, 67568@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@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.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#67568: Emacs master: Bug in byte compiler when there's an unused parameter.
  2023-12-03 16:21           ` Eli Zaretskii
@ 2023-12-03 19:24             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-12-03 19:28               ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-12-03 19:24 UTC (permalink / raw
  To: Eli Zaretskii; +Cc: dmitry, acm, 67568-done

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






^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#67568: Emacs master: Bug in byte compiler when there's an unused parameter.
  2023-12-03 19:24             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-12-03 19:28               ` Eli Zaretskii
  0 siblings, 0 replies; 10+ messages in thread
From: Eli Zaretskii @ 2023-12-03 19:28 UTC (permalink / raw
  To: Stefan Monnier; +Cc: dmitry, acm, 67568-done

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Cc: acm@muc.de,  67568-done@debbugs.gnu.org,  dmitry@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@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.





^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-12-03 19:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-01 12:49 bug#67568: Emacs master: Bug in byte compiler when there's an unused parameter Alan Mackenzie
2023-12-01 13:06 ` Dmitry Gutov
2023-12-01 14:16   ` Alan Mackenzie
2023-12-01 15:22   ` Alan Mackenzie
2023-12-01 15:40     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-01 16:34       ` Alan Mackenzie
2023-12-03 15:55         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-03 16:21           ` Eli Zaretskii
2023-12-03 19:24             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-03 19:28               ` Eli Zaretskii

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.