unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: "Mattias Engdegård" <mattias.engdegard@gmail.com>
Cc: 65051@debbugs.gnu.org, Eli Zaretskii <eliz@gnu.org>,
	Stefan Monnier <monnier@iro.umontreal.ca>
Subject: bug#65051: internal_equal manipulates symbols with position without checking symbols-with-pos-enabled.
Date: Mon, 7 Aug 2023 09:44:55 +0000	[thread overview]
Message-ID: <ZNC9F_4-xUUkyMlf@ACM> (raw)
In-Reply-To: <65A42652-DB4A-4FA6-8ADA-0D5BEB00F54C@gmail.com>

Hello, Mattias.

On Mon, Aug 07, 2023 at 10:58:41 +0200, Mattias Engdegård wrote:
> 6 aug. 2023 kl. 17.02 skrev Alan Mackenzie <acm@muc.de>:

> >>> together with an unsigned integer called the @dfn{position}.  These
> >>> -objects are intended for use by the byte compiler, which records in
> >>> -them the position of each symbol occurrence and uses those positions
> >>> -in warning and error messages.
> >>> +objects are stored internally much like vectors

> >> Not sure why we want to say how they are stored here. They can be
> >> stored in bubble memory for all the user cares.

> > The point is, they are _not_ stored in the obarray.  Eli specifically
> > asked me to clarify this point, yesterday.

> Oh that part is perfectly fine (thank you), we just don't need to say
> that the sympos objects are stored "like vectors" -- that just confuses
> the reader.

Why not?  It's true, and I doubt it will cause confusion.  I think we
need to say something positive in that place (since we're following it
with a negative).  Perhaps you could suggest an alternative.

> >>> +When @code{symbols-with-pos-enabled} is @code{nil}, any symbols with
> >>> +position continue to exist, but do not behave as symbols, or have the
> >>> +other useful properties outlined in the previous paragraph.  @code{eq}
> >>> +returns @code{t} when given identical arguments, and @code{equal}
> >>> +returns @code{t} when given arguments with @code{equal} components.

> >> Since the components are bare symbols and fixnums, equality and
> >> identity for them are equivalent, right?

> > No.  If there are two distinct SWPs with the same bare symbol and the
> > same position, they should be equal, but not eq.  But the real point is
> > to contrast how equal and eq work when symbols-with-pos-enabled is nil
> > with when it is non-nil.

> I meant that the components of equal sympos objects aren't merely equal
> but identical. (This is a very minor quibble; you can keep the text if
> you like.)

The current proposed text has a more subtle intention.  It says that eq
and equal behave just like they always have done for everything when
symbols-with-pos-enabled is nil.

> >> OK. This reduces the number of branches in the hot path for ordinary
> >> (non-sympos) code by one while adding one to sym-pos code, and that
> >> should be a fair trade-off. The new branch should be well-predicted but
> >> is still consuming resources.

> > I did some simple timings on the old and new code, and the new code is
> > not slower.

> This is not easy to measure and details matter, but as I said -- there
> is no reason to believe that your changes should be a regression in the
> important measure, rather the opposite.

Agreed.

> >>> +	if (SYMBOL_WITH_POS_P(o1)) /* symbols_with_pos_enabled is false. */
> >>> +	  return (internal_equal (XSYMBOL_WITH_POS (o1)->sym,
> >>> +				  XSYMBOL_WITH_POS (o2)->sym,
> >>> +				  equal_kind, depth + 1, ht)
> >>> +		  && internal_equal (XSYMBOL_WITH_POS (o1)->pos,
> >>> +				     XSYMBOL_WITH_POS (o2)->pos,
> >>> +				     equal_kind, depth + 1, ht));

> >> Why recurse here if the components are a bare symbol and a fixnum,
> >> respectively?

> > Maybe in case they might somehow be something else?

> No, we must be able to assume that internal invariants hold when we
> offer no way for them to be violated. Let's just change the calls to
> BASE_EQ and be done with it.

OK, I think you're right, here, I'll change that.

> >> However we should make an effort to prevent the compiler from
> >> optimising (eq X X) -> t etc, which it is completely entitled to doing,
> >> ....

