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

From: Andrea Corallo <[email-masked]>
Date: Fri, 22 Jul 2022 13:41:32 +0000

Eli Zaretskii <[email-masked]> writes:

>> Date: Thu, 21 Jul 2022 10:01:57 +0000
>> From: [email-masked]
>> Cc: Michael Heerdegen <[email-masked]>, [email-masked], [email-masked]
>> 
>> > > Alternatively we could introduce a named helper function. Note there
>> > > are more calls of `help-setup-xref' using lambdas in arguments.
>> >
>> >
>> > And that would solve the problem? Did you try that?
>> 
>> I tried it with describe-function and it does solve the problem,
>> although as noted above there are many other functions that generate
>> help buffers and pass in a lambda.
>
> I know very well there are other instances, I just wanted us to stay
> focused.
>
>> Named helper:
>> 
>> (defun describe-function-xref-func (function buffer)
>>   (let ((describe-function-orig-buffer
>>                     (if (buffer-live-p buffer) buffer)))
>>                (describe-function function)))
>> 
>> Revised describe-function snippet:
>> 
>>     (help-setup-xref
>>      (list 'describe-function-xref-func function describe-function-orig-buffer)
>>      (called-interactively-p 'interactive))
>> 
>> This produces the following bookmark, which I confirmed still works after restarting Emacs:
>> 
>> ("named-function-help-bookmark"
>>  (position . 1)
>>  (last-modified 25305 7198 806743 243000)
>>  (help-fn . describe-function-xref-func)
>>  (help-args completing-read "*scratch*")
>>  (position . 1)
>>  (handler . help-bookmark-jump))
>
> Thanks.  If Andrea confirms that this won't have any problems with
> native-compilation, I will install such changes on the release branch
> (since AFAIU this issue is a regression in Emacs 28).

I confirm it should just work.

Actually I think the use of a lambda there was not really optimal in
first place as is not capturing anything and we were serializing and
deserializing the same code over and over again for no good reason.

BTW, I mention this for other similar cases, another fix would be to add
(declare (speed -1)) to `describe-function'.  Ideally would be _really_
nice to add it directly to the lambda we want to be able to
se/deserialize, but AFAIK the declare semantinc is not available to
lambdas :( Probably an improvement to keep in mind...

Thanks

  Andrea