unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Pip Cet <pipcet@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Paul Eggert <eggert@cs.ucla.edu>,
	emacs-diffs@gnu.org, emacs-devel@gnu.org
Subject: Re: master 724af76 2/2: Fix sxhash-equal on bytecodes, markers, etc.
Date: Wed, 8 Jan 2020 19:23:19 +0000	[thread overview]
Message-ID: <CAOqdjBeBYFTcO3TjJY6EjidpSze9=1s_O5EhkN89C0ZOfN1ysQ@mail.gmail.com> (raw)
In-Reply-To: <jwvsgkqvnyi.fsf-monnier+emacs@gnu.org>

On Tue, Jan 7, 2020 at 11:37 PM Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> >> Again, I don't think there's any reason for using markers as keys in
> >> an equal-based hash table. But if you do, what you probably meant was
> >> to use an eq-based hash table, and that used to work; now it doesn't.
> >>
> >> (puthash marker value ht)
> >> <...move marker...>
> >> (gethash marker ht)
> >
> > If it hurts don't do that: the same happens with

(It turns out I've already done it. Easy enough to fix in my code, but
then I'm aware of the change in behavior. Others might not be.)

Out of curiosity, though, how would you fix code that uses a cons cell
of two markers, say, as a hash key? I still think it'd be nice to have
an equality predicate which looks at lists but doesn't recurse into
them, but in the absence of it you'd have to use nested hash tables or
your own hash function, right? (My code used to do that, then switched
to a single overlay as hash key, but I forgot to change the hash table
predicate).

> >     (puthash conscell value ht)
> >     <...setcar conscell...>
> >     (gethash conscell ht)

I don't think of inserting text in a buffer "far away" from a marker
as modifying the marker. That's probably because I'm playing around
with some unfinished code which would put markers and buffer text in a
tree-like data structure and wouldn't actually modify the markers upon
insertion at all, but that's just an implementation detail.

> BTW, id we really wanted it, we could make that work as you expect by
> making sxhash only return a value that does not depend on the properties
> that can be modified (i.e. doesn't depend on the cons's car and car nor
> the marker's current position), but it would lead to lots of objects
> with equal hash, hence poor hashing performance.

I think for very volatile objects, such as markers, that's the best
course of action (they could still depend on the marker's buffer). For
explicitly-modified objects, I think the current behavior is something
we're going to have to live with, including some bugs when C code
assumes its hash keys can't change under it.

I personally would prefer not changing the behavior of sxhash/equal
more than necessary, and err on the side of caution. For markers and
overlays, we can just hash the buffer (if you have many markers or
overlays in a single buffer, you'll run into complexity issues
anyway), rather than breaking my badly-written real-world code.



  reply	other threads:[~2020-01-08 19:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200107192947.22465.82501@vcs0.savannah.gnu.org>
     [not found] ` <20200107192950.02DA2211A5@vcs0.savannah.gnu.org>
2020-01-07 19:36   ` master 724af76 2/2: Fix sxhash-equal on bytecodes, markers, etc Pip Cet
2020-01-07 20:06     ` Stefan Monnier
2020-01-07 23:37       ` Stefan Monnier
2020-01-08 19:23         ` Pip Cet [this message]
2020-01-07 20:19     ` Paul Eggert

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='CAOqdjBeBYFTcO3TjJY6EjidpSze9=1s_O5EhkN89C0ZOfN1ysQ@mail.gmail.com' \
    --to=pipcet@gmail.com \
    --cc=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    --cc=emacs-diffs@gnu.org \
    --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).