all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Pip Cet <pipcet@gmail.com>
To: eggert@cs.ucla.edu
Cc: kbrown@cornell.edu, emacs-devel@gnu.org
Subject: Re: [Emacs-diffs] master f18af6c: Audit use of lsh and fix glitches
Date: Wed, 22 Aug 2018 20:05:37 +0000	[thread overview]
Message-ID: <CAOqdjBc+ASTx=NuvPQQimhSnTAh1b23fu4_9dAJNsnCT7v68Tg@mail.gmail.com> (raw)
In-Reply-To: <54e51f66-ba73-d5ef-3839-3986ed759bdc@cs.ucla.edu>

On Wed, Aug 22, 2018 at 5:27 PM Paul Eggert <eggert@cs.ucla.edu> wrote:
> Pip Cet wrote:
> We get some of that effect already in 32- vs 64-bit builds. Perhaps you're right
> and we would benefit from artificially small fixnums, or from debug builds that
> warn about eq misuse.

Well, it's harder to implement this than I thought at first, since we
want to change `eq' and `most-positive-fixnum' but not EQ and
MOST_POSITIVE_FIXNUM.

> > That said, vc-hg.el doesn't contain any suspicious-looking instances
> > of `eq', `memq', or `hash'
> Unfortunately that doesn't seem to be quite right. I looked and found one
> incorrect (though quite unlikely to fail) use of eq. I changed it to eql as part
> of the attached patch, which I installed.

No objections to that patch, but `eq' is correct in that code: string
length is limited by STRING_BYTES_BOUND, which is <=
MOST_POSITIVE_FIXNUM, so flen will always be a fixnum. It's also
handed to fixnum-only functions immediately afterwards, so even if we
allowed non-fixnum-length strings we'd get, at worst, a different
signal.

> > As for `eq' and `eql', what I thought Stefan proposed was to keep a
> > hash value in struct Lisp_Bignum, which is calculated lazily the first
> > time the bignum is compared to another bignum with `eq', at which
> > point we might as well point out to the user that portable code would
> > require `eql'. That sounds to me like it would be much cheaper than a
> > hash table, but if there are objections to it we can still implement
> > it without guaranteeing it for the future in the documentation.
>
> It might be helpful to have that in a debugging build.
> I am still leaning more towards hash tables, though;

It's precisely the opposite for me: I'm leaning towards hash tables in
debugging builds, where "which bignums currently exist" is a useful
question to ask, and lazy hashing in production builds, where
make_number is called often and (soon) shouldn't actually walk through
the bignum again to make a copy of it or calculate its hash value.

>at least, I want to time
> them to see how much they actually cost in typical practice. I suspect the cost
> is rather small, and if so it may well be worth it to avoid hassles like the
> eq-vs-eql glitch that I just now fixed in vc-hg.el.

I suspect the answer is they're cheap in "typical" practice because
bignums don't appear there, and expensive enough in atypical
situations (cryptography? number theory? Gödel coding?) to make some
applications resort to unnecessary and danger-prone C libraries.

And we're comparing two proposals which would make eq-vs-eql a
non-issue; one would slow down make_number (significantly, I believe,
unless we keep the current behavior which includes an unnecessary
memcpy), the other would slow down `eq' and possibly `EQ' to require a
tag bit check to catch bignum-on-bignum comparisons. That's an xor
(unless we change some other things) and a test insn if we give
bignums ("vectors with overloaded EQ behavior") their own tag value
(yay, now I've used up the tag bit you've freed for the second time).

[In fact, I like the idea of extending this to reserving one tag value
for "it's complicated" objects, which may but don't have to overload
primitives. All the primitives would check OVERLOADEDP(arg), a simple
and cheap tag bit check, before doing the right thing for primitive
objects. Think of all the number systems we could still implement.]



  reply	other threads:[~2018-08-22 20:05 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20180821204437.16880.99611@vcs0.savannah.gnu.org>
     [not found] ` <20180821204439.62390209A6@vcs0.savannah.gnu.org>
2018-08-22 12:36   ` [Emacs-diffs] master f18af6c: Audit use of lsh and fix glitches Pip Cet
2018-08-22 13:35     ` Ken Brown
2018-08-22 13:44       ` Paul Eggert
2018-08-22 15:50         ` Pip Cet
2018-08-22 17:27           ` Paul Eggert
2018-08-22 20:05             ` Pip Cet [this message]
2018-08-22 21:53               ` Paul Eggert
2018-08-22 20:45           ` Stefan Monnier
2018-08-23 14:55             ` Pip Cet
2018-08-23 15:56               ` Stefan Monnier
2018-08-24 18:00                 ` Pip Cet
2018-08-24 20:55                   ` Paul Eggert
2018-08-25 15:02                     ` Pip Cet
2018-08-25 18:02                       ` Stefan Monnier
2018-08-25 21:24                       ` Paul Eggert
2018-08-28 14:08                 ` hash-consing bignums and eq==eql Stefan Monnier
2018-08-29 13:32                   ` Pip Cet
2018-08-29 19:23                     ` Stefan Monnier
2018-08-29 19:31                     ` Paul Eggert
2018-08-29 20:50                       ` Stefan Monnier
2018-09-09  3:09                       ` Stefan Monnier
2018-09-09  6:26                         ` Paul Eggert
2018-08-22 13:49       ` [Emacs-diffs] master f18af6c: Audit use of lsh and fix glitches Pip Cet
2018-08-22 14:52         ` Eli Zaretskii

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOqdjBc+ASTx=NuvPQQimhSnTAh1b23fu4_9dAJNsnCT7v68Tg@mail.gmail.com' \
    --to=pipcet@gmail.com \
    --cc=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    --cc=kbrown@cornell.edu \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.