Subject: Re: bug#56643: 29.0.50; Help-mode bookmarks not loading with native compilation

From: Andrea Corallo <[email-masked]>
Date: Wed, 20 Jul 2022 09:51:17 +0000

"defun.foo--- via \"Bug reports for GNU Emacs, the Swiss army knife of
text editors\"" <[email-masked]> writes:

> I dug into that a little when I was trying to find a work-around. It looks like help-mode maintains a stack of previously-visited help items which is what enables users to jump back and forth between different items they've viewed. From "C-h v help-xref-stack":
>
> "A stack of ways by which to return to help buffers after following xrefs.
> Used by ‘help-follow-symbol’ and ‘help-xref-go-back’.
> An element looks like (POSITION FUNCTION ARGS...).
> To use the element, do (apply FUNCTION ARGS) then goto the point."
>
> So basically the FUNCTION element is a recipe for recreating a specific help item, and "help-bookmark-make-record" just drops that FUNCTION element intact into "help-fn" when creating a bookmark:
>
> `(,@(bookmark-make-record-default 'NO-FILE 'NO-CONTEXT)
>       (help-fn     . ,(car help-xref-stack-item))
>       (help-args   . ,(mapcar (lambda (a)
>                                 (if (bufferp a) (buffer-name a) a))
>                               (cdr help-xref-stack-item)))
>       (position    . ,(point))
>       (handler     . help-bookmark-jump))
>
> The catch is that every function that generates a help buffer also defines its own way of setting up an xref stack item. Some pass in a symbol while some pass in a lambda, so after a while the stack might end up looking like this:
>
> ((1 #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_20>
>     (("" .
>       [24 3]))
>     #<buffer *Help*>)
>  (232 describe-variable help-xref-stack #<buffer *Help*>)
>  (1 #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_7> describe-package #<buffer *Help*>))
>
> Then when bookmark.el saves all the bookmarks ("bookmark-write-file"), it just calls "pp" on each one:
>
> (dolist (i bookmark-alist) (pp i (current-buffer)))
>
> which apparently is able to create a readable representation of byte-compiled lambdas, but not native-compiled ones.
>
> And that's where my knowledge ends. :) I have very little C programming experience and have no idea if it's even possible to serialize a compiled thing into something the reader can understand, or whether there's some processing help-mode could do on each function before it even becomes part of a bookmark.

It is unfortunatelly not possible to serialize native compiled code so
that the reader can read it back.  Native code can only stay in shared
libraries (eln files) and be loaded from there.

Not sure if help-mode can use a different strategy.

BR

  Andrea