Subject: Re: bug#61962: 30.0.50; New trouble with symbols with positions

From: Alan Mackenzie <[email-masked]>
Date: Mon, 6 Mar 2023 13:22:31 +0000

Hello, Michael.

On Sun, Mar 05, 2023 at 20:41:48 +0100, Michael Heerdegen wrote:
> Alan Mackenzie <[email-masked]> writes:

> > I disagree with your concept here.  Warning positions are not accurate
> > or inaccurate (they cannot be +- 2%, for example), they are either
> > correct or they are wrong.  A lot of effort was put into making them
> > correct, although it is clear from this bug that that project is as yet
> > incomplete.

> This was not intended to sound like it did to you.  I see the
> exact compiler warning positions as a big improvement.

Sorry, I overreacted there.

> > Please don't revert that commit from 2023-02-17.  I will look into
> > this and try to fix the bug properly.

> I wanted to spare others from seeing these hard to interpret errors
> this commit introduces.  Anyway, take your time, a few days won't hurt.

I think I now understand what's going on.  It's all to do with stripping
symbol positions in eval-and-compile forms.  Before the patch of ~two
weeks ago, the positions were stripped in e-and-c.  After the patch,
they weren't stripped.

I think the correct thing to do is to strip the symbol positions in the
`eval' part of eval-and-compile, but leave them alone in the `compile'
part.  This is actually quite tricky, since
byte-run-strip-symbol-positions works destructively.  So I need to copy
the code first, and there is no suitable function to do this.  copy-tree
is close, but can't handle circular lists.  So I will have to write a
safe version of copy tree.

In the mean time, could you try out the following patch which uses
copy-tree as a first approximation.  I think it fixes the problem, apart
from the above.

Thanks!

diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 6f3d7a70903..30f58eeb731 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -533,7 +533,9 @@ byte-compile-initial-macro-environment
                                       (macroexpand--all-toplevel
                                        form
                                        macroexpand-all-environment)))
-                                (eval expanded lexical-binding)
+                                (eval (byte-run-strip-symbol-positions
+                                       (copy-tree expanded))
+                                      lexical-binding)
                                 expanded)))))
     (with-suppressed-warnings
         . ,(lambda (warnings &rest body)

> Michael.

-- 
Alan Mackenzie (Nuremberg, Germany).