From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#41988: 28.0.50; Edebug unconditionally instruments definitions with &define specs Date: Sat, 10 Apr 2021 11:51:50 -0400 Message-ID: References: <6D19F14E-0133-4751-B0BD-EC2A73C1D21F@gmail.com> <3619E155-8F06-4F8F-B239-121ED3D164A8@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22831"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 41988@debbugs.gnu.org To: Philipp Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Apr 10 17:53:11 2021 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 1lVFv3-0005mL-Rb for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 10 Apr 2021 17:53:09 +0200 Original-Received: from localhost ([::1]:43498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lVFv2-0004Lc-Be for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 10 Apr 2021 11:53:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51492) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVFuw-0004L7-5c for bug-gnu-emacs@gnu.org; Sat, 10 Apr 2021 11:53:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:41525) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lVFuv-0004ZS-UU for bug-gnu-emacs@gnu.org; Sat, 10 Apr 2021 11:53:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lVFuv-0001f7-Ri for bug-gnu-emacs@gnu.org; Sat, 10 Apr 2021 11:53:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 10 Apr 2021 15:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41988 X-GNU-PR-Package: emacs Original-Received: via spool by 41988-submit@debbugs.gnu.org id=B41988.16180699236322 (code B ref 41988); Sat, 10 Apr 2021 15:53:01 +0000 Original-Received: (at 41988) by debbugs.gnu.org; 10 Apr 2021 15:52:03 +0000 Original-Received: from localhost ([127.0.0.1]:53071 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVFty-0001du-Lg for submit@debbugs.gnu.org; Sat, 10 Apr 2021 11:52:03 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:57992) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVFtw-0001dP-AF for 41988@debbugs.gnu.org; Sat, 10 Apr 2021 11:52:01 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id A3E1F1001D2; Sat, 10 Apr 2021 11:51:54 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 85A861000DA; Sat, 10 Apr 2021 11:51:52 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1618069912; bh=csAUf5IAr9DUxpEtYDhR7JxBQ2/L2e0s+H90017RHSk=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=g6GWvu54HUGkK8tRzc3AsbIoziqqWBfi4az2aLJAwWgBARDzG+5cr5qUo4C3ciWGI BdQqm6KYY2+umUgwAxR7ysETveLFZ/hc6s3E3HIsFtSxDt6LdOBDjEkXa1tqbk605e OEMgpEo3i9XTUEUmQu+Asm9iXKH4qv7QTr2rz6n2p7PBNbK2XY9e4AkMCsLuPZOvh/ ImzjmwIVe4rFxrHh7DBc8Jo8tEhGLlPhZrXk0n6xdlRFkFx9w9P0QZek4wsSPvCuPJ 7tRMk5jnHCpTqd6JfDHQYFXdlhHDexlmGuGLWvBZCt5zcgwNT45aSD0W9Q5bT7sA/X Sy5KEZiPbWGNw== Original-Received: from alfajor (104-222-126-84.cpe.teksavvy.com [104.222.126.84]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 54CC8120228; Sat, 10 Apr 2021 11:51:52 -0400 (EDT) In-Reply-To: (Philipp's message of "Sat, 10 Apr 2021 17:07:48 +0200") 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" Xref: news.gmane.io gmane.emacs.bugs:203799 Archived-At: > Here's a patch. LGTM, as far as I'm concerned you can push it to `master` and we'll just cross our fingers ;-) Stefan > From 9e2183edea41adf275f057a75232ea0b2c51e726 Mon Sep 17 00:00:00 2001 > From: Philipp Stephani > Date: Thu, 18 Mar 2021 12:40:08 +0100 > Subject: [PATCH] Edebug: Disable backtracking when hitting a &define keyword. > > Edebug doesn't deal well with backtracking out of definitions, see > Bug#41988. Rather than trying to support this rare situation (e.g. by > implementing a multipass parser), prevent it by adding an implicit > gate. > > * lisp/emacs-lisp/edebug.el (edebug--match-&-spec-op): Disable > backtracking when hitting a &define keyword. > > * test/lisp/emacs-lisp/edebug-tests.el > (edebug-tests-duplicate-&define): New unit test. > (edebug-tests--duplicate-&define): New helper macro. > > * doc/lispref/edebug.texi (Backtracking): Mention &define in the list > of constructs that disable backtracking. > > * etc/NEWS: Document new behavior. > --- > doc/lispref/edebug.texi | 10 +++++----- > etc/NEWS | 3 +++ > lisp/emacs-lisp/edebug.el | 18 ++++++++++-------- > test/lisp/emacs-lisp/edebug-tests.el | 25 +++++++++++++++++++++++++ > 4 files changed, 43 insertions(+), 13 deletions(-) > > diff --git a/doc/lispref/edebug.texi b/doc/lispref/edebug.texi > index 8942f55aff..323130f237 100644 > --- a/doc/lispref/edebug.texi > +++ b/doc/lispref/edebug.texi > @@ -1510,11 +1510,11 @@ Backtracking > must be in the form itself rather than at a higher level. > > Backtracking is also disabled after successfully matching a quoted > -symbol or string specification, since this usually indicates a > -recognized construct. But if you have a set of alternative constructs that > -all begin with the same symbol, you can usually work around this > -constraint by factoring the symbol out of the alternatives, e.g., > -@code{["foo" &or [first case] [second case] ...]}. > +symbol, string specification, or @code{&define} keyword, since this > +usually indicates a recognized construct. But if you have a set of > +alternative constructs that all begin with the same symbol, you can > +usually work around this constraint by factoring the symbol out of the > +alternatives, e.g., @code{["foo" &or [first case] [second case] ...]}. > > Most needs are satisfied by these two ways that backtracking is > automatically disabled, but occasionally it is useful to explicitly > diff --git a/etc/NEWS b/etc/NEWS > index a0f05d8cf1..9ae3740482 100644 > --- a/etc/NEWS > +++ b/etc/NEWS > @@ -2524,6 +2524,9 @@ back in Emacs 23.1. The affected functions are: 'make-obsolete', > > ** The 'values' variable is now obsolete. > > +** The '&define' keyword in an Edebug specification now disables > +backtracking. > + > > * Lisp Changes in Emacs 28.1 > > diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el > index f1455ffe73..365bc74874 100644 > --- a/lisp/emacs-lisp/edebug.el > +++ b/lisp/emacs-lisp/edebug.el > @@ -1942,14 +1942,16 @@ edebug--match-&-spec-op > ;; Normally, &define is interpreted specially other places. > ;; This should only be called inside of a spec list to match the remainder > ;; of the current list. e.g. ("lambda" &define args def-body) > - (edebug-make-form-wrapper > - cursor > - (edebug-before-offset cursor) > - ;; Find the last offset in the list. > - (let ((offsets (edebug-cursor-offsets cursor))) > - (while (consp offsets) (setq offsets (cdr offsets))) > - offsets) > - specs)) > + (prog1 (edebug-make-form-wrapper > + cursor > + (edebug-before-offset cursor) > + ;; Find the last offset in the list. > + (let ((offsets (edebug-cursor-offsets cursor))) > + (while (consp offsets) (setq offsets (cdr offsets))) > + offsets) > + specs) > + ;; Stop backtracking here (Bug#41988). > + (setq edebug-gate t))) > > (cl-defmethod edebug--match-&-spec-op ((_ (eql &name)) cursor specs) > "Compute the name for `&name SPEC FUN` spec operator. > diff --git a/test/lisp/emacs-lisp/edebug-tests.el b/test/lisp/emacs-lisp/edebug-tests.el > index dcb261c2eb..7d45432e57 100644 > --- a/test/lisp/emacs-lisp/edebug-tests.el > +++ b/test/lisp/emacs-lisp/edebug-tests.el > @@ -1061,5 +1061,30 @@ edebug-tests-duplicate-symbol-backtrack > "edebug-anon10001" > "edebug-tests-duplicate-symbol-backtrack")))))) > > +(defmacro edebug-tests--duplicate-&define (_arg) > + "Helper macro for the ERT test `edebug-tests-duplicate-&define'. > +The Edebug specification is similar to the one used by `cl-flet' > +previously; see Bug#41988." > + (declare (debug (&or (&define name function-form) (defun))))) > + > +(ert-deftest edebug-tests-duplicate-&define () > + "Check that Edebug doesn't backtrack out of `&define' forms. > +This avoids potential duplicate definitions (Bug#41988)." > + (with-temp-buffer > + (print '(defun edebug-tests-duplicate-&define () > + (edebug-tests--duplicate-&define > + (edebug-tests-duplicate-&define-inner () nil))) > + (current-buffer)) > + (let* ((edebug-all-defs t) > + (edebug-initial-mode 'Go-nonstop) > + (instrumented-names ()) > + (edebug-new-definition-function > + (lambda (name) > + (when (memq name instrumented-names) > + (error "Duplicate definition of `%s'" name)) > + (push name instrumented-names) > + (edebug-new-definition name)))) > + (should-error (eval-buffer) :type 'invalid-read-syntax)))) > + > (provide 'edebug-tests) > ;;; edebug-tests.el ends here