Subject: Re: bug#41988: 28.0.50; Edebug unconditionally instruments definitions with &define specs

From: Philipp Stephani <[email-masked]>
Date: Sun, 4 Apr 2021 20:40:11 +0200

Am So., 21. März 2021 um 15:37 Uhr schrieb Stefan Monnier
<[email-masked]>:
>
> >> - The old spec of `cl-flet` would be broken by such a change, so if we
> >>  want to make such a change, we'd probably want to arrange so that it
> >>  emits a clear warning.
> > Where?  When setting the debug specification (byte-run--set-debug), or in some other place?
>
> The old spec was of the form (or (&define name form) (&define name sexp
> body)), so if we put a gate at `&define`, this will probably fail to even match
> the (&define name sexp body) part.

Correct, this would turn a mismatch into a hard error.

>
> [ Disclaimer: I don't understand the precise semantics of `gate`, tho
>   I do remember using it once via trial-and-error.  So maybe it wouldn't
>   prevent it, but if doesn't prevent it, then it doesn't likely "fix"
>   our problem ;-)  ]

AIUI the semantics of "gate" aren't that complex, it just means "don't
backtrack beyond this point."

>
> >> I'm not sure it's worth the trouble: the pain seems higher than the gain.
> > This bug is rather nasty when it's hit (it took me quite a while to
> > debug/hunt down),
>
> Could you remind me what was this nasty outcome?

The original bug report was
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=41853 (extremely subtle
bug due to mismatch between frequency and offset vector). I don't know
whether that problem would appear here as well, but it's nasty enough
that I'd like to prevent duplicate definitions altogether.

> In the context of
> Edebug the effect is negligible (it just emits a spurious message about
> defining an extra something, but other than that debugging works just fine).

That's only true if edebug-new-definition-function handles the
"duplicate definition" case well. For example, to prevent bug#41853 I
bail out on duplicate definitions in
https://github.com/phst/rules_elisp/blob/b67339e66fed8117dc26d4d2fb2ad321c66a3632/elisp/ert/runner.el#L127-L136;
that doesn't work if this bug isn't fixed.

>
> > so I think it would be reasonable to prevent.  We already
> > disable backtracking for literal symbols, and I think forms that require
> > multiple &define forms with backtracking should be exceedingly rare and can
> > be rewritten as you did with cl-flet.
>
> Emitting a warning would be much more helpful than just silently
> "cut"ting the backtracking.

A gate isn't silent, it would cause a hard error in this case.