From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#64642: 29.0.92; Native compiler doesn't compile dynamically bound functions. Date: Sat, 15 Jul 2023 15:17:20 +0000 Message-ID: References: <838rbhcxg0.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8957"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 64642@debbugs.gnu.org To: Eli Zaretskii , Andrea Corallo Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 15 17:18:15 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qKh2F-00027F-Aa for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 15 Jul 2023 17:18:15 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qKh24-0005hZ-JQ; Sat, 15 Jul 2023 11:18:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qKh22-0005h7-B0 for bug-gnu-emacs@gnu.org; Sat, 15 Jul 2023 11:18:02 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qKh22-0002uU-3H for bug-gnu-emacs@gnu.org; Sat, 15 Jul 2023 11:18:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qKh21-0002vQ-Ur for bug-gnu-emacs@gnu.org; Sat, 15 Jul 2023 11:18:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 15 Jul 2023 15:18:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64642 X-GNU-PR-Package: emacs Original-Received: via spool by 64642-submit@debbugs.gnu.org id=B64642.168943424911199 (code B ref 64642); Sat, 15 Jul 2023 15:18:01 +0000 Original-Received: (at 64642) by debbugs.gnu.org; 15 Jul 2023 15:17:29 +0000 Original-Received: from localhost ([127.0.0.1]:45787 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qKh1V-0002uZ-8l for submit@debbugs.gnu.org; Sat, 15 Jul 2023 11:17:29 -0400 Original-Received: from mx3.muc.de ([193.149.48.5]:43492) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qKh1T-0002uL-8Q for 64642@debbugs.gnu.org; Sat, 15 Jul 2023 11:17:28 -0400 Original-Received: (qmail 36935 invoked by uid 3782); 15 Jul 2023 17:17:20 +0200 Original-Received: from acm.muc.de (pd953a5ce.dip0.t-ipconnect.de [217.83.165.206]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Sat, 15 Jul 2023 17:17:20 +0200 Original-Received: (qmail 28041 invoked by uid 1000); 15 Jul 2023 15:17:20 -0000 Content-Disposition: inline In-Reply-To: <838rbhcxg0.fsf@gnu.org> X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:265215 Archived-At: 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 > > Hello, Emacs. > > In the Emacs 29 pretest version (or the master version): > > (i) emacs -Q > > (ii) C-x b foo.el > > (iii) M-x emacs-lisp-mode > > 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).