Subject: bug#75188: closed (Re: bug#75188: persist.el should recursively copy hash tables)

From: [email-masked] (GNU bug Tracking System)
Date: Thu, 13 Feb 2025 09:55:02 +0000

Your bug report

#75188: persist.el should recursively copy hash tables

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].

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

Subject: Re: bug#75188: persist.el should recursively copy hash tables
From: Stefan Kangas <[email-masked]>
To: Eli Zaretskii <[email-masked]>
Cc: [email-masked], [email-masked], Joseph Turner <[email-masked]>, [email-masked], [email-masked], [email-masked], [email-masked]
Date: Thu, 13 Feb 2025 01:54:11 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

Eli Zaretskii <[email-masked]> writes:

>> From: Joseph Turner <[email-masked]>
>> Cc: [email-masked],  [email-masked],  [email-masked],
>>   [email-masked],  [email-masked],
>>   [email-masked]
>> Date: Mon, 27 Jan 2025 18:08:57 -0800
>>
>> Eli Zaretskii <[email-masked]> writes:
>>
>> >> From: Joseph Turner <[email-masked]>
>> >> Cc:  Daniel Mendler <[email-masked]>,
>> >> 	Ihor Radchenko <[email-masked]>,
>> >> 	Stefan Monnier <[email-masked]>,
>> >> 	Adam Porter <[email-masked]>, Eli Zaretskii <[email-masked]>,
>> >> 	[email-masked]
>> >> Date: Tue, 31 Dec 2024 14:12:00 -0800
>> >>
>> >> > Hello!
>> >> >
>> >> > This patch demonstrates a bug in persist.el
>> >>
>> >> [...]
>> >>
>> >> This issue also relates to the bug#63513, in which the suggestion was
>> >> made to replace persist-copy-tree with (compat-call copy-tree) now that
>> >> Compat 30 is available:
>> >>
>> >> https://yhetil.org/emacs-bugs/[email-masked]/
>> >
>> > Thanks, would you like to submit a patch along those lines?
>>
>> Please see patch:
>
> LGTM.  Phillip, would you please install?

I'm not Phillip, but I installed the patch now.  Closing.

Subject: persist.el should recursively copy hash tables
From: Joseph Turner <[email-masked]>
To: [email-masked]
Date: Mon, 30 Dec 2024 01:05:30 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello!

This patch demonstrates a bug in persist.el, which may be the cause of
https://github.com/alphapapa/activities.el/issues/109 and a similar bug
in hyperdrive.el which causes the `persist' variable file to be deleted.
We have not yet found a way to reproduce the bug in either activities.el
or hyperdrive.el, so this `persist' bug may be unrelated.

>From c28644c957d9fabf883990ff145cec19ed12ff10 Mon Sep 17 00:00:00 2001
From: Joseph Turner <[email-masked]>
Date: Mon, 30 Dec 2024 00:40:33 -0800
Subject: [PATCH] Test that persist-copy recursively copies hash tables

---
 test/persist-tests.el | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/test/persist-tests.el b/test/persist-tests.el
index 6bf2ed3708..adf37a5bf0 100644
--- a/test/persist-tests.el
+++ b/test/persist-tests.el
@@ -151,3 +151,14 @@ (ert-deftest test-persist-reset ()
      (should-not (eq persist--test-reset-variable initial-value))
      (should-not (eq initial-value
                      (persist-default 'persist--test-reset-variable))))))
+
+(ert-deftest test-persist-copy-hash-table ()
+  "`persist-copy' should copy hash keys and values."
+  (let* ((hash (make-hash-table))
+         (rec (record 'a))
+         (_ (puthash 'foo rec hash))
+         (copy-hash (persist-copy hash)))
+    (setf (aref (gethash 'foo copy-hash) 0) 'b)
+    (should-not (persist-equal hash copy-hash))
+    (should-not (eq (gethash 'foo hash)
+                    (gethash 'foo copy-hash)))))
-- 
2.46.0

IIUC, the solution requires rewriting `persist-copy-tree' (which is
copied from Emacs 30's `copy-tree') so that it handles hash tables.  If
you all agree, I can do this in `persist.el`.

However, would it make sense for `copy-tree' to handle hash tables?

Forgive me if this has been discussed and settled before.  I did find
this thread about comparing hash tables with `equal':

https://yhetil.org/emacs-devel/871qvz4kdw.fsf@localhost/

Thank you!

Joseph