Subject: bug#76546: closed (Re: bug#76546: 30.1; Native compilation is corrupting lambdas/closures stored in variables after some time)

From: [email-masked] (GNU bug Tracking System)
Date: Tue, 20 May 2025 17:28:02 +0000

Your bug report

#76546: 30.1; Native compilation is corrupting lambdas/closures stored in variables after some time

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
76546: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=76546
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#76546: 30.1; Native compilation is corrupting lambdas/closures stored in variables after some time
From: Stefan Monnier <[email-masked]>
To: Eli Zaretskii <[email-masked]>
Cc: Christian Johansson <[email-masked]>, [email-masked], [email-masked]
Date: Tue, 20 May 2025 13:26:48 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

>> I have a discussion with Stefan Monnier about this, this seems to be a
>> feature and not a bug, the printing of lambdas has been limited in new
>> Emacs version to avoid this issue I think
> Was the discussion with Stefan off-list?

My best guess is that he's referring to

    https://lists.gnu.org/archive/html/emacs-devel/2025-05/msg00133.html

> Stefan, should I close this bug, then?

I think so, mostly because there is no actionable element in it: no
clear description of what was the problem and even less info about how
to reproduce it.

        Stefan

Subject: 30.1; Native compilation is corrupting lambdas/closures stored in variables after some time
From: Christian Johansson <[email-masked]>
To: [email-masked]
Date: Tue, 25 Feb 2025 11:27:58 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello!

There is something fishy going on, but it is a very slippery bug, I have 
trouble reproducing it but it started to happen when native compilation 
was introduced and it has significantly gotten worse with Emacs 30, I 
never happened before native-compilation was introduced.

Maybe you can give me some tips in building a reproducible test case? I 
will try to explain what happens. So prior to Emacs 30 there was only 
one bug I stumbled upon:

1. When a lambda is stored in a variable in a lexical scoped file it 
stores a closure. After some time when native compilation has done its 
magic on the variable you will get an error when you try to output it 
like this:
(format "%S" my-native-compiled-variable) and Emacs crashes.

This happened every time my parser-generator library ran for a long time 
and then tried to output a parser file. The only solution to this was to 
not byte-compile the file that contained the lambdas that was later 
supposed to be printed to a file, this solution worked but it was a 
workaround due to this bug.

2. After Emacs 30 it seems to corrupt strings with escape sequences 
inside lambdas inside variables, like this:

(setq my-lambda (lambda() (looking-at "<\\?=")))

After native-compilation has performed its magic on the variable the 
function body will become corrupted and it will become a invalid 
function body. This happens now to my major my phps-mode, I have 
reproduced the error on two machines with Emacs 30 and it has never 
occurred before Emacs 30 and there has been no recent changes to the 
plugin. If I just eval the function files anew the problem disappears so 
it only happens in compiled files. It however does not happen in 
byte-compiled files, only in native compiled files.

Kind regards
Christian