From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jens Schmidt via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org> Newsgroups: gmane.emacs.bugs Subject: bug#67005: 30.0.50; improve nadivce/comp/trampoline handling Date: Wed, 22 Nov 2023 23:01:44 +0100 Message-ID: <87leap8n1z.fsf@sappc2.fritz.box> References: <874jhv9921.fsf@sappc2.fritz.box> <jwvbkc3c1dv.fsf-monnier+emacs@gnu.org> <875y24zrt1.fsf@sappc2.fritz.box> <jwvbkbw6i5b.fsf-monnier+emacs@gnu.org> <87ttpmwuxi.fsf@sappc2.fritz.box> <877cmct4a1.fsf@sappc2.fritz.box> <jwv7cmbdhgc.fsf-monnier+emacs@gnu.org> <87bkbmiwpf.fsf@sappc2.fritz.box> <jwvedgisqel.fsf-monnier+emacs@gnu.org> Reply-To: Jens Schmidt <jschmidt4gnu@vodafonemail.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7808"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Cc: andrea corallo <acorallo@gnu.org>, 67005@debbugs.gnu.org To: Stefan Monnier <monnier@iro.umontreal.ca> Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Nov 22 23:03:22 2023 Return-path: <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org> 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 <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>) id 1r5vJZ-0001pI-TA for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 22 Nov 2023 23:03:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from <bug-gnu-emacs-bounces@gnu.org>) id 1r5vJF-0006Qn-Gk; Wed, 22 Nov 2023 17:03:01 -0500 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 <Debian-debbugs@debbugs.gnu.org>) id 1r5vJD-0006Fv-H3 for bug-gnu-emacs@gnu.org; Wed, 22 Nov 2023 17:02:59 -0500 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 <Debian-debbugs@debbugs.gnu.org>) id 1r5vJD-0003nT-6d for bug-gnu-emacs@gnu.org; Wed, 22 Nov 2023 17:02:59 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1r5vJG-00007q-LY for bug-gnu-emacs@gnu.org; Wed, 22 Nov 2023 17:03:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Jens Schmidt <jschmidt4gnu@vodafonemail.de> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org> Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 22 Nov 2023 22:03:02 +0000 Resent-Message-ID: <handler.67005.B67005.1700690531378@debbugs.gnu.org> Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67005 X-GNU-PR-Package: emacs Original-Received: via spool by 67005-submit@debbugs.gnu.org id=B67005.1700690531378 (code B ref 67005); Wed, 22 Nov 2023 22:03:02 +0000 Original-Received: (at 67005) by debbugs.gnu.org; 22 Nov 2023 22:02:11 +0000 Original-Received: from localhost ([127.0.0.1]:59993 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>) id 1r5vIR-00005z-7E for submit@debbugs.gnu.org; Wed, 22 Nov 2023 17:02:11 -0500 Original-Received: from mr6.vodafonemail.de ([145.253.228.166]:54724) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <jschmidt4gnu@vodafonemail.de>) id 1r5vIP-00005c-4a for 67005@debbugs.gnu.org; Wed, 22 Nov 2023 17:02:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vodafonemail.de; s=vfde-mb-mr2-23sep; t=1700690519; bh=lOxIdmXpwbMckyK+kaR+WVu/mnLRP8fCj95rfGMLBO4=; h=From:To:Subject:References:Date:In-Reply-To:Message-ID:User-Agent: Content-Type:From; b=ZPVOQLQ8zzpLPjILvAERp27oIwPiCSt5CCvO0Q7b2fndf3Eyhh3svOziItO+kDO/k LOQOefOUbBuop7UiUvPPF7fcrr+dtZWAg7MEDg2beOH1Y3qmnCuyTX0Jz7ztqvpHet lE7F2b/dVVhORCdRxNE6sD24jgN6O0nh/CS4mDkM= Original-Received: from smtp.vodafone.de (unknown [10.0.0.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by mr6.vodafonemail.de (Postfix) with ESMTPS id 4SbFZv44w6z1y0B; Wed, 22 Nov 2023 22:01:59 +0000 (UTC) Original-Received: from sappc2 (port-83-236-5-70.dynamic.as20676.net [83.236.5.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp.vodafone.de (Postfix) with ESMTPSA id 4SbFZh6Fvmz9sBV; Wed, 22 Nov 2023 22:01:45 +0000 (UTC) In-Reply-To: <jwvedgisqel.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Tue, 21 Nov 2023 17:18:13 -0500") X-purgate-type: clean X-purgate: clean X-purgate-size: 4793 X-purgate-ID: 155817::1700690515-7BFFC7FF-57217AFF/0/0 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" <bug-gnu-emacs.gnu.org> List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-gnu-emacs>, <mailto:bug-gnu-emacs-request@gnu.org?subject=unsubscribe> List-Archive: <https://lists.gnu.org/archive/html/bug-gnu-emacs> List-Post: <mailto:bug-gnu-emacs@gnu.org> List-Help: <mailto:bug-gnu-emacs-request@gnu.org?subject=help> List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-gnu-emacs>, <mailto:bug-gnu-emacs-request@gnu.org?subject=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:274779 Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/274779> --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Improve-handling-of-advices-and-trampoline-generatio.patch >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 --=-=-=--