From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#46722: test-map-into fails Date: Wed, 05 Jan 2022 14:17:19 -0500 Message-ID: References: <871r2yu8b1.fsf@gnus.org> <87czl7w4fh.fsf@dick> <87bl0quhz6.fsf@dick> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13139"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: 46722@debbugs.gnu.org To: dick Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jan 05 20:26:48 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n5Bvs-000304-9Q for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 05 Jan 2022 20:26:48 +0100 Original-Received: from localhost ([::1]:35766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n5Bvq-00036C-Aw for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 05 Jan 2022 14:26:46 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:55254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5BnO-0005RW-GZ for bug-gnu-emacs@gnu.org; Wed, 05 Jan 2022 14:18:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:58578) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n5BnO-0008FB-6e for bug-gnu-emacs@gnu.org; Wed, 05 Jan 2022 14:18:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1n5BnO-0005Lb-3C for bug-gnu-emacs@gnu.org; Wed, 05 Jan 2022 14:18:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 05 Jan 2022 19:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46722 X-GNU-PR-Package: emacs Original-Received: via spool by 46722-submit@debbugs.gnu.org id=B46722.164141025219629 (code B ref 46722); Wed, 05 Jan 2022 19:18:02 +0000 Original-Received: (at 46722) by debbugs.gnu.org; 5 Jan 2022 19:17:32 +0000 Original-Received: from localhost ([127.0.0.1]:41891 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n5Bmt-00056I-H9 for submit@debbugs.gnu.org; Wed, 05 Jan 2022 14:17:32 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:41009) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n5Bmq-00051r-Q4 for 46722@debbugs.gnu.org; Wed, 05 Jan 2022 14:17:29 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id C9C52441D75; Wed, 5 Jan 2022 14:17:22 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 3C4DF440780; Wed, 5 Jan 2022 14:17:21 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1641410241; bh=D079Nsg3YVlN4PbbA7tuj0nvnQUdVr3rj0imm7mA2Kw=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=gXiuTp5zSxyGdOQuyLBfgXNG/4VptHWoJIOzuAhN5n8kuBLGLoeQ8Y1UN6K3Gq3Az uql19g8wW9XzwIiN5TDn1GadSg1oXhPpbkNnDQAaNI8yew87RihpKFD7rJ38wGJzLf pBgdE5dnnVr4oNhODJaIpueLIrJGA+hAV0wYzb+oTQ8OeuYogiwMc0qrq7RohR3H22 RqfqXNTzP49iHxTfHKnJHp9f5ZafF95Zfqcu9q/f1Sq6nDEg6KN2w/3w8cLtND82Jj 6KF+UrpDH7TqldHn1OSKjCfk1ZfGq4r63i7cFihNAu2cZTjkoFXfwGCikszDIHSzVK GfQNPqjCF1cwQ== Original-Received: from ceviche (unknown [216.154.30.173]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 0953412033F; Wed, 5 Jan 2022 14:17:21 -0500 (EST) In-Reply-To: <87bl0quhz6.fsf@dick> (dick's message of "Wed, 05 Jan 2022 13:59:09 -0500") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:223711 Archived-At: >> 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 fl= apping. Basically, here's what happens: On one call, `dispatch` is of the form (1 # #) because the arg n=B01 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=B01 now also has methods that use `head`, so this object is modified (by setcdr) to (1 # # #). Since it's the very same object, it means that the hash table now has a mapping from (1 # # #) 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 # # #) is not the same as the hash of (1 # #) 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't= ed. 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