GNU bug report logs - #64642
29.0.92; Native compiler doesn't compile dynamically bound functions.

Previous Next

Package: emacs;

Reported by: Alan Mackenzie <acm <at> muc.de>

Date: Sat, 15 Jul 2023 09:39:02 UTC

Severity: normal

Found in version 29.0.92

Done: Alan Mackenzie <acm <at> muc.de>

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 64642 in the body.
You can then email your comments to 64642 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#64642; Package emacs. (Sat, 15 Jul 2023 09:39: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 bug-gnu-emacs <at> gnu.org. (Sat, 15 Jul 2023 09:39:02 GMT) Full text and rfc822 format available.

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

From: Alan Mackenzie <acm <at> muc.de>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.92; Native compiler doesn't compile dynamically bound functions.
Date: Sat, 15 Jul 2023 09:38:13 +0000
Hello, Emacs.

In the Emacs 29 pretest version (or the master version):
(i) emacs -Q
(ii) C-x b foo.el <RET>
(iii) M-x emacs-lisp-mode <RET>
Don't set lexical-binding in this buffer.
(iv) Enter a function called foo:
    (defun foo () "foo doc string"
      (lambda (bar) "lambda doc string" (car bar)))
(v) With point after the function, evaluate it with C-x C-e.

(vi) M-: (native-compile 'foo)
This signals an error, native-compiler-error-dyn-func.  This is a bug.

#########################################################################

The immediate cause of the bug is in the version of
comp-spill-lap-function which processes named functions (comp.el).
Unlike the other version of the cl-defmethod (which processes lambda
functions), there is no code for dynamic functions here.

If the intention is not to process dynamic functions, this should be
indicated by an error message rather than a signal.  Personally, I feel
that dynamic functions ought to be handled in Emacs-29.

Fixing this bug should be relatively straightforward, since it should
only involve copying and adapting the corresponding code in the lambda
version of comp-spill-lap-function.

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#64642; Package emacs. (Sat, 15 Jul 2023 09:54:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Alan Mackenzie <acm <at> muc.de>, Andrea Corallo <acorallo <at> gnu.org>
Cc: 64642 <at> debbugs.gnu.org
Subject: Re: bug#64642: 29.0.92;
 Native compiler doesn't compile dynamically bound functions.
Date: Sat, 15 Jul 2023 12:53:51 +0300
> Date: Sat, 15 Jul 2023 09:38:13 +0000
> From: Alan Mackenzie <acm <at> muc.de>
> 
> Hello, Emacs.
> 
> In the Emacs 29 pretest version (or the master version):
> (i) emacs -Q
> (ii) C-x b foo.el <RET>
> (iii) M-x emacs-lisp-mode <RET>
> Don't set lexical-binding in this buffer.
> (iv) Enter a function called foo:
>     (defun foo () "foo doc string"
>       (lambda (bar) "lambda doc string" (car bar)))
> (v) With point after the function, evaluate it with C-x C-e.
> 
> (vi) M-: (native-compile 'foo)
> This signals an error, native-compiler-error-dyn-func.  This is a bug.
> 
> #########################################################################
> 
> The immediate cause of the bug is in the version of
> comp-spill-lap-function which processes named functions (comp.el).
> Unlike the other version of the cl-defmethod (which processes lambda
> functions), there is no code for dynamic functions here.
> 
> If the intention is not to process dynamic functions, this should be
> indicated by an error message rather than a signal.  Personally, I feel
> that dynamic functions ought to be handled in Emacs-29.
> 
> Fixing this bug should be relatively straightforward, since it should
> only involve copying and adapting the corresponding code in the lambda
> version of comp-spill-lap-function.

Adding Andrea.

It is unlikely that this will be fixed in Emacs 29, unless the fix is
so simple that will surprise me.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#64642; Package emacs. (Sat, 15 Jul 2023 15:18:01 GMT) Full text and rfc822 format available.

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

From: Alan Mackenzie <acm <at> muc.de>
To: Eli Zaretskii <eliz <at> gnu.org>, Andrea Corallo <acorallo <at> gnu.org>
Cc: 64642 <at> debbugs.gnu.org
Subject: Re: bug#64642: 29.0.92; Native compiler doesn't compile dynamically
 bound functions.
Date: Sat, 15 Jul 2023 15:17:20 +0000
Hello, Eli and Andrea.

On Sat, Jul 15, 2023 at 12:53:51 +0300, Eli Zaretskii wrote:
> > Date: Sat, 15 Jul 2023 09:38:13 +0000
> > From: Alan Mackenzie <acm <at> muc.de>

> > Hello, Emacs.

> > In the Emacs 29 pretest version (or the master version):
> > (i) emacs -Q
> > (ii) C-x b foo.el <RET>
> > (iii) M-x emacs-lisp-mode <RET>
> > Don't set lexical-binding in this buffer.
> > (iv) Enter a function called foo:
> >     (defun foo () "foo doc string"
> >       (lambda (bar) "lambda doc string" (car bar)))
> > (v) With point after the function, evaluate it with C-x C-e.

> > (vi) M-: (native-compile 'foo)
> > This signals an error, native-compiler-error-dyn-func.  This is a bug.

> > #########################################################################

> > The immediate cause of the bug is in the version of
> > comp-spill-lap-function which processes named functions (comp.el).
> > Unlike the other version of the cl-defmethod (which processes lambda
> > functions), there is no code for dynamic functions here.

> > If the intention is not to process dynamic functions, this should be
> > indicated by an error message rather than a signal.  Personally, I feel
> > that dynamic functions ought to be handled in Emacs-29.

> > Fixing this bug should be relatively straightforward, since it should
> > only involve copying and adapting the corresponding code in the lambda
> > version of comp-spill-lap-function.

> Adding Andrea.

> It is unlikely that this will be fixed in Emacs 29, unless the fix is
> so simple that will surprise me.

Here is a fix.  Its simplicity probably doesn't surprise you (Eli), but
the change is entirely within one function, and a lot of the patch is
just whitespace changes.

There are no problems running make bootstrap or make check with patch in
place.  It also solves the bug; unless there are good reasons dynamically
bound functions weren't handled.  Andrea?




diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index 322df0e86a1..3e0725cef4f 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -1274,33 +1274,45 @@ comp-spill-lap-function
           (make-temp-file (comp-c-func-name function-name "freefn-")
                           nil ".eln")))
   (let* ((f (symbol-function function-name))
+         (byte-code (byte-compile function-name))
          (c-name (comp-c-func-name function-name "F"))
-         (func (make-comp-func-l :name function-name
-                                 :c-name c-name
-                                 :doc (documentation f t)
-                                 :int-spec (interactive-form f)
-                                 :command-modes (command-modes f)
-                                 :speed (comp-spill-speed function-name)
-                                 :pure (comp-spill-decl-spec function-name
-                                                             'pure))))
+         (func
+          (if (comp-lex-byte-func-p byte-code)
+              (make-comp-func-l :name function-name
+                                :c-name c-name
+                                :doc (documentation f t)
+                                :int-spec (interactive-form f)
+                                :command-modes (command-modes f)
+                                :speed (comp-spill-speed function-name)
+                                :pure (comp-spill-decl-spec function-name
+                                                            'pure))
+            (make-comp-func-d :name function-name
+                              :c-name c-name
+                              :doc (documentation f t)
+                              :int-spec (interactive-form f)
+                              :command-modes (command-modes f)
+                              :speed (comp-spill-speed function-name)
+                              :pure (comp-spill-decl-spec function-name
+                                                          'pure)))))
       (when (byte-code-function-p f)
         (signal 'native-compiler-error
                 "can't native compile an already byte-compiled function"))
-      (setf (comp-func-byte-func func)
-            (byte-compile (comp-func-name func)))
+      (setf (comp-func-byte-func func) byte-code)
       (let ((lap (byte-to-native-lambda-lap
                   (gethash (aref (comp-func-byte-func func) 1)
                            byte-to-native-lambdas-h))))
         (cl-assert lap)
         (comp-log lap 2 t)
-        (let ((arg-list (aref (comp-func-byte-func func) 0)))
-          (setf (comp-func-l-args func)
-                (comp-decrypt-arg-list arg-list function-name)
-                (comp-func-lap func)
-                lap
-                (comp-func-frame-size func)
-                (comp-byte-frame-size (comp-func-byte-func func))))
-        (setf (comp-ctxt-top-level-forms comp-ctxt)
+        (if (comp-func-l-p func)
+            (let ((arg-list (aref (comp-func-byte-func func) 0)))
+              (setf (comp-func-l-args func)
+                    (comp-decrypt-arg-list arg-list function-name)))
+          (setf (comp-func-d-lambda-list func) (cadr f)))
+        (setf (comp-func-lap func)
+              lap
+              (comp-func-frame-size func)
+              (comp-byte-frame-size (comp-func-byte-func func))
+              (comp-ctxt-top-level-forms comp-ctxt)
               (list (make-byte-to-native-func-def :name function-name
                                                   :c-name c-name)))
         (comp-add-func-to-ctxt func))))


-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#64642; Package emacs. (Mon, 17 Jul 2023 13:43:01 GMT) Full text and rfc822 format available.

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

From: Andrea Corallo <acorallo <at> gnu.org>
To: Alan Mackenzie <acm <at> muc.de>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 64642 <at> debbugs.gnu.org
Subject: Re: bug#64642: 29.0.92; Native compiler doesn't compile dynamically
 bound functions.
Date: Mon, 17 Jul 2023 09:42:31 -0400
Alan Mackenzie <acm <at> muc.de> writes:

> Hello, Eli and Andrea.
>
> On Sat, Jul 15, 2023 at 12:53:51 +0300, Eli Zaretskii wrote:
>> > Date: Sat, 15 Jul 2023 09:38:13 +0000
>> > From: Alan Mackenzie <acm <at> muc.de>
>
>> > Hello, Emacs.
>
>> > In the Emacs 29 pretest version (or the master version):
>> > (i) emacs -Q
>> > (ii) C-x b foo.el <RET>
>> > (iii) M-x emacs-lisp-mode <RET>
>> > Don't set lexical-binding in this buffer.
>> > (iv) Enter a function called foo:
>> >     (defun foo () "foo doc string"
>> >       (lambda (bar) "lambda doc string" (car bar)))
>> > (v) With point after the function, evaluate it with C-x C-e.
>
>> > (vi) M-: (native-compile 'foo)
>> > This signals an error, native-compiler-error-dyn-func.  This is a bug.
>
>> > #########################################################################
>
>> > The immediate cause of the bug is in the version of
>> > comp-spill-lap-function which processes named functions (comp.el).
>> > Unlike the other version of the cl-defmethod (which processes lambda
>> > functions), there is no code for dynamic functions here.
>
>> > If the intention is not to process dynamic functions, this should be
>> > indicated by an error message rather than a signal.  Personally, I feel
>> > that dynamic functions ought to be handled in Emacs-29.
>
>> > Fixing this bug should be relatively straightforward, since it should
>> > only involve copying and adapting the corresponding code in the lambda
>> > version of comp-spill-lap-function.
>
>> Adding Andrea.
>
>> It is unlikely that this will be fixed in Emacs 29, unless the fix is
>> so simple that will surprise me.
>
> Here is a fix.  Its simplicity probably doesn't surprise you (Eli), but
> the change is entirely within one function, and a lot of the patch is
> just whitespace changes.
>
> There are no problems running make bootstrap or make check with patch in
> place.  It also solves the bug; unless there are good reasons dynamically
> bound functions weren't handled.  Andrea?

Hi Alan,

the fix LGTM thanks for the patch, I think we only need to add a test as
well to exercise this code, something like the "free-fun" test in
comp-tests.el.

Thanks

  Andrea




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#64642; Package emacs. (Mon, 17 Jul 2023 16:07:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Andrea Corallo <acorallo <at> gnu.org>
Cc: acm <at> muc.de, 64642 <at> debbugs.gnu.org
Subject: Re: bug#64642: 29.0.92; Native compiler doesn't compile dynamically
 bound functions.
Date: Mon, 17 Jul 2023 19:06:58 +0300
> From: Andrea Corallo <acorallo <at> gnu.org>
> Cc: Eli Zaretskii <eliz <at> gnu.org>,  64642 <at> debbugs.gnu.org
> Date: Mon, 17 Jul 2023 09:42:31 -0400
> 
> >> It is unlikely that this will be fixed in Emacs 29, unless the fix is
> >> so simple that will surprise me.
> >
> > Here is a fix.  Its simplicity probably doesn't surprise you (Eli), but
> > the change is entirely within one function, and a lot of the patch is
> > just whitespace changes.
> >
> > There are no problems running make bootstrap or make check with patch in
> > place.  It also solves the bug; unless there are good reasons dynamically
> > bound functions weren't handled.  Andrea?
> 
> Hi Alan,
> 
> the fix LGTM thanks for the patch, I think we only need to add a test as
> well to exercise this code, something like the "free-fun" test in
> comp-tests.el.

Alan, when the patch is ready, please install on master.

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#64642; Package emacs. (Mon, 17 Jul 2023 17:44:01 GMT) Full text and rfc822 format available.

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

From: Alan Mackenzie <acm <at> muc.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Andrea Corallo <acorallo <at> gnu.org>, 64642 <at> debbugs.gnu.org
Subject: Re: bug#64642: 29.0.92; Native compiler doesn't compile dynamically
 bound functions.
Date: Mon, 17 Jul 2023 17:43:26 +0000
Hello, Eli.

On Mon, Jul 17, 2023 at 19:06:58 +0300, Eli Zaretskii wrote:
> > From: Andrea Corallo <acorallo <at> gnu.org>
> > Cc: Eli Zaretskii <eliz <at> gnu.org>,  64642 <at> debbugs.gnu.org
> > Date: Mon, 17 Jul 2023 09:42:31 -0400

> > >> It is unlikely that this will be fixed in Emacs 29, unless the fix is
> > >> so simple that will surprise me.

> > > Here is a fix.  Its simplicity probably doesn't surprise you (Eli), but
> > > the change is entirely within one function, and a lot of the patch is
> > > just whitespace changes.

> > > There are no problems running make bootstrap or make check with patch in
> > > place.  It also solves the bug; unless there are good reasons dynamically
> > > bound functions weren't handled.  Andrea?

> > Hi Alan,

> > the fix LGTM thanks for the patch, I think we only need to add a test as
> > well to exercise this code, something like the "free-fun" test in
> > comp-tests.el.

> Alan, when the patch is ready, please install on master.

I'll do that, "ready" meaning when I've written that test suggested by
Andrea.

Thanks!

> Thanks.

-- 
Alan Mackenzie (Nuremberg, Germany).




Reply sent to Alan Mackenzie <acm <at> muc.de>:
You have taken responsibility. (Wed, 19 Jul 2023 11:32:01 GMT) Full text and rfc822 format available.

Notification sent to Alan Mackenzie <acm <at> muc.de>:
bug acknowledged by developer. (Wed, 19 Jul 2023 11:32:01 GMT) Full text and rfc822 format available.

Message #25 received at 64642-done <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: acm <at> muc.de, Andrea Corallo <acorallo <at> gnu.org>, 64642-done <at> debbugs.gnu.org
Subject: Re: bug#64642: 29.0.92; Native compiler doesn't compile dynamically
 bound functions.
Date: Wed, 19 Jul 2023 11:31:14 +0000
Hello, Eli.

On Mon, Jul 17, 2023 at 19:06:58 +0300, Eli Zaretskii wrote:
> > From: Andrea Corallo <acorallo <at> gnu.org>
> > Cc: Eli Zaretskii <eliz <at> gnu.org>,  64642 <at> debbugs.gnu.org
> > Date: Mon, 17 Jul 2023 09:42:31 -0400

> > >> It is unlikely that this will be fixed in Emacs 29, unless the fix is
> > >> so simple that will surprise me.

> > > Here is a fix.  Its simplicity probably doesn't surprise you (Eli), but
> > > the change is entirely within one function, and a lot of the patch is
> > > just whitespace changes.

> > > There are no problems running make bootstrap or make check with patch in
> > > place.  It also solves the bug; unless there are good reasons dynamically
> > > bound functions weren't handled.  Andrea?

> > Hi Alan,

> > the fix LGTM thanks for the patch, I think we only need to add a test as
> > well to exercise this code, something like the "free-fun" test in
> > comp-tests.el.

> Alan, when the patch is ready, please install on master.

DONE.  I'm closing the bug with this post.

> Thanks.

-- 
Alan Mackenzie (Nuremberg, Germany).




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 17 Aug 2023 11:24:08 GMT) Full text and rfc822 format available.

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

Previous Next


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