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#41988: 28.0.50;
Edebug unconditionally instruments definitions with &define specs
Date: Sun, 9 Aug 2020 13:33:53 +0200
Message-ID:
References:
<20200621234816.88427.qmail@mail.muc.de>
<20200808145948.GA10181@ACM>
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="15286"; mail-complaints-to="usenet@ciao.gmane.io"
Cc: 41988@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 13:40:07 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 1k4jgN-0003qE-8G
for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 09 Aug 2020 13:40:07 +0200
Original-Received: from localhost ([::1]:55362 helo=lists1p.gnu.org)
by lists.gnu.org with esmtp (Exim 4.90_1)
(envelope-from )
id 1k4jgM-00021D-9t
for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 09 Aug 2020 07:40:06 -0400
Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50668)
by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
(Exim 4.90_1) (envelope-from )
id 1k4jbS-0000xs-2S
for bug-gnu-emacs@gnu.org; Sun, 09 Aug 2020 07:35:02 -0400
Original-Received: from debbugs.gnu.org ([209.51.188.43]:48592)
by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
(Exim 4.90_1) (envelope-from )
id 1k4jbR-0003L0-P2
for bug-gnu-emacs@gnu.org; Sun, 09 Aug 2020 07:35:01 -0400
Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
(envelope-from ) id 1k4jbR-0003KG-MU
for bug-gnu-emacs@gnu.org; Sun, 09 Aug 2020 07:35: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 11:35: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.159697285212668
(code B ref 41988); Sun, 09 Aug 2020 11:35:01 +0000
Original-Received: (at 41988) by debbugs.gnu.org; 9 Aug 2020 11:34:12 +0000
Original-Received: from localhost ([127.0.0.1]:60138 helo=debbugs.gnu.org)
by debbugs.gnu.org with esmtp (Exim 4.84_2)
(envelope-from )
id 1k4jad-0003IG-LW
for submit@debbugs.gnu.org; Sun, 09 Aug 2020 07:34:12 -0400
Original-Received: from mail-ot1-f54.google.com ([209.85.210.54]:33805)
by debbugs.gnu.org with esmtp (Exim 4.84_2)
(envelope-from ) id 1k4jab-0003I1-VD
for 41988@debbugs.gnu.org; Sun, 09 Aug 2020 07:34:10 -0400
Original-Received: by mail-ot1-f54.google.com with SMTP id k12so5139775otr.1
for <41988@debbugs.gnu.org>; Sun, 09 Aug 2020 04:34:09 -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=6fal7yEZr6AvDAgOfOLLinsHTt4+laJj/uoBiDOQWJQ=;
b=QwwZ2Y/rv58PHS7+nMa2odXa7VwvpJDMjllr7wd+PbtEBNvo0h/FsNkeRMA6OnvWgb
aEqTPi4fUQ+XIqnZ8xl6tssukstsxoF/FSU7VGEwTCMGfyA75s8HEe2h/I7P/ymAwPFR
WMwkNkGshMatKCOqJ5qiuxkuGDnEwmLFsr0MMqBjLbmK6GJs5f4Ojqo1A+LBaP+YywJa
drNf3mhdm0MIE3/x7YMFSktgnYowcg6EXcTybCXbXI95mhAtieXYeT0kgI+8hfFQN/XX
16npDqoH9Q9rihVTKSfnKRq2hw0xJ4QDCJlHmxBs0BsaKgsti7NofsBCrz0YhSm4MoVf
vMpw==
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=6fal7yEZr6AvDAgOfOLLinsHTt4+laJj/uoBiDOQWJQ=;
b=IcHNdRv4+xAA2i6uBbFnR/lqPE6pedyoFSyT8Nz1rtYCmXYBP3bqobKHw4nvfmkzWe
7lQdOINVfC4lckZa9rTKuuVR1K6mBeYKg1aoa5UkA4+5ai4EmW8JsFPzyemwV0ICfumF
lixtlIKiJHPnz3w6h0FzdJ6O9f2UPyZJpVfwXjIRHIgsZ0PlTY7KsI2ny6HYmjcu1Dkx
6mC7IFlFlPMj7N3ao8aZTZwpeB86DSCwLprg82dhEzhkpLCy26+axMKrqtPb3oGH/mYj
AAvtAS2o1620h503YRE7MZVSF3hQ9blMver6cmqS27HAUbZv/S7VQXshF9JRnWSMc21i
Ak3Q==
X-Gm-Message-State: AOAM531tfWUVXOO1iSWGw8XK3Adkk6uPSse/LAkT2GJ6Z/sLiclvRlO3
vkvrvS07HnrV8Pwpos4XO3ErkuXLw4jRMZUGDoRdLZG7
X-Google-Smtp-Source: ABdhPJzGDOHTdN878aNjY3oJDEns/jdUV/BzL2td+XunJnBk8W+YO/j6T5LKe85nVNTfnXNXAWtZvLdcKArZgL/KaQg=
X-Received: by 2002:a9d:2203:: with SMTP id o3mr18292377ota.149.1596972844052;
Sun, 09 Aug 2020 04:34:04 -0700 (PDT)
In-Reply-To: <20200808145948.GA10181@ACM>
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:184402
Archived-At:
Am Sa., 8. Aug. 2020 um 16:59 Uhr schrieb Alan Mackenzie :
>
> Hello, Philipp.
>
> I must admit, I'm having difficulty understanding this problem.
>
> On Sat, Aug 08, 2020 at 13:01:50 +0200, Philipp Stephani wrote:
> > Am Mo., 22. Juni 2020 um 01:48 Uhr schrieb Alan Mackenzie :
>
> > > In article you wrote:
>
> > > > As an example, edebug-instrument (C-u C-M-x) the following
> > > > definition:
>
> > > > (defun bar ()
> > > > (cl-flet ((foo () 1))
> > > > (foo)))
>
> > > > The *Messages* buffer now says
>
> > > > Edebug: foo [2 times]
> > > > Edebug: bar
>
> > > > Note the '[2 times]'. I believe this is because
> > > > `edebug-match-&define' calls `edebug-make-form-wrapper'
> > > > unconditionally. The Edebug spec for `cl-flet' has two `&or'
> > > > branches that both use `&define', so if the first one doesn't match
> > > > it will still create a definition using `edebug-make-form-wrapper'.
> > > > Probably `edebug-match-&define' should only invoke
> > > > `edebug-make-form-wrapper' if the specification actually matches.
>
> > > I don't understand why this is a bug. What precisely is wrong with
> > > the messages displayed in *Messages*? Or is it something else which
> > > is wrong?
>
> > > After instrumenting bar, can you actually step through it with
> > > edebug? (I can't try it out myself, since I can't discern from the
> > > documentation what, precisely, cl-flet is supposed to do.)
>
>
> > So this is somewhat subtle, so let me try to give some context. The
> > message is merely a symptom of defining a symbol twice (via
> > edebug-make-form-wrapper). That's a problem when using Edebug for
> > coverage instrumentation (in batch mode), as the coverage information
> > is attached to properties of the symbol that Edebug
> > generates/instruments.
>
> I'm trying to see what, exactly, this problem is. Edebug is defining a
> symbol twice, once for each of two arms of a &or form in the edebug spec.
> The first of these surely does nothing; it will eventually end up in the
> garbage collector. The second will form the function slot of the symbol,
> fulfilling all the Edebug things. What am I missing?
The problem is that Edebug not only generates objects that would later
be garbage-collected (and therefore not observable), but also modifies
observable global state. This starts at
https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/emacs-lisp/edebug.el?id=55bcb3f7e05c01d86778f1a2b7caccf72124614d#n1418
and continues for the rest of the edebug-make-form-wrapper function.
In particular, https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/emacs-lisp/edebug.el?id=55bcb3f7e05c01d86778f1a2b7caccf72124614d#n1444
sets the `edebug' symbol property of the symbol being generated. None
of these mutations are undone when backtracking.
>
> > Instrumenting a symbol with two different definitions can lead to very
> > subtle bugs because the frequency vector and the form offset vector are
> > out of sync, ....
>
> The picture you seem to be painting is of two distinct definitions being
> assigned to the same symbol, and both of them being live. Do you have
> any evidence that this is happening?
Let's say it's rather an incompatible mixture of two definitions.
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=41853 is a symptom of
this. Another piece of evidence is the implementation of
`edebug-make-form-wrapper': that function clearly modifies buffer
contents and symbol properties even in branches that would later be
discarded as part of backtracking.
My (not well evidenced) assumption is that
https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/emacs-lisp/edebug.el?id=55bcb3f7e05c01d86778f1a2b7caccf72124614d#n1427
regenerates the offset vector, but there's no regeneration of the
frequency vector, which is the immediate trigger of
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=41853, since now the
frequency and offset vectors might be incompatible with each other.
But I'd also assume the problem runs deeper: edebug-make-form-wrapper
performs multiple mutations, and it's not really clear which of those
are "safe" w.r.t. multiple definitions in not-taken branches.
>
> > .... see e.g. https://debbugs.gnu.org/cgi/bugreport.cgi?bug=41853.
> > Therefore it's important to prevent such duplicate instrumentation,
> > typically by changing the Edebug symbol in some way (appending a unique
> > suffix, etc.). Edebug does this already in many cases (ERT tests, CL
> > methods, ...), but not always. For some more context, see the coverage
> > instrumentation in my Bazel rules for ELisp
> > (https://github.com/phst/rules_elisp).
> > https://github.com/phst/rules_elisp/blob/master/elisp/ert/runner.el
> > contains the ERT and coverage integration. In
> > https://github.com/phst/rules_elisp/blob/0b24aa1660af2f6c668899bdd78aaba383d7ac18/elisp/ert/runner.el#L133-L134
> > I explicitly check for duplicate instrumentation. It is hard to predict
> > in general whether a specific instance of duplicate instrumentation
> > will lead to bugs like
> > https://debbugs.gnu.org/cgi/bugreport.cgi?bug=41853 or not, thus I'm
> > treating every duplicate instrumentation as a bug.
>
> What exactly do you mean by "duplicate instrumentation"? If a symbol
> gets defined twice, once for each arm of an &or in the edebug spec, does
> that count as a duplicate instrumentation?
What I mean concretely is evaluating `edebug-make-form-wrapper' (and
therefore, mutating symbol properties and buffer contents) once for
each branch of an &or construct.