> > Why?  (eq X X) is t in all circumstances, whether X is a symbol, a cons
> > structure, or anything else.  What am I missing, here?

> If the compiler transforms (eq foo1 foo1) into t then the test won't
> actually exercise the implementation of `eq`.

Ah!  You're talking about the tests.  OK.  In my tests, I timed (equal a
b) where a and b were variables which were either equal or not.

> >> .... and also test both the interpreted and compiled version of `eq`
> >> and `equal`.

> > They're the same code in both cases.  I'm missing something here, too, I
> > think.

> Byte-code doesn't call Feq, it uses its own implementation. They should
> work identically but as we are checking edge cases here we'd better be
> sure about that.

> >> The test bytecomp--eq-symbols-with-pos-enabled already does most of
> >> this for a different reason. Perhaps it can be extended to cover
> >> `equal` as well?

> > I don't have such a test in my repository anywhere.  Are you sure you
> > wrote it right?

> It was added in 44d7fd3805.

OK.  That commit is recent, then?  If so, I'll see it soon.

-- 
Alan Mackenzie (Nuremberg, Germany).





  reply	other threads:[~2023-08-07  9:44 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-04 14:00 bug#65051: internal_equal manipulates symbols with position without checking symbols-with-pos-enabled Alan Mackenzie
2023-08-04 14:32 ` Eli Zaretskii
2023-08-04 14:59   ` Alan Mackenzie
2023-08-04 15:27     ` Eli Zaretskii
2023-08-04 17:06       ` Alan Mackenzie
2023-08-04 18:01         ` Eli Zaretskii
2023-08-05 10:45           ` Alan Mackenzie
2023-08-05 10:57             ` Eli Zaretskii
2023-08-05 11:52               ` Alan Mackenzie
2023-08-05 12:13                 ` Eli Zaretskii
2023-08-05 13:04                   ` Alan Mackenzie
2023-08-05 13:13                     ` Eli Zaretskii
2023-08-13 16:14                       ` Alan Mackenzie
2023-08-05 14:40 ` Mattias Engdegård
2023-08-05 16:59   ` Alan Mackenzie
2023-08-05 17:02     ` Mattias Engdegård
2023-08-05 21:07   ` Alan Mackenzie
2023-08-06 13:37     ` Mattias Engdegård
2023-08-06 15:02       ` Alan Mackenzie
2023-08-07  8:58         ` Mattias Engdegård
2023-08-07  9:44           ` Alan Mackenzie [this message]
2023-08-09 18:45             ` Mattias Engdegård
2023-08-07  3:30 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-07  9:20   ` Alan Mackenzie
2023-08-08  2:56     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-08 15:33       ` Alan Mackenzie
2023-08-10  3:28         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-10  9:14           ` Alan Mackenzie
2023-08-10 14:28             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-10 18:35               ` Alan Mackenzie
2023-08-12  5:36                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-12  6:10                   ` Eli Zaretskii
2023-08-12 18:46                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-12 19:10                       ` Eli Zaretskii
2023-08-13 15:27                       ` Alan Mackenzie
2023-08-12 10:41                   ` Alan Mackenzie
2023-08-12 18:07                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-13 13:52                       ` Alan Mackenzie
2023-08-12 21:59                   ` Alan Mackenzie
2023-08-11  0:51         ` Dmitry Gutov
2023-08-11 10:42           ` Alan Mackenzie
2023-08-11 11:18             ` Dmitry Gutov
2023-08-11 12:05               ` Alan Mackenzie
2023-08-11 13:19                 ` Dmitry Gutov
2023-08-11 14:04                   ` Alan Mackenzie
2023-08-11 18:15                     ` Dmitry Gutov
     [not found] ` <handler.65051.B.169115764532326.ack@debbugs.gnu.org>
2023-09-04 12:57   ` bug#65051: Acknowledgement (internal_equal manipulates symbols with position without checking symbols-with-pos-enabled.) Alan Mackenzie

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=ZNC9F_4-xUUkyMlf@ACM \
    --to=acm@muc.de \
    --cc=65051@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=mattias.engdegard@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).