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.

Full log


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.




This bug report was last modified 3 years and 20 days ago.

Previous Next


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