Subject: Re: bug#67455: (Record source position, etc., in doc strings, and use this in *Help* and backtraces.)

From: Stefan Monnier <[email-masked]>
Date: Sun, 10 Mar 2024 13:19:03 -0400

> I've got a version almost ready which actually does something, namely
> prefixes "anonymous" lines of a backtrace with the name of the defining
> symbol, like {foo} .  It'll soon be time to start seriously thinking
> about what information ought to go there for the live version.

Cool!

>> - Testing `byte-compile-in-progress` can't be right.  Do you to test
>>   whether the result of this backquote will be byte-compiled or do you
>>   really mean to test whether this backquote happens to be executed
>>   during compilation (which could be because the compiler ends up
>>   loading code while executing `eval-when-compile` or `require`)?
>
> Quite simply, during compilation, all symbols (except nil) get read with
> position, so to strip their positions here would be wrong.

This isn't quite right: during compilation, some code is read with
positions (the code that we will compile), but some code is read in the
normal way (the code we load for the purpose of running).
The distinction is important.

>> - My gut tells me that changing backquote can't be right.
>
> I tend to agree.  I put the code into backquote-process when having
> problems with things like:
>
>        (mapatoms #'(lambda (,(car spec)) ,@body)
>
> in cl-macs.el, where it's impossible to know where the doc string (if
> any) is until after the expansion of the backquotes, or even at run time
> (as here).  In the latter case, rather than "posifying" the doc string
> at macro expansion time, we have to generate code to do it at run time.

Hmm... here what you call "run time" is really some later
macro-expansion, right?  The `lambda` symbol comes from the first
macro-expansion (ME1), but the docstring comes from the second (ME2).

IIUC the problem you face is that you want to get the function's
position info from the `lambda` symbol, which here would be wrong (even if we
try to preserve it long enough), is that it?

[ Tho, in more complex cases it becomes debatable whether the function's
  position should point to the position corresponding to ME1 or to that
  of ME2.  ]

More generally: what goes wrong in the above example if you just treat
that as a list of symbol (stripping them all of their position info).
AFAICT when *that* macro is expanded (i.e. ME2) you'll presumably get
code like

    (mapatoms #'(lambda (FOO/p) (DO/p SOME/p (THING/p))))

right?  [ where "/p" means that the symbol has a sympos.  ]
Isn't that sufficient info to add a docstring with position?

>>   (lambda (f) ..) *can* appear within a backquote without it being an
>>   actual lambda expression.
>>   What alternatives have you considered?
> Not a lot of them, as yet.  Maybe testing for (function (lambda ...))
> would be safer.

No matter how many extra tests you add to reduce the frequency, you're
fundamentally adding a bug :-(

        Stefan