Subject: bug#46722: test-map-into fails

From: Stefan Monnier <[email-masked]>
Date: Wed, 05 Jan 2022 11:31:59 -0500

Hi Dick,

dick [2022-01-05 09:01:29] wrote:
> For unclear reasons, the hash-table `cl--generic-dispatchers` keyed off
> raw, unburnished defstructs returns values for non-existent keys.

Hmm... I don't understand what this means concretely.
I'm aware that `cl--generic-dispatchers` can be fiddly (IIRC because
there can be functions in the key), but I still can't figure out what
scenario you're describing nor how it can happen to return values for
non-existent keys.

Could you say a bit more, ideally with something like a trace or
a test case?

[...time passes...]

> I normalized its key to a signature string, and,
>
> for i in {1..300} ; do src/emacs -Q -batch -f batch-byte-compile foo.el
> ; src/emacs -Q -batch -l foo.elc ;  done ;

Oh I think I see what you mean.  I can now reproduce the problem locally
as well, and with the foo.el below I get two different traces:

    (trace-function 'cl--generic-get-dispatcher)
    
    (require 'map)
    (condition-case nil
        (progn
          (map-into nil '(hash-table))
          (with-current-buffer "*trace-output*"
            (write-region nil nil "~/tmp/trace-good.eld")))
      (error
       (with-current-buffer "*trace-output*"
         (write-region nil nil "~/tmp/trace-bad.eld")
         (message "ERROR!!"))))

the two backtraces only differ on the last line.  The good trace
(slightly cleaned up for legibility) ends with:

======================================================================
1 -> (cl--generic-get-dispatcher
      (1 #s(cl--generic-generalizer cl--generic-eql-generalizer 100
            #[385 "<bytecode>" [gethash (cl--generic-eql-used)] 5]
            #[385 "<bytecode>" [eql] 4])
         #s(cl--generic-generalizer cl--generic-t-generalizer 0
            #[385 #2="\300\207" [nil] 3 #1#]
            #[385 #2# [(t)] 3])))
1 <- cl--generic-get-dispatcher:
     #[771 "<bytecode>" [make-hash-table :test eql make-closure
                         #[642 "<bytecode>"
                           [V0 V1 V2 V3 cl--generic-eql-used apply gethash
                            cl--generic-cache-miss 1 append
                            #[385 "<bytecode>" [eql] 4]
                            #[385 "\300\207" [(t)] 3]
                            nil puthash]
                           15]]
                        10]
======================================================================
1 -> (cl--generic-get-dispatcher
      (1 #s(cl--generic-generalizer cl--generic-eql-generalizer 100
            #[385 "<bytecode>" [gethash (cl--generic-eql-used)] 5]
            #[385 "<bytecode>" [eql] 4])
         #s(cl--generic-generalizer cl--generic-head-generalizer 80
            #[385 "<bytecode>" [gethash car-safe (cl--generic-head-used)] 5]
            #[385 "<bytecode>" [head] 4])
         #s(cl--generic-generalizer cl--generic-t-generalizer 0
            #[385 #3="\300\207" [nil] 3]
            #[385 #3# [(t)] 3])))
1 <- cl--generic-get-dispatcher:
     #[771 "<bytecode>" [make-hash-table :test eql make-closure
                         #[642 "<bytecode>"
                           [V0 V1 V2 V3 cl--generic-eql-used
                            cl--generic-head-used apply gethash
                            cl--generic-cache-miss 1 append
                            #[385 "<bytecode>" [eql] 4]
                            #[385 "<bytecode>" [head] 4]
                            #[385 "\300\207" [(t)] 3]
                            nil puthash]
                           16]]
                        10]

whereas in the bad trace, the last returned value is identical to the
previous one (i.e. somehow the `head` dispatcher is absent from the
returned function).

Hmm....

        Stefan