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" Newsgroups: gmane.emacs.bugs Subject: bug#58396: 29.0.50; Optimization failure for add-to-list Date: Sat, 30 Sep 2023 12:39:57 +0200 Message-ID: <87ttrcaqrm.fsf@sappc2.fritz.box> References: <87o7uknkyx.fsf@gnus.org> <87fsfwnkl4.fsf@gnus.org> <87a663kxtz.fsf@gnus.org> <87czaygqqp.fsf@gnus.org> <87fsfte2hf.fsf@gnus.org> <87o7hod6dk.fsf@sappc2.fritz.box> <87v8bwip2h.fsf@sappc2.fritz.box> Reply-To: Jens Schmidt 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="39011"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Cc: German Pacenza , 58396@debbugs.gnu.org, Lars Ingebrigtsen To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 30 12:41:06 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 1qmXPF-0009v5-KM for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 30 Sep 2023 12:41:05 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmXOz-0006iZ-4N; Sat, 30 Sep 2023 06:40:49 -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 1qmXOx-0006iD-9k for bug-gnu-emacs@gnu.org; Sat, 30 Sep 2023 06:40:47 -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 1qmXOx-0002XA-1F for bug-gnu-emacs@gnu.org; Sat, 30 Sep 2023 06:40:47 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qmXPB-0003Xl-TW for bug-gnu-emacs@gnu.org; Sat, 30 Sep 2023 06:41:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jens Schmidt Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 30 Sep 2023 10:41:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58396 X-GNU-PR-Package: emacs Original-Received: via spool by 58396-submit@debbugs.gnu.org id=B58396.169607044213576 (code B ref 58396); Sat, 30 Sep 2023 10:41:01 +0000 Original-Received: (at 58396) by debbugs.gnu.org; 30 Sep 2023 10:40:42 +0000 Original-Received: from localhost ([127.0.0.1]:57783 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qmXOr-0003Wt-Qi for submit@debbugs.gnu.org; Sat, 30 Sep 2023 06:40:42 -0400 Original-Received: from mr4.vodafonemail.de ([145.253.228.164]:59538) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qmXOo-0003WZ-QL for 58396@debbugs.gnu.org; Sat, 30 Sep 2023 06:40:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vodafonemail.de; s=vfde-mb-mr2-21dec; t=1696070415; bh=kQejq4Idjkg1gJWsui67/zEg8XroZ8HDnw46CjQQMPk=; h=From:To:Subject:References:Date:In-Reply-To:Message-ID:User-Agent: Content-Type:From; b=f8tgfx3v6lKUnH8NVT8YpDSDw4iMS+nzSVGCBMdmRJjb5Su9/s3/pXUnPicVsldc9 7Bu89mm3zkgtkLfg5/jt9YlwEEmYR+ILkO3sMlAo97DGG/eS49K8rcauWjriQIs5Sb 42t0rOoptweMUWjKIvVcQOdnb6eq8ZeaYxeAbXjk= 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 mr4.vodafonemail.de (Postfix) with ESMTPS id 4RyNyl2Bz6z1y2Y; Sat, 30 Sep 2023 10:40:15 +0000 (UTC) Original-Received: from sappc2 (port-83-236-57-119.dynamic.as20676.net [83.236.57.119]) (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 4RyNyT369Mz9sR9; Sat, 30 Sep 2023 10:39:58 +0000 (UTC) In-Reply-To: (Stefan Monnier's message of "Tue, 26 Sep 2023 18:06:53 -0400") X-purgate-type: clean X-purgate: clean X-purgate-size: 6829 X-purgate-ID: 155817::1696070411-3AFFA7FF-386A5EB0/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" 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:271538 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Stefan Monnier writes: >> I also wanted to ask whether to extend that approach to the other advice >> installed in `elisp--local-variables=C2=B4 > > That would be nice, but... > >> but then noticed that `macroexpand=C2=B4 is actually a built-in. > > `elisp--local-variables=C2=B4 doesn't use that built-in any more, it uses > `macroexpand-1` instead, which is implemented in `macroexp.el` :-) > > But the problem is that the advice wraps the call within > a `condition-case` and that's inconvenient to do in a way which > doesn't interfere too much with "normal use" (e.g. doesn't hide/catch > errors when we don't want to, and doesn't impose too much of > a performance cost either). Agreed. Anyway, here are two patches: One for Emacs 29 and one for master. The patch for Emacs 29: - does not contain the rather non-local change for avoiding compiler macros. But it fixes this bug, anyway, by just ignoring all errors during the `macroexpand-all' call. - contains a "don't merge to master" maker in the commit message. What do you think? --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-29-Silence-macro-expansion-during-completion-at-point.patch >From cc663ccb14f3fae361733fe9742d7c7d07274d54 Mon Sep 17 00:00:00 2001 From: Jens Schmidt Date: Tue, 26 Sep 2023 22:26:15 +0200 Subject: [PATCH] Silence macro expansion during completion-at-point * lisp/progmodes/elisp-mode.el (elisp--local-variables): Silence messages. Suppress all errors during macro expansion. (Bug#58396) Do not merge to master. --- lisp/progmodes/elisp-mode.el | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index bd3916ce108..bc01058ff3c 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -445,11 +445,19 @@ elisp--local-variables (condition-case nil (apply expander form args) (error form)))) + ;; Avoid any macro expansion errors when attempting + ;; completion at point (bug#58148). As Stefan suggested + ;; there: Silence messages [1] and suppress all errors + ;; [3]. (Not avoiding compiler macros in the current + ;; release branch, though.) (sexp (unwind-protect - (let ((warning-minimum-log-level :emergency)) + (let ((inhibit-message t) ;[1] + (warning-minimum-log-level :emergency)) (advice-add 'macroexpand :around macroexpand-advice) - (macroexpand-all sexp)) + (condition-case nil ;[3] + (macroexpand-all sexp) + (t sexp))) (advice-remove 'macroexpand macroexpand-advice))) (vars (elisp--local-variables-1 nil sexp))) (delq nil -- 2.30.2 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-30-Silence-macro-expansion-during-completion-at-point.patch >From feb9906cece4a1fbce6417e9225a937aa7e8c830 Mon Sep 17 00:00:00 2001 From: Jens Schmidt Date: Fri, 29 Sep 2023 22:04:43 +0200 Subject: [PATCH] Silence macro expansion during completion-at-point * lisp/emacs-lisp/macroexp.el (macroexp-inhibit-compiler-macros): Add variable. (macroexp--compiler-macro): Inspect that new variable and, if it is non-nil, return the input form unchanged. * lisp/progmodes/elisp-mode.el (elisp--local-variables): Silence messages. Avoid compiler macros. Suppress all errors during macro expansion. (Bug#58396) --- lisp/emacs-lisp/macroexp.el | 20 ++++++++++++++------ lisp/progmodes/elisp-mode.el | 12 ++++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el index 3ef924a5c73..6eb670d6dc1 100644 --- a/lisp/emacs-lisp/macroexp.el +++ b/lisp/emacs-lisp/macroexp.el @@ -105,13 +105,21 @@ macroexp--all-clauses (macroexp--all-forms clause skip) clause))) +(defvar macroexp-inhibit-compiler-macros nil + "Inhibit application of compiler macros if non-nil.") + (defun macroexp--compiler-macro (handler form) - (condition-case-unless-debug err - (apply handler form (cdr form)) - (error - (message "Warning: Optimization failure for %S: Handler: %S\n%S" - (car form) handler err) - form))) + "Apply compiler macro HANDLER to FORM and return the result. +Unless `macroexp-inhibit-compiler-macros' is non-nil, in which +case return FORM unchanged." + (if macroexp-inhibit-compiler-macros + form + (condition-case-unless-debug err + (apply handler form (cdr form)) + (error + (message "Warning: Optimization failure for %S: Handler: %S\n%S" + (car form) handler err) + form)))) (defun macroexp--funcall-if-compiled (_form) "Pseudo function used internally by macroexp to delay warnings. diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index 664299df288..434b493ed55 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -458,11 +458,19 @@ elisp--local-variables (apply expander form args) ((debug error) (message "Ignoring macroexpansion error: %S" err) form)))) + ;; Avoid any macro expansion errors when attempting + ;; completion at point (bug#58148). As Stefan suggested + ;; there: Silence messages [1], avoid compiler macros + ;; [2], and suppress all errors [3]. (sexp (unwind-protect - (let ((warning-minimum-log-level :emergency)) + (let ((inhibit-message t) ;[1] + (macroexp-inhibit-compiler-macros t) ;[2] + (warning-minimum-log-level :emergency)) (advice-add 'macroexpand-1 :around macroexpand-advice) - (macroexpand-all sexp elisp--local-macroenv)) + (condition-case nil ;[3] + (macroexpand-all sexp elisp--local-macroenv) + (t sexp))) (advice-remove 'macroexpand-1 macroexpand-advice))) (vars (elisp--local-variables-1 nil sexp))) (delq nil -- 2.30.2 --=-=-=--