Re: [Sbcl-commits] master: Pass 2 args to adaptive-equal-hash
Gábor Melis <[email protected]>
| Newsgroups | gmane.lisp.steel-bank.devel |
|---|---|
| Message-ID | <CADJFn4UYW3rbfNTVMYEoKQM+h65sroCb5XjNAqy9XSSrS2Ci2A@mail.gmail.com> |
Regarding the FIXNUM vs SIGNED-WORD thing, the defstruct for HASH-TABLE has the explanation: (%hash-fun-state 0 ;; HASH-FUN-STATE easily fits into a fixnum, but having it unboxed ;; as a signed word allows EQ-HASH/SMALL in EQ-HASH/COMMON to be ;; compiled a bit more tightly. :type sb-vm:signed-word) So, the state is a fixnum by design, and assuming (SUBTYPEP 'FIXNUM 'SIGNED-WORD), things should be fine. The only large numbers that can arise as valid hash states are for ADAPTIVE-EQUAL-HASH, for which the maximum expected chain length (4 bits) and the truncation limit for %SXHASH (see PERHAPS-TRUNCATED-EQUAL-HASH) are encoded in the state with a shift and a LOGIOR. That this state fits in a fixnum is ensured by MAKE-SXSTATE and this: (defconstant +sxstate-limit-bits+ #-64-bit (- sb-vm:n-fixnum-bits +sxstate-max-chain-length-bits+) ;; Chosen for ease of extracting the limit (e.g. AND REG, -2 on ;; x86-64). #+64-bit 31) All this is to say that I think there is no FIXNUM vs SIGNED-WORD issue, and the error stems from the other issue, calling an adaptive hash function with only one argument, which can then get invalid junk as hash state. The current version of WITH-WEAK-HASH-TABLE-ENTRY is written as if there were no adaptive weak hash tables, but MAKE-HASH-TABLE does allow adaptive equal hashing. During the original implementation, I accidentally left them in this inconsistent state after a lengthy back and forth on what to do with weak hash tables. To bring them into sync, I chose to fix W-W-H-T-E and committed 393fd97d9. Hopefully, that fixes the 32 bit build. On Mon, 8 Dec 2025 at 03:40, Douglas Katzman via Sbcl-devel < [email protected]> wrote: > Probably best if Gábor looks at it. > I don't feel confident to fix the adaptive hashing functions but I saw two > occurrences of funcall that look wrong- one is the one I changed, and the > other is at line 2040 - > > '((hash (clip-hash (the fixnum > > (funcall (hash-table-hash-fun hash-table) > key)))) > > > and you can't funcall it except with the function declaring not to check > its arg count > *(sb-impl::hash-table-hash-fun (make-hash-table :test 'equal)) => *#<FUNCTION > SB-IMPL::ADAPTIVE-EQUAL-HASH> > > _______________________________________________ > Sbcl-devel mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/sbcl-devel > _______________________________________________ Sbcl-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sbcl-devel