unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Jens Schmidt via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: andrea corallo <acorallo@gnu.org>, 67005@debbugs.gnu.org
Subject: bug#67005: 30.0.50; improve nadivce/comp/trampoline handling
Date: Wed, 22 Nov 2023 23:01:44 +0100	[thread overview]
Message-ID: <87leap8n1z.fsf@sappc2.fritz.box> (raw)
In-Reply-To: <jwvedgisqel.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Tue, 21 Nov 2023 17:18:13 -0500")

[-- Attachment #1: Type: text/plain, Size: 1069 bytes --]

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Only slightly off-topic: When changing the default value of user option
>> `native-comp-never-optimize-functions', which now both Andrea and I have
>> done, does one also need to bump the :version?  Or is this taken care of
>> automagically?  If it needs to be done manually, to which value should
>> we/I set it?
>
> I guess you should change it to the version in which the new value will
> be released (i.e. "30.1").

Andrea has already seen to that, thanks.

>> And here is another comment question: Do you think this snippet that
>> made me so upset:
>>
>>       (let* ((f (if (symbolp callee)
>>                     (symbol-function callee)
>>                   (cl-assert (byte-code-function-p callee))
>>                   callee))
>>              (subrp (subrp f))
>>              (comp-func-callee (comp-func-in-unit callee)))
>>
>> deserves some explanation?
>
> A comment would make sense, since the code got you confused, yes.

That comment added, others removed and shortened.  Please review.

Thanks


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Improve-handling-of-advices-and-trampoline-generatio.patch --]
[-- Type: text/x-diff, Size: 3417 bytes --]

From 8758a6b4f7eff990dea45b651eaa2b7e94db730e Mon Sep 17 00:00:00 2001
From: Jens Schmidt <jschmidt4gnu@vodafonemail.de>
Date: Mon, 20 Nov 2023 23:42:01 +0100
Subject: [PATCH] Improve handling of advices and trampoline generation

* lisp/emacs-lisp/comp-common.el
(native-comp-never-optimize-functions): Remove macroexpand and
rename-buffer from default value.
* lisp/emacs-lisp/comp.el (comp-call-optim-form-call): Document call
optimization for advised primitives.
* lisp/emacs-lisp/nadvice.el (advice-add): Disallow advices during
bootstrap.  (Bug#67005)
---
 lisp/emacs-lisp/comp-common.el | 9 ++++-----
 lisp/emacs-lisp/comp.el        | 8 ++++++++
 lisp/emacs-lisp/nadvice.el     | 9 +++++++--
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/lisp/emacs-lisp/comp-common.el b/lisp/emacs-lisp/comp-common.el
index 6d94d1bd82e..cc7f21900e8 100644
--- a/lisp/emacs-lisp/comp-common.el
+++ b/lisp/emacs-lisp/comp-common.el
@@ -49,11 +49,10 @@ native-comp-verbose
   :version "28.1")

 (defcustom native-comp-never-optimize-functions
-  '(eval
-    ;; The following two are mandatory for Emacs to be working
-    ;; correctly (see comment in `advice--add-function'). DO NOT
-    ;; REMOVE.
-    macroexpand rename-buffer)
+  ;; We used to list those functions here that were advised during
+  ;; preload, but we now prefer to disallow preload advices in
+  ;; `advice-add' (bug#67005).
+  '(eval)
   "Primitive functions to exclude from trampoline optimization.

 Primitive functions included in this list will not be called
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index 73764eb1d79..9d537cbcfa7 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -2783,6 +2783,14 @@ comp-call-optim-form-call
                     (symbol-function callee)
                   (cl-assert (byte-code-function-p callee))
                   callee))
+             ;; Below call to `subrp' returns nil on an advised
+             ;; primitive F, so that we do not optimize calls to F
+             ;; with the funcall trampoline removal below.  But if F
+             ;; is advised while we compile its call, it is very
+             ;; likely to be advised also when that call is executed.
+             ;; And in that case an "unoptimized" call to F is
+             ;; actually cheaper since it avoids the call to the
+             ;; intermediate native trampoline (bug#67005).
              (subrp (subrp f))
              (comp-func-callee (comp-func-in-unit callee)))
         (cond
diff --git a/lisp/emacs-lisp/nadvice.el b/lisp/emacs-lisp/nadvice.el
index 42027c01491..c43d1b86752 100644
--- a/lisp/emacs-lisp/nadvice.el
+++ b/lisp/emacs-lisp/nadvice.el
@@ -507,10 +507,15 @@ advice-add
 is defined as a macro, alias, command, ...
 HOW can be one of:
 <<>>"
+  ;; Actively disallow function advices during bootstrap for the
+  ;; following reasons:
+  ;; - Advices in Emacs' core are generally considered bad style.
+  ;; - `Snarf-documentation' looses docstrings of advised dumped
+  ;;   functions (bug#66032#20).
   ;; TODO:
   ;; - record the advice location, to display in describe-function.
-  ;; - change all defadvice in lisp/**/*.el.
-  ;; - obsolete advice.el.
+  (when purify-flag
+    (error "Invalid pre-dump advice on %s" symbol))
   (let* ((f (symbol-function symbol))
 	 (nf (advice--normalize symbol f)))
     (unless (eq f nf) (fset symbol nf))
--
2.30.2

  parent reply	other threads:[~2023-11-22 22:01 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-08 22:25 bug#67005: 30.0.50; improve nadivce/comp/trampoline handling Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-08 22:50 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-12 19:50   ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-14  8:02   ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-14  8:31     ` Andrea Corallo
2023-11-14 20:23       ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-15  0:06     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-15 21:47       ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-20 23:04         ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-21  3:35           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-21 11:07             ` Andrea Corallo
2023-11-21 22:10             ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-21 22:18               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-22 15:40                 ` Andrea Corallo
2023-11-22 16:07                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-22 16:31                     ` Eli Zaretskii
2023-11-23 13:02                       ` Andrea Corallo
2023-11-23 16:27                         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-23 20:26                           ` Andrea Corallo
2023-11-22 22:01                 ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-11-23  6:19                   ` Eli Zaretskii
2023-11-23 15:01                     ` Andrea Corallo
2023-11-23 21:13                       ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-23 15:00                   ` Andrea Corallo
2023-11-23 16:24                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-23 16:38                       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-23 20:21                         ` Andrea Corallo
2023-11-23 21:36                       ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-23 23:48                         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-25 12:41                           ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-25 14:39                             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-25 18:35                               ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-04 20:08                                 ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-04 20:47                                   ` Andrea Corallo
2023-12-04 23:57                                     ` Andy Moreton
2023-12-05 17:09                                       ` Andrea Corallo
2023-12-05 21:32                                         ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-06  0:13                                           ` Andy Moreton
2023-12-18 21:27                                           ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-23 21:18                     ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-22 14:18               ` Eli Zaretskii
2023-11-16  8:46       ` Andrea Corallo
2023-11-17 15:58         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-17 20:37           ` Andrea Corallo
2023-11-17 20:44             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-20  8:58               ` Andrea Corallo
2023-11-20 13:13                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-18  7:05             ` Eli Zaretskii
2023-11-20  9:31               ` Andrea Corallo
2023-11-13  9:54 ` Andrea Corallo

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=87leap8n1z.fsf@sappc2.fritz.box \
    --to=bug-gnu-emacs@gnu.org \
    --cc=67005@debbugs.gnu.org \
    --cc=acorallo@gnu.org \
    --cc=jschmidt4gnu@vodafonemail.de \
    --cc=monnier@iro.umontreal.ca \
    /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).