From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: dick <dick.r.chiang@gmail.com>
Cc: 46722@debbugs.gnu.org
Subject: bug#46722: test-map-into fails
Date: Wed, 05 Jan 2022 14:17:19 -0500 [thread overview]
Message-ID: <jwv7dbeqa35.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87bl0quhz6.fsf@dick> (dick's message of "Wed, 05 Jan 2022 13:59:09 -0500")
>> So the underlying bug only appears if either the hash-table is rehashed
>> or the new `sxhash-equal` value happens to the same as the old one.
> I can't say I understand this, but I'm contented if map-tests.el stops flapping.
Basically, here's what happens:
On one call, `dispatch` is of the form (1 #<eq-generalizer> #<t-generalizer>)
because the arg n°1 has methods that use `eql` and `t`.
So an entry for it is placed in bucket 7 of the hash-table (say) with
the corresponding "eq + t dispatch function".
Now, this very `dispatch` object is also stored in the generic
function metadata. And later on, some new `cl-defmethod` is executed
which means the arg n°1 now also has methods that use `head`, so this
object is modified (by setcdr)
to (1 #<eq-generalizer> #<head-generalizer> #<t-generalizer>).
Since it's the very same object, it means that the hash table now has
a mapping from (1 #<eq-generalizer> #<head-generalizer> #<t-generalizer>)
to the "eq + t dispatch function", which is wrong and the core of problem.
Luckily for us, this problem has not bitten us very often because, the
hash of (1 #<eq-generalizer> #<head-generalizer> #<t-generalizer>) is
not the same as the hash of (1 #<eq-generalizer> #<t-generalizer>) so
our (now incorrect) entry (still placed in bucket 7) will simply never be
found by `gethash` because gethash will look for it in another bucket.
>> The benefit of the `method-cache` OTOH should be very significant
>> since without it we'd have to recompute the effective method at every
>> call.
>
> I don't get it. This assumes `method-cache` persists between successive
> calls to the byte-compiled closure... but `method-cache` is clearly let'ted.
It does persist: the byte-compiled closure is a "dispatcher builder".
The function we store in the `symbol-function` slot of generic
functions, is the (lambda (,@fixedargs &rest args) ...) function
*returned* by this function. This inner function has the method cache
in its captured environment which is why it persists between calls.
Stefan
prev parent reply other threads:[~2022-01-05 19:17 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-23 16:22 bug#46722: test-map-into fails Glenn Morris
2021-02-23 16:33 ` Basil L. Contovounesios
2021-02-23 17:06 ` Glenn Morris
2021-02-23 17:30 ` Stefan Monnier
2021-02-23 20:58 ` Basil L. Contovounesios
2021-02-23 22:50 ` Basil L. Contovounesios
2021-04-04 16:05 ` Glenn Morris
2021-11-17 8:47 ` Stefan Kangas
2021-11-29 18:20 ` Glenn Morris
2021-11-29 18:26 ` Lars Ingebrigtsen
2021-11-29 18:40 ` Glenn Morris
2022-01-04 21:56 ` dick
2022-01-05 14:01 ` dick
2022-01-05 16:31 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-05 17:51 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-05 18:07 ` Eli Zaretskii
2022-01-05 18:24 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-13 19:23 ` Philipp Stephani
2022-01-13 20:40 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-13 20:45 ` Philipp Stephani
2022-01-14 7:40 ` Lars Ingebrigtsen
2022-01-14 12:02 ` Philipp Stephani
2022-01-15 8:01 ` Lars Ingebrigtsen
2022-01-15 11:47 ` Philipp Stephani
2022-01-15 15:16 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-15 15:55 ` Eli Zaretskii
2022-01-20 12:49 ` Lars Ingebrigtsen
2022-01-05 15:17 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-05 16:04 ` dick
2022-01-05 16:38 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-05 18:35 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-05 18:59 ` dick
2022-01-05 19:17 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwv7dbeqa35.fsf-monnier+emacs@gnu.org \
--to=bug-gnu-emacs@gnu.org \
--cc=46722@debbugs.gnu.org \
--cc=dick.r.chiang@gmail.com \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).