From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#31090: 26.0.91; Edebug incorrectly instruments unquotes in nested backquotes Date: Sun, 22 Sep 2019 10:16:34 +0000 Message-ID: <20190922101634.GA8955@ACM> References: <87fu4662fm.fsf@runbox.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="104644"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) Cc: 31090@debbugs.gnu.org To: Gemini Lasswell Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Sep 22 12:17:17 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iByvd-000R7O-9I for geb-bug-gnu-emacs@m.gmane.org; Sun, 22 Sep 2019 12:17:17 +0200 Original-Received: from localhost ([::1]:45994 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iByvb-0007Ds-GP for geb-bug-gnu-emacs@m.gmane.org; Sun, 22 Sep 2019 06:17:15 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41922) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iByvQ-0007Dl-KN for bug-gnu-emacs@gnu.org; Sun, 22 Sep 2019 06:17:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iByvO-0002Q4-H6 for bug-gnu-emacs@gnu.org; Sun, 22 Sep 2019 06:17:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52829) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iByvN-0002Py-Tr for bug-gnu-emacs@gnu.org; Sun, 22 Sep 2019 06:17:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iByvN-0005cd-LJ for bug-gnu-emacs@gnu.org; Sun, 22 Sep 2019 06:17: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: Sun, 22 Sep 2019 10:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31090 X-GNU-PR-Package: emacs Original-Received: via spool by 31090-submit@debbugs.gnu.org id=B31090.156914740221574 (code B ref 31090); Sun, 22 Sep 2019 10:17:01 +0000 Original-Received: (at 31090) by debbugs.gnu.org; 22 Sep 2019 10:16:42 +0000 Original-Received: from localhost ([127.0.0.1]:33417 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iByv3-0005bs-Tv for submit@debbugs.gnu.org; Sun, 22 Sep 2019 06:16:42 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:26639 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1iByv0-0005bh-3t for 31090@debbugs.gnu.org; Sun, 22 Sep 2019 06:16:39 -0400 Original-Received: (qmail 97825 invoked by uid 3782); 22 Sep 2019 10:16:36 -0000 Original-Received: from acm.muc.de (p4FE15FF8.dip0.t-ipconnect.de [79.225.95.248]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 22 Sep 2019 12:16:34 +0200 Original-Received: (qmail 9106 invoked by uid 1000); 22 Sep 2019 10:16:34 -0000 Content-Disposition: inline In-Reply-To: <87fu4662fm.fsf@runbox.com> X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:166897 Archived-At: Hello, Gemini. I think I've cracked this bug. On Sat, Apr 07, 2018 at 16:44:59 -0700, Gemini Lasswell wrote: > Edebug incorrectly instruments unquotes inside of nested backquotes, > causing errors if the incorrectly instrumented forms are part of a > macro expansion that then gets executed in another context. As you say the problem is with nested backquotes, in particular when there's no , or ,@ "between" the two backquotes. What edebug does at the moment is, once a backquote is encountered, _every_ , and ,@ form inside it is instrumented. This is wrong. The inner backquote form should not be instrumented, since it is code which will be generated by the macro, not code executed by the macro. The exception is when there is a , or ,@ inside the inner backquote, which needs to "turn on" instrumentation again for its contents. Or something like that. > To reproduce, enter this code into *scratch*: > (defun my-wrap-form (form description) > `(unless ,form > (message "failed %s" ,description))) > (defmacro my-should (form) > (declare (debug t)) > (let ((fn (gensym "fn-")) > (args (gensym "args-")) > (value (gensym "value-"))) > `(let ((,fn (function ,(car form))) > (,args (list ,@(cdr form))) > ,value) > ,(my-wrap-form > `(setq ,value (apply ,fn ,args)) > `(nconc (list :form `(,,fn ,@,args)) > (list :value ,value)))))) > (defun my-test () > (my-should (= 1 2))) > Then: > Navigate to the definition of my-wrap-form and evaluate it with C-M-x > Navigate to the definition of my-should and evaluate it with C-u C-M-x > Navigate to the definition of my-test and evaluate it with C-M-x > g > M-: (my-test) RET > Result: The debugger appears with an error (wrong-type-argument consp nil) > in edebug-before. It now seems clear the problem is in the def-edebug-spec for backquote-form. It needs to be amended such that the nested ` doesn't simply call backquote-form recursively. Here is my first approximation to a fix. It seems to work for your test case, though I haven't tried it out extensively on anything else. Since my understanding of edebug-specs is incomplete, I'd be grateful if you (or anybody else) could check it out and criticise it. diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el index c898da3d39..46fc3c39b5 100644 --- a/lisp/emacs-lisp/edebug.el +++ b/lisp/emacs-lisp/edebug.el @@ -2165,6 +2165,7 @@ \` ;; but only at the top level inside unquotes. (def-edebug-spec backquote-form (&or + ("`" nested-backquote-form) ([&or "," ",@"] &or ("quote" backquote-form) form) ;; The simple version: ;; (backquote-form &rest backquote-form) @@ -2180,6 +2181,14 @@ backquote-form (vector &rest backquote-form) sexp)) +(def-edebug-spec nested-backquote-form + (&or + ([&or "," ",@"] backquote-form) + (nested-backquote-form [&rest [¬ "," ",@"] nested-backquote-form] + . [&or nil nested-backquote-form]) + (vector &rest nested-backquote-form) + sexp)) + ;; Special version of backquote that instruments backquoted forms ;; destined to be evaluated, usually as the result of a ;; macroexpansion. Backquoted code can only have unquotes (, and ,@) > The sample code above is a much simplified version of the > implementation of ert.el's 'should' macro, which Edebug does not > instrument correctly. > While this nested backquote construction is a valid use of backquote, > and Edebug should be fixed to handle it correctly, I think that this > is a case where backquote makes readability worse instead of better > and the code in ert.el would be more readable if `(,,fn ,@,args) was > replaced by a non-backquoted way of doing the same thing, such as > (cons ,fn ,args). > In GNU Emacs 26.0.91 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.21) > of 2018-04-03 built on localhost > Windowing system distributor 'The X.Org Foundation', version 11.0.11905000 [ .... ] -- Alan Mackenzie (Nuremberg, Germany).