From: Alan Mackenzie <acm@muc.de>
To: Eli Zaretskii <eliz@gnu.org>, Andrea Corallo <acorallo@gnu.org>
Cc: 64642@debbugs.gnu.org
Subject: bug#64642: 29.0.92; Native compiler doesn't compile dynamically bound functions.
Date: Sat, 15 Jul 2023 15:17:20 +0000 [thread overview]
Message-ID: <ZLK4gMhXMVDqXyiY@ACM> (raw)
In-Reply-To: <838rbhcxg0.fsf@gnu.org>
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@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).
next prev parent reply other threads:[~2023-07-15 15:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-15 9:38 bug#64642: 29.0.92; Native compiler doesn't compile dynamically bound functions Alan Mackenzie
2023-07-15 9:53 ` Eli Zaretskii
2023-07-15 15:17 ` Alan Mackenzie [this message]
2023-07-17 13:42 ` Andrea Corallo
2023-07-17 16:06 ` Eli Zaretskii
2023-07-17 17:43 ` Alan Mackenzie
2023-07-19 11:31 ` Alan Mackenzie
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZLK4gMhXMVDqXyiY@ACM \
--to=acm@muc.de \
--cc=64642@debbugs.gnu.org \
--cc=acorallo@gnu.org \
--cc=eliz@gnu.org \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).