From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philipp Stephani Newsgroups: gmane.emacs.bugs Subject: bug#42701: 28.0.50; Duplicate Edebug instrumentation of lambda form in some cases Date: Sun, 9 Aug 2020 16:59:57 +0200 Message-ID: References: <20200804201258.73145.qmail@mail.muc.de> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37998"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 42701@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Aug 09 17:01:13 2020 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 1k4moz-0009o4-0B for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 09 Aug 2020 17:01:13 +0200 Original-Received: from localhost ([::1]:54056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k4mox-0005gi-EA for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 09 Aug 2020 11:01:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53448) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k4moo-0005gR-6G for bug-gnu-emacs@gnu.org; Sun, 09 Aug 2020 11:01:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49953) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k4mon-0007re-TL for bug-gnu-emacs@gnu.org; Sun, 09 Aug 2020 11:01:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1k4mon-0007Cg-NN for bug-gnu-emacs@gnu.org; Sun, 09 Aug 2020 11:01:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philipp Stephani Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 09 Aug 2020 15:01:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42701 X-GNU-PR-Package: emacs Original-Received: via spool by 42701-submit@debbugs.gnu.org id=B42701.159698521927627 (code B ref 42701); Sun, 09 Aug 2020 15:01:01 +0000 Original-Received: (at 42701) by debbugs.gnu.org; 9 Aug 2020 15:00:19 +0000 Original-Received: from localhost ([127.0.0.1]:33266 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k4mo6-0007BW-PW for submit@debbugs.gnu.org; Sun, 09 Aug 2020 11:00:19 -0400 Original-Received: from mail-ot1-f47.google.com ([209.85.210.47]:43795) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k4mo2-0007BD-TD for 42701@debbugs.gnu.org; Sun, 09 Aug 2020 11:00:16 -0400 Original-Received: by mail-ot1-f47.google.com with SMTP id r21so5324197ota.10 for <42701@debbugs.gnu.org>; Sun, 09 Aug 2020 08:00:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hyzlnIEe8QYAexZnLI8y5Xwc7OJ4BSWLC7is8J1waM4=; b=A4UzECvhotbXLVHGisVYXmqquNcwdyG4ewkoFzg4z+3U5rZk6HjlBlDRjuIHWNuWUc KUeLasLeGuHL8ZvcikeZIZMaEOeFy94UBLOBOTSZwnxudW7Xm+b/mabvAIJ+JVkyXgPP misqNCPgDVTFuK7be8jWX1oI4RgOxX2XOz/qgpERwEshp86GU38LbI3IUVk/fb8m6BtV nU0MpCdgZuPiDE3XnnXTLxOPW2t1T/1D/3FIl3kEjjCs4UG0Ta9+i88J4OT1/P0dOB23 LL43as5b5YI/8KtqvEKzYMadXtGVhu3zpPk1AimZ13TvLfK5ep2zwFBqAkTxHAVQFXbC sUzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hyzlnIEe8QYAexZnLI8y5Xwc7OJ4BSWLC7is8J1waM4=; b=CJvXyCQbKJ710Ra+qFDul+MDeJbqeFVF1+D6IXrbN76zEybLnSJCsttad5pKDQPLMT cxHsAw5jUEcqqR6O2lAZb4FTqVZd+Ag0WiqQpZLjVdG/lgDlzVTnbHEBYbe+QIUiVpbV dfz3Oo/c2oChOkF0GbJwjmzI/FTbWdeNcpH/Cj51QGfRjyPs+sBGnnUzZRZFirwSwh2w S0yG26s5f7KglCLSdtCFR+fbKTSs6HWY+WMYBwoG4FXN/qKrep2BudQt4RZOUc+SqQDg G+UJMIiqsxUa7uTLQgfTvrSP9Cx3jUTV86lJaCNKupsk3LLrAT4EAFF343MMwCBNSwMn oZPg== X-Gm-Message-State: AOAM532bnS0E4nrY2dSnVIkTYFHAiY3oeBazi/QU/D49odCTDpowI1aC 60Hwn0Pxr9GIl+MWPwQVNEKWennzu+Bg97q/by43UjUc X-Google-Smtp-Source: ABdhPJyRWjuS+dmYAt/fM5xR0hQjfT1d6gZkTrcjqNAQ0np8btaUlV+Wkyk92BXpNbT9gt3E3/sM6kz5/RhzEx+s31c= X-Received: by 2002:a9d:170c:: with SMTP id i12mr19758329ota.36.1596985208859; Sun, 09 Aug 2020 08:00:08 -0700 (PDT) In-Reply-To: <20200804201258.73145.qmail@mail.muc.de> 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:184429 Archived-At: ) Am Di., 4. Aug. 2020 um 22:12 Uhr schrieb Alan Mackenzie : > > Hello, Philipp. > > In article you wrote: > > > Create a file /tmp/edebug.el: > > > $ cat /tmp/edebug.el > > (defun f () (if-let (x (funcall (lambda (y) 1) 2)) 3 4)) > > > Visit the file: > > > $ emacs -Q -l subr-x -l edebug /tmp/edebug.el > > > Now instrument the function `f' using C-u C-M-x. The *Messages* buffer > > will now contain > > > Edebug: edebug-anon0 [2 times] > > Edebug: f > > > The [2 times] indicates the problem: Edebug has instrumented two > > definitions with the same (generated) symbol. > > I don't think you're correct, here. I think it's instrumented the > lambda form twice, once for each arm of the edebug spec. It discards > the first attempt, then succeeds at the second. > > The pertinent edebug spec (from the if-let definition in subr-x.el) > looks like: > > ([&or (&rest [&or symbolp (symbolp form) (form)]) > (symbolp form)] > form body) > > . In the outer &or sub-spec, the (&rest ....) bit doesn't match, but > the failure to match only happens after the "Edebug: edebug-anon0" > message has been output the first time. Edebug then tries the (symbolp > form) alternative, which does match and outputs the "...-anon0" message > a second time. That is correct, but when the match fails, it's already too late: Edebug (in `edebug-make-form-wrapper') has already performed some global mutations such as modifying `edebug-form-data' of the `edebug' property of the newly-generated symbol. These mutations aren't unwound after the first failed match. > > > This is a problem when using Edebug for e.g. coverage instrumentation, > > as the coverage information is attached to the symbol itself (as a > > symbol property), and duplicate symbols when instrumenting code lead > > to subtle errors such as mismatching vector lengths for the position > > of the breakpoints and the hit counts. > > I don't think this is happening (see above), but I admit not having > looked into it all that closely. Do you have any further evidence of > two distinct functions being mapped onto the same generated symbol? I've tried to provide some context in https://lists.gnu.org/archive/html/bug-gnu-emacs/2020-08/msg00574.html. The most common symptom of such duplicate definitions (as defined by "calling `edebug-make-form-wrapper' twice with the same `edebug-def-name'") is https://debbugs.gnu.org/cgi/bugreport.cgi?bug=41853. > > > I'd speculate that this issue is similar to Bug#41988 in that Edebug > > defines instrumented symbols even when backtracking later. In this > > case, Edebug backtracks to the legacy (SYM VAL) form, but has already > > partially matched the ((SYM VAL)) form, including instrumenting the > > lambda form therein. I guess Edebug should perform some kind of > > two-phase instrumentation and instrument subforms only when a form has > > been chosen after backtracking. Since this is somewhat difficult to > > implement without rewriting larger parts of Edebug, it might be more > > feasible to regenerate anonymous symbols after a failed match. > > I don't know why Edebug re-uses the symbol. . My guess is that `edebug-old-def-name' becomes non-nil because the form has already been instrumented (https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/emacs-lisp/edebug.el?id=1a845a672dc73c8e98e6cb9bb734616e168e60ba#n1382). It's then reused in https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/emacs-lisp/edebug.el?id=1a845a672dc73c8e98e6cb9bb734616e168e60ba#n1250. > But beyond the misleading > double message in *Messages*, is there any harm done? Would it be less > confusing if two distinct messages "Edebug: edebug-anon0" and "Edebug: > edebug-anon1" were to be output? The duplicate message is just a symptom of calling `edebug-make-form-wrapper' twice with the same `edebug-def-name' symbol, and attaching various instrumentation data to the symbol. Depending on whether the two definitions are compatible, this can be harmless or lead to subtle issues like https://debbugs.gnu.org/cgi/bugreport.cgi?bug=41853. Therefore in my coverage instrumentation driver I'm rejecting such duplicate instrumentations (https://github.com/phst/rules_elisp/commit/31d30e99c21027c5859782229aebb314ed3cb36c, since it doesn't seem to be possible to predict whether the redefinition would indeed be harmless or trigger https://debbugs.gnu.org/cgi/bugreport.cgi?bug=41853.