Subject: bug#51026: 29.0.50; Edebug leaves data in symbols plist after instrumentation

From: Arthur Miller <[email-masked]>
Date: Tue, 05 Oct 2021 13:17:48 +0200

Lars Ingebrigtsen <[email-masked]> writes:

> Arthur Miller <[email-masked]> writes:
>
>> +(defun edebug--strip-plist (symbol)
>> +  "Remove edebug related properties from SYMBOL's plist."
>> +  (dolist (prop '(edebug edebug-behavior edebug-coverage
>> +                         edebug-form-spec edebug-freq-count
>> +                         ghost-edebug))
>> +    (cl-remprop symbol prop)))
>
> This will break edebug -- edebug-form-spec is set when loading
> edebug.el, it's not something that happens when you instrument a
> function.

Ahh that pcase in the niddle of nowhere; what does it do there? Why is it not in
some "init" function? :-)

Yes, it is true what you say, but only for a handful of symbols, not even all of
those handled in that pcase. I think it is emitted only for let, let*, setq and
quote, but it is not important. See attached patch, if it is acceptable. It will
check if a symbol is one of those specially treated and do nothing for those.

I think that is what you mean? I don't see any other place that adds properties
and I don't see any edebug properties in "random" symbols unless instrumented.

> I don't know about the other symbols.

That seems to be the only one added automatically.

>From 508dea329d8ef389b6b07d6339faf753d746ff16 Mon Sep 17 00:00:00 2001
From: Arthur Miller <[email-masked]>
Date: Tue, 5 Oct 2021 13:07:07 +0200
Subject: [PATCH] Clean edebug props on instrumentation removal

* lisp/emacs-lisp/edebug.el (edebug--strip-plist): New function.
(edebug-remove-instrumentation): Added call to 'edebug--strip-plist'.
---
 lisp/emacs-lisp/edebug.el | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el
index a38c8bd5ca..97869a2bb9 100644
--- a/lisp/emacs-lisp/edebug.el
+++ b/lisp/emacs-lisp/edebug.el
@@ -4529,6 +4529,15 @@ edebug--unwrap*-symbol-function
         (was-macro               `(macro . ,unwrapped))
         (t                       unwrapped))))))
 
+(defun edebug--strip-plist (symbol)
+  "Remove edebug related properties from SYMBOL's plist."
+  (unless (memq symbol '(quote defvar defconst defun defmacro function
+                               let let* setq cond condition-case \` \, \,@))
+    (dolist (prop '(edebug edebug-behavior edebug-coverage
+                           edebug-form-spec edebug-freq-count
+                           ghost-edebug))
+      (cl-remprop symbol prop))))
+
 (defun edebug-remove-instrumentation (functions)
   "Remove Edebug instrumentation from FUNCTIONS.
 Interactively, the user is prompted for the function to remove
@@ -4560,6 +4569,7 @@ edebug-remove-instrumentation
   (dolist (symbol functions)
     (when-let ((unwrapped
                 (edebug--unwrap*-symbol-function symbol)))
+      (edebug--strip-plist symbol)
       (defalias symbol unwrapped)))
   (message "Removed edebug instrumentation from %s"
            (mapconcat #'symbol-name functions ", ")))
-- 
2.33.0