* bug#32503: 26.1; Byte-compiled functions don't hash consistently
@ 2018-08-22 19:00 Adam Porter
2018-08-23 1:42 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Adam Porter @ 2018-08-22 19:00 UTC (permalink / raw)
To: 32503
I noticed that byte-compiled functions don't hash consistently. Here's
an ECM from Noam Postavsky
<https://github.com/skeeto/emacs-memoize/pull/10#issuecomment-415066682>:
(let ((obj1 (byte-compile (lambda (x) x)))
(obj2 (byte-compile (lambda (x) x))))
(list (equal obj1 obj2)
(eq obj1 obj2)
(= (sxhash obj1)
(sxhash obj2))))
;=> (t nil nil)
According to "(elisp) Defining Hash":
If two objects OBJ1 and OBJ2 are equal, then ‘(sxhash OBJ1)’ and
‘(sxhash OBJ2)’ are the same integer.
This makes it impossible to use byte-compiled functions as keys or parts
of keys in hash tables. A workaround is to `prin1-to-string` the
byte-compiled function and use that as the key.
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#32503: 26.1; Byte-compiled functions don't hash consistently
2018-08-22 19:00 bug#32503: 26.1; Byte-compiled functions don't hash consistently Adam Porter
@ 2018-08-23 1:42 ` Tom Tromey
0 siblings, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2018-08-23 1:42 UTC (permalink / raw)
To: Adam Porter; +Cc: 32503
Adam> I noticed that byte-compiled functions don't hash consistently.
The Lisp_Vectorlike case in Fequal has a number of special cases which
don't seem to be reflected in sxhash:
if (OVERLAYP (o1))
[...]
if (MARKERP (o1))
[...]
if (WINDOW_CONFIGURATIONP (o1))
[...]
/* Aside from them, only true vectors, char-tables, compiled
functions, and fonts (font-spec, font-entity, font-object)
are sensible to compare, so eliminate the others now. */
(Bignums and bool vectors are special-cased as well but are handled in
sxhash.) This is followed by code to loop over the pseudovector's
elements.
However, the Lisp_Vectorlike case in sxhash doesn't do any of this.
Probably there should be a rule that adding a new type should
necessitate adding a new hasher (much like how print syntax is needed);
or certainly if the type has non-trivial equal behavior.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#32503: 26.1; Byte-compiled functions don't hash consistently
2020-03-09 3:26 ` Eli Zaretskii
@ 2021-06-24 16:30 ` Lars Ingebrigtsen
0 siblings, 0 replies; 3+ messages in thread
From: Lars Ingebrigtsen @ 2021-06-24 16:30 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 32503, niwtrx, Adam Porter, 38912
Eli Zaretskii <eliz@gnu.org> writes:
>> Sorry, haven't had a chance to look at it yet. I've been treating it as
>> low-ish priority because pdumping outside loadup isn't supported yet. Is
>> there some reason to expedite this work?
>
> Not that I can see, no. I just wanted to be sure this isn't
> forgotten.
>
> Thanks.
This was a long thread, and I only skimmed it lightly. But I noticed
that it was merged with this bug report:
Adam Porter <adam@alphapapa.net> writes:
> I noticed that byte-compiled functions don't hash consistently. Here's
> an ECM from Noam Postavsky
> <https://github.com/skeeto/emacs-memoize/pull/10#issuecomment-415066682>:
>
> (let ((obj1 (byte-compile (lambda (x) x)))
> (obj2 (byte-compile (lambda (x) x))))
> (list (equal obj1 obj2)
> (eq obj1 obj2)
> (= (sxhash obj1)
> (sxhash obj2))))
> ;=> (t nil nil)
And this test case no longer fails in Emacs 28 (but it fails in Emacs
27). So is there more to be done in these merged bug reports?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-06-24 16:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-22 19:00 bug#32503: 26.1; Byte-compiled functions don't hash consistently Adam Porter
2018-08-23 1:42 ` Tom Tromey
-- strict thread matches above, loose matches on Subject: below --
2020-01-04 1:49 bug#38912: 27.0.60; PDumper meets segmentation fault when evil is loaded NiwTinray via Bug reports for GNU Emacs, the Swiss army knife of text editors
2020-01-04 9:17 ` Eli Zaretskii
[not found] ` <D1473DD8-48F8-4204-80B5-BE6396B8B668@icloud.com>
2020-01-05 18:45 ` Eli Zaretskii
2020-01-06 17:10 ` Daniel Colascione
2020-03-05 7:14 ` Eli Zaretskii
2020-03-09 2:15 ` Daniel Colascione
2020-03-09 3:26 ` Eli Zaretskii
2021-06-24 16:30 ` bug#32503: 26.1; Byte-compiled functions don't hash consistently Lars Ingebrigtsen
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).