GNU bug report logs - #32503
26.1; Byte-compiled functions don't hash consistently

Previous Next

Package: emacs;

Reported by: Adam Porter <adam <at> alphapapa.net>

Date: Wed, 22 Aug 2018 19:01:02 UTC

Severity: normal

Merged with 38912

Found in versions 26.1, 27.0.60

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 32503 in the body.
You can then email your comments to 32503 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#32503; Package emacs. (Wed, 22 Aug 2018 19:01:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Adam Porter <adam <at> alphapapa.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 22 Aug 2018 19:01:04 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Adam Porter <adam <at> alphapapa.net>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.1; Byte-compiled functions don't hash consistently
Date: Wed, 22 Aug 2018 14:00:28 -0500
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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32503; Package emacs. (Thu, 23 Aug 2018 01:43:02 GMT) Full text and rfc822 format available.

Message #8 received at 32503 <at> debbugs.gnu.org (full text, mbox):

From: Tom Tromey <tom <at> tromey.com>
To: Adam Porter <adam <at> alphapapa.net>
Cc: 32503 <at> debbugs.gnu.org
Subject: Re: bug#32503: 26.1; Byte-compiled functions don't hash consistently
Date: Wed, 22 Aug 2018 19:42:12 -0600
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




Merged 32503 38912. Request was from Eli Zaretskii <eliz <at> gnu.org> to control <at> debbugs.gnu.org. (Mon, 06 Jan 2020 18:32:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32503; Package emacs. (Thu, 24 Jun 2021 16:31:01 GMT) Full text and rfc822 format available.

Message #13 received at 32503 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 32503 <at> debbugs.gnu.org, niwtrx <at> icloud.com,
 Daniel Colascione <dancol <at> dancol.org>, Adam Porter <adam <at> alphapapa.net>,
 38912 <at> debbugs.gnu.org
Subject: Re: bug#32503: 26.1; Byte-compiled functions don't hash consistently
Date: Thu, 24 Jun 2021 18:30:26 +0200
Eli Zaretskii <eliz <at> 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 <at> 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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32503; Package emacs. (Thu, 28 Apr 2022 11:42:01 GMT) Full text and rfc822 format available.

Message #16 received at 32503 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 32503 <at> debbugs.gnu.org, niwtrx <at> icloud.com,
 Daniel Colascione <dancol <at> dancol.org>, Adam Porter <adam <at> alphapapa.net>,
 38912 <at> debbugs.gnu.org
Subject: Re: bug#38912: 27.0.60; PDumper meets segmentation fault when evil
 is loaded
Date: Thu, 28 Apr 2022 13:41:02 +0200
Lars Ingebrigtsen <larsi <at> gnus.org> 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?

There wasn't any response in 43 weeks, so it seems like the issue has
been fixed for Emacs 28, and I'm therefore closing it.  If there are
other problems in this area, I think it would be better to open a new
bug report for those problems.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug closed, send any further explanations to 38912 <at> debbugs.gnu.org and NiwTinray <niwtrx <at> icloud.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Thu, 28 Apr 2022 11:42:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 27 May 2022 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 306 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.