GNU logs - #41354, boring messages


Message sent to bug-guile@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#41354: equal? has no sensible code path for symbols
Resent-From: David Kastrup <dak@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-guile@HIDDEN
Resent-Date: Sun, 17 May 2020 10:50:02 +0000
Resent-Message-ID: <handler.41354.B.15897125956229 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: report 41354
X-GNU-PR-Package: guile
X-GNU-PR-Keywords: 
To: 41354 <at> debbugs.gnu.org
X-Debbugs-Original-To: bug-guile@HIDDEN
Received: via spool by submit <at> debbugs.gnu.org id=B.15897125956229
          (code B ref -1); Sun, 17 May 2020 10:50:02 +0000
Received: (at submit) by debbugs.gnu.org; 17 May 2020 10:49:55 +0000
Received: from localhost ([127.0.0.1]:42386 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1jaGrj-0001cO-7o
	for submit <at> debbugs.gnu.org; Sun, 17 May 2020 06:49:55 -0400
Received: from lists.gnu.org ([209.51.188.17]:57936)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <dak@HIDDEN>) id 1jaGrh-0001cG-R0
 for submit <at> debbugs.gnu.org; Sun, 17 May 2020 06:49:54 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:43532)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <dak@HIDDEN>) id 1jaGrh-0000jr-Iy
 for bug-guile@HIDDEN; Sun, 17 May 2020 06:49:53 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e]:57076)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <dak@HIDDEN>) id 1jaGrh-0006R4-A1
 for bug-guile@HIDDEN; Sun, 17 May 2020 06:49:53 -0400
Received: from x5d849d3d.dyn.telefonica.de ([93.132.157.61]:34774 helo=lola)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <dak@HIDDEN>) id 1jaGrg-00083A-Rd
 for bug-guile@HIDDEN; Sun, 17 May 2020 06:49:53 -0400
From: David Kastrup <dak@HIDDEN>
Date: Sun, 17 May 2020 12:49:50 +0200
Message-ID: <87v9kuzvht.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -2.3 (--)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)


In Scheme, symbols can be compared using eq? for equality.  However,
since they have garbage-collected content attached, they do not meet the
predicate SCM_IMP in the short-circuit evaluation at the start of equal?
This means that unequal symbols compared using equal? fall through a
whole bunch of tests and end up in a general structural comparison
comparing their underlying string names.

This completely sabotages the semantics symbols are intended for.
Behavior for eqv? is similar but the fall-through at least is not as
expensive as it is for equal? .

-- 
David Kastrup




Message sent:


Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-Mailer: MIME-tools 5.505 (Entity 5.505)
Content-Type: text/plain; charset=utf-8
X-Loop: help-debbugs@HIDDEN
From: help-debbugs@HIDDEN (GNU bug Tracking System)
To: David Kastrup <dak@HIDDEN>
Subject: bug#41354: Acknowledgement (equal? has no sensible code path for
 symbols)
Message-ID: <handler.41354.B.15897125956229.ack <at> debbugs.gnu.org>
References: <87v9kuzvht.fsf@HIDDEN>
X-Gnu-PR-Message: ack 41354
X-Gnu-PR-Package: guile
Reply-To: 41354 <at> debbugs.gnu.org
Date: Sun, 17 May 2020 10:50:02 +0000

Thank you for filing a new bug report with debbugs.gnu.org.

This is an automatically generated reply to let you know your message
has been received.

Your message is being forwarded to the package maintainers and other
interested parties for their attention; they will reply in due course.

Your message has been sent to the package maintainer(s):
 bug-guile@HIDDEN

If you wish to submit further information on this problem, please
send it to 41354 <at> debbugs.gnu.org.

Please do not send mail to help-debbugs@HIDDEN unless you wish
to report a problem with the Bug-tracking system.

--=20
41354: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D41354
GNU Bug Tracking System
Contact help-debbugs@HIDDEN with problems


Message sent to bug-guile@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#41354: equal? has no sensible code path for symbols
Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-guile@HIDDEN
Resent-Date: Wed, 27 May 2020 20:41:01 +0000
Resent-Message-ID: <handler.41354.B41354.15906120109889 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 41354
X-GNU-PR-Package: guile
X-GNU-PR-Keywords: 
To: David Kastrup <dak@HIDDEN>
Cc: 41354 <at> debbugs.gnu.org
Received: via spool by 41354-submit <at> debbugs.gnu.org id=B41354.15906120109889
          (code B ref 41354); Wed, 27 May 2020 20:41:01 +0000
Received: (at 41354) by debbugs.gnu.org; 27 May 2020 20:40:10 +0000
Received: from localhost ([127.0.0.1]:50066 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1je2qP-0002ZR-Rs
	for submit <at> debbugs.gnu.org; Wed, 27 May 2020 16:40:10 -0400
Received: from eggs.gnu.org ([209.51.188.92]:56272)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <ludo@HIDDEN>) id 1je2qN-0002Z6-Sr
 for 41354 <at> debbugs.gnu.org; Wed, 27 May 2020 16:40:08 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e]:44841)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <ludo@HIDDEN>) id 1je2qI-0000o9-IU
 for 41354 <at> debbugs.gnu.org; Wed, 27 May 2020 16:40:02 -0400
Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=37088 helo=ribbon)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <ludo@HIDDEN>)
 id 1je2qG-0001o1-Pd; Wed, 27 May 2020 16:40:01 -0400
From: Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>
References: <87v9kuzvht.fsf@HIDDEN>
Date: Wed, 27 May 2020 22:39:59 +0200
In-Reply-To: <87v9kuzvht.fsf@HIDDEN> (David Kastrup's message of
 "Sun, 17 May 2020 12:49:50 +0200")
Message-ID: <875zchjen4.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -2.3 (--)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Hi David,

David Kastrup <dak@HIDDEN> skribis:

> In Scheme, symbols can be compared using eq? for equality.  However,
> since they have garbage-collected content attached, they do not meet the
> predicate SCM_IMP in the short-circuit evaluation at the start of equal?
> This means that unequal symbols compared using equal? fall through a
> whole bunch of tests and end up in a general structural comparison
> comparing their underlying string names.

=E2=80=98equal?=E2=80=99 starts by checking for eq-ness, which LGTM:

  SCM
  scm_equal_p (SCM x, SCM y)
  #define FUNC_NAME s_scm_i_equal_p
  {
    SCM_CHECK_STACK;
   tailrecurse:
    SCM_TICK;
    if (scm_is_eq (x, y))
      return SCM_BOOL_T;

Or were you referring to something else?

Thanks,
Ludo=E2=80=99.




Message sent to bug-guile@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#41354: equal? has no sensible code path for symbols
Resent-From: David Kastrup <dak@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-guile@HIDDEN
Resent-Date: Wed, 27 May 2020 20:50:02 +0000
Resent-Message-ID: <handler.41354.B41354.159061256218992 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 41354
X-GNU-PR-Package: guile
X-GNU-PR-Keywords: 
To: Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>
Cc: 41354 <at> debbugs.gnu.org
Received: via spool by 41354-submit <at> debbugs.gnu.org id=B41354.159061256218992
          (code B ref 41354); Wed, 27 May 2020 20:50:02 +0000
Received: (at 41354) by debbugs.gnu.org; 27 May 2020 20:49:22 +0000
Received: from localhost ([127.0.0.1]:50091 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1je2zJ-0004wG-Kv
	for submit <at> debbugs.gnu.org; Wed, 27 May 2020 16:49:21 -0400
Received: from eggs.gnu.org ([209.51.188.92]:57498)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <dak@HIDDEN>) id 1je2zI-0004w4-Eg
 for 41354 <at> debbugs.gnu.org; Wed, 27 May 2020 16:49:20 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e]:45092)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <dak@HIDDEN>)
 id 1je2zB-0005m2-EP; Wed, 27 May 2020 16:49:14 -0400
Received: from x5d85576d.dyn.telefonica.de ([93.133.87.109]:33288 helo=lola)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <dak@HIDDEN>)
 id 1je2zA-0002bD-Rg; Wed, 27 May 2020 16:49:13 -0400
From: David Kastrup <dak@HIDDEN>
References: <87v9kuzvht.fsf@HIDDEN> <875zchjen4.fsf@HIDDEN>
Date: Wed, 27 May 2020 22:49:10 +0200
In-Reply-To: <875zchjen4.fsf@HIDDEN> ("Ludovic =?UTF-8?Q?Court=C3=A8s?="'s message of "Wed, 27
 May 2020 22:39:59 +0200")
Message-ID: <87o8q9cddl.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -2.3 (--)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Ludovic Court=C3=A8s <ludo@HIDDEN> writes:

> Hi David,
>
> David Kastrup <dak@HIDDEN> skribis:
>
>> In Scheme, symbols can be compared using eq? for equality.  However,
>> since they have garbage-collected content attached, they do not meet the
>> predicate SCM_IMP in the short-circuit evaluation at the start of equal?
>> This means that unequal symbols compared using equal? fall through a
>> whole bunch of tests and end up in a general structural comparison
>> comparing their underlying string names.
>
> =E2=80=98equal?=E2=80=99 starts by checking for eq-ness, which LGTM:
>
>   SCM
>   scm_equal_p (SCM x, SCM y)
>   #define FUNC_NAME s_scm_i_equal_p
>   {
>     SCM_CHECK_STACK;
>    tailrecurse:
>     SCM_TICK;
>     if (scm_is_eq (x, y))
>       return SCM_BOOL_T;
>
> Or were you referring to something else?

I repeat: "This means that UNEQUAL symbols compared using equal? fall
through a whole bunch of tests and end up in a general structural
comparison comparing their underlying string names".

Lots of searches _end_ with an equal comparison (which is fast) but do a
lot of unequal comparisons before that (which is slow, even though
symbols that are not eq? will also not be equal?, so if you know you are
checking _symbols_, if they are not eq? you are done).

Symbols comparing as _unequal_ have no special path in equal?.

--=20
David Kastrup




Message sent to bug-guile@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#41354: equal? has no sensible code path for symbols
Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-guile@HIDDEN
Resent-Date: Thu, 28 May 2020 16:08:02 +0000
Resent-Message-ID: <handler.41354.B41354.159068203219106 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 41354
X-GNU-PR-Package: guile
X-GNU-PR-Keywords: 
To: David Kastrup <dak@HIDDEN>
Cc: 41354 <at> debbugs.gnu.org
Received: via spool by 41354-submit <at> debbugs.gnu.org id=B41354.159068203219106
          (code B ref 41354); Thu, 28 May 2020 16:08:02 +0000
Received: (at 41354) by debbugs.gnu.org; 28 May 2020 16:07:12 +0000
Received: from localhost ([127.0.0.1]:52879 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1jeL3n-0004y5-Lh
	for submit <at> debbugs.gnu.org; Thu, 28 May 2020 12:07:12 -0400
Received: from eggs.gnu.org ([209.51.188.92]:57956)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <ludo@HIDDEN>) id 1jeL3m-0004xq-07
 for 41354 <at> debbugs.gnu.org; Thu, 28 May 2020 12:07:10 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e]:35607)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <ludo@HIDDEN>) id 1jeL3g-0002ft-QM
 for 41354 <at> debbugs.gnu.org; Thu, 28 May 2020 12:07:04 -0400
Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=39468 helo=ribbon)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <ludo@HIDDEN>)
 id 1jeL3Y-00076D-A9; Thu, 28 May 2020 12:07:02 -0400
From: Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>
References: <87v9kuzvht.fsf@HIDDEN> <875zchjen4.fsf@HIDDEN>
 <87o8q9cddl.fsf@HIDDEN>
X-URL: http://www.fdn.fr/~lcourtes/
X-Revolutionary-Date: 10 Prairial an 228 de la =?UTF-8?Q?R=C3=A9volution?=
X-PGP-Key-ID: 0x090B11993D9AEBB5
X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc
X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4  0CFB 090B 1199 3D9A EBB5
X-OS: x86_64-pc-linux-gnu
Date: Thu, 28 May 2020 18:06:54 +0200
In-Reply-To: <87o8q9cddl.fsf@HIDDEN> (David Kastrup's message of
 "Wed, 27 May 2020 22:49:10 +0200")
Message-ID: <87367kavs1.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: -2.3 (--)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

--=-=-=
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hi,

David Kastrup <dak@HIDDEN> skribis:

> Ludovic Court=C3=A8s <ludo@HIDDEN> writes:
>
>> Hi David,
>>
>> David Kastrup <dak@HIDDEN> skribis:
>>
>>> In Scheme, symbols can be compared using eq? for equality.  However,
>>> since they have garbage-collected content attached, they do not meet the
>>> predicate SCM_IMP in the short-circuit evaluation at the start of equal?
>>> This means that unequal symbols compared using equal? fall through a
>>> whole bunch of tests and end up in a general structural comparison
>>> comparing their underlying string names.
>>
>> =E2=80=98equal?=E2=80=99 starts by checking for eq-ness, which LGTM:
>>
>>   SCM
>>   scm_equal_p (SCM x, SCM y)
>>   #define FUNC_NAME s_scm_i_equal_p
>>   {
>>     SCM_CHECK_STACK;
>>    tailrecurse:
>>     SCM_TICK;
>>     if (scm_is_eq (x, y))
>>       return SCM_BOOL_T;
>>
>> Or were you referring to something else?
>
> I repeat: "This means that UNEQUAL symbols compared using equal? fall
> through a whole bunch of tests and end up in a general structural
> comparison comparing their underlying string names".
>
> Lots of searches _end_ with an equal comparison (which is fast) but do a
> lot of unequal comparisons before that (which is slow, even though
> symbols that are not eq? will also not be equal?, so if you know you are
> checking _symbols_, if they are not eq? you are done).
>
> Symbols comparing as _unequal_ have no special path in equal?.

I was going to say that this is necessary for uninterned symbols, but it
turns out that uninterned symbols that look the same are not =E2=80=98equal=
?=E2=80=99:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (define a (make-symbol "x"))
scheme@(guile-user)> (define b (make-symbol "x"))
scheme@(guile-user)> (eq? a b)
$10 =3D #f
scheme@(guile-user)> (equal? a b)
$11 =3D #f
--8<---------------cut here---------------end--------------->8---

Thus we could go with the patch below, though I doubt it would make a
measurable difference (and it actually adds tests for other cases).

Thoughts?

Besides, in the common case where one is comparing against a symbol
literal, the question is moot:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> ,optimize (equal? 'x s)
$14 =3D (eq? 'x s)
--8<---------------cut here---------------end--------------->8---

Ludo=E2=80=99.


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline

diff --git a/libguile/eq.c b/libguile/eq.c
index 627d6f09b..16c5bfb3f 100644
--- a/libguile/eq.c
+++ b/libguile/eq.c
@@ -303,6 +303,8 @@ scm_equal_p (SCM x, SCM y)
     return SCM_BOOL_F;
   if (SCM_IMP (y))
     return SCM_BOOL_F;
+  if (scm_is_symbol (x) || scm_is_symbol (y))
+    return SCM_BOOL_F;
   if (scm_is_pair (x) && scm_is_pair (y))
     {
       if (scm_is_false (scm_equal_p (SCM_CAR (x), SCM_CAR (y))))

--=-=-=--




Message sent to bug-guile@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#41354: equal? has no sensible code path for symbols
Resent-From: David Kastrup <dak@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-guile@HIDDEN
Resent-Date: Thu, 28 May 2020 16:51:01 +0000
Resent-Message-ID: <handler.41354.B41354.159068463223115 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 41354
X-GNU-PR-Package: guile
X-GNU-PR-Keywords: 
To: Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>
Cc: 41354 <at> debbugs.gnu.org
Received: via spool by 41354-submit <at> debbugs.gnu.org id=B41354.159068463223115
          (code B ref 41354); Thu, 28 May 2020 16:51:01 +0000
Received: (at 41354) by debbugs.gnu.org; 28 May 2020 16:50:32 +0000
Received: from localhost ([127.0.0.1]:52931 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1jeLjk-00060l-2L
	for submit <at> debbugs.gnu.org; Thu, 28 May 2020 12:50:32 -0400
Received: from eggs.gnu.org ([209.51.188.92]:36678)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <dak@HIDDEN>) id 1jeLji-00060X-Af
 for 41354 <at> debbugs.gnu.org; Thu, 28 May 2020 12:50:30 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e]:36745)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <dak@HIDDEN>)
 id 1jeLjc-0003jw-8Y; Thu, 28 May 2020 12:50:24 -0400
Received: from x5d859cc4.dyn.telefonica.de ([93.133.156.196]:37826 helo=lola)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <dak@HIDDEN>)
 id 1jeLjb-0003OT-QZ; Thu, 28 May 2020 12:50:24 -0400
From: David Kastrup <dak@HIDDEN>
References: <87v9kuzvht.fsf@HIDDEN> <875zchjen4.fsf@HIDDEN>
 <87o8q9cddl.fsf@HIDDEN> <87367kavs1.fsf@HIDDEN>
Date: Thu, 28 May 2020 18:50:20 +0200
In-Reply-To: <87367kavs1.fsf@HIDDEN> ("Ludovic =?UTF-8?Q?Court=C3=A8s?="'s message of "Thu, 28
 May 2020 18:06:54 +0200")
Message-ID: <87blm8c8c3.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -2.3 (--)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Ludovic Court=C3=A8s <ludo@HIDDEN> writes:

> David Kastrup <dak@HIDDEN> skribis:
>
>> Ludovic Court=C3=A8s <ludo@HIDDEN> writes:
>>
>>> Hi David,
>>>
>>> David Kastrup <dak@HIDDEN> skribis:
>>
>> Symbols comparing as _unequal_ have no special path in equal?.
>
> I was going to say that this is necessary for uninterned symbols, but it
> turns out that uninterned symbols that look the same are not =E2=80=98equ=
al?=E2=80=99:
>
> scheme@(guile-user)> (define a (make-symbol "x"))
> scheme@(guile-user)> (define b (make-symbol "x"))
> scheme@(guile-user)> (eq? a b)
> $10 =3D #f
> scheme@(guile-user)> (equal? a b)
> $11 =3D #f

And it would be pretty horrible if they were, in my book.

> Thus we could go with the patch below, though I doubt it would make a
> measurable difference (and it actually adds tests for other cases).

It made a considerable measurable difference in LilyPond where it slowed
down the operation of assoc when used for symbol lookup (while assoc has
a short-circuit path to assq for SCM_IMP (key) that happens to have the
same problem of not being effective for symbols).  It took some
debugging to figure out why so much time was spent in equal? .

> Thoughts?
>
> Besides, in the common case where one is comparing against a symbol
> literal, the question is moot:
>
> scheme@(guile-user)> ,optimize (equal? 'x s)
> $14 =3D (eq? 'x s)

That is really quite irrelevant since the problem becomes visible when a
large number of comparisons in a row is done and if you were only
looking for a single constant key among a large set, you'd hardly have a
single constant key your code path would be looking for among that large
set.

> Ludo=E2=80=99.
>
> diff --git a/libguile/eq.c b/libguile/eq.c
> index 627d6f09b..16c5bfb3f 100644
> --- a/libguile/eq.c
> +++ b/libguile/eq.c
> @@ -303,6 +303,8 @@ scm_equal_p (SCM x, SCM y)
>      return SCM_BOOL_F;
>    if (SCM_IMP (y))
>      return SCM_BOOL_F;
> +  if (scm_is_symbol (x) || scm_is_symbol (y))
> +    return SCM_BOOL_F;
>    if (scm_is_pair (x) && scm_is_pair (y))
>      {
>        if (scm_is_false (scm_equal_p (SCM_CAR (x), SCM_CAR (y))))
>

Yes, that looks reasonable.  scm_is_symbol checks some tag subset that
the code for equal_p later looks at closer as well: if you worry about
the extra cost of the scm_is_symbol check, one could try folding the
symbol check into that later code passage, which would slow down the
symbol check and effect the more costly fallbacks less.  But since those
fallbacks _are_ more costly, I doubt it would be worth the trouble.

--=20
David Kastrup




Message sent to bug-guile@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#41354: equal? has no sensible code path for symbols
Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-guile@HIDDEN
Resent-Date: Fri, 29 May 2020 08:06:01 +0000
Resent-Message-ID: <handler.41354.B41354.15907395174713 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 41354
X-GNU-PR-Package: guile
X-GNU-PR-Keywords: 
To: David Kastrup <dak@HIDDEN>
Cc: 41354 <at> debbugs.gnu.org
Received: via spool by 41354-submit <at> debbugs.gnu.org id=B41354.15907395174713
          (code B ref 41354); Fri, 29 May 2020 08:06:01 +0000
Received: (at 41354) by debbugs.gnu.org; 29 May 2020 08:05:17 +0000
Received: from localhost ([127.0.0.1]:53717 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1jea0y-0001Dx-Lg
	for submit <at> debbugs.gnu.org; Fri, 29 May 2020 04:05:16 -0400
Received: from eggs.gnu.org ([209.51.188.92]:48300)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <ludo@HIDDEN>) id 1jea0w-0001Dk-SD
 for 41354 <at> debbugs.gnu.org; Fri, 29 May 2020 04:05:15 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e]:50638)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <ludo@HIDDEN>) id 1jea0r-00013j-Mg
 for 41354 <at> debbugs.gnu.org; Fri, 29 May 2020 04:05:09 -0400
Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=41832 helo=ribbon)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <ludo@HIDDEN>)
 id 1jea0q-0007XN-Rk; Fri, 29 May 2020 04:05:09 -0400
From: Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>
References: <87v9kuzvht.fsf@HIDDEN> <875zchjen4.fsf@HIDDEN>
 <87o8q9cddl.fsf@HIDDEN> <87367kavs1.fsf@HIDDEN>
 <87blm8c8c3.fsf@HIDDEN>
X-URL: http://www.fdn.fr/~lcourtes/
X-Revolutionary-Date: 11 Prairial an 228 de la =?UTF-8?Q?R=C3=A9volution?=
X-PGP-Key-ID: 0x090B11993D9AEBB5
X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc
X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4  0CFB 090B 1199 3D9A EBB5
X-OS: x86_64-pc-linux-gnu
Date: Fri, 29 May 2020 10:05:06 +0200
In-Reply-To: <87blm8c8c3.fsf@HIDDEN> (David Kastrup's message of
 "Thu, 28 May 2020 18:50:20 +0200")
Message-ID: <87ftbj6ua5.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -2.3 (--)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Hi,

David Kastrup <dak@HIDDEN> skribis:

> Ludovic Court=C3=A8s <ludo@HIDDEN> writes:

[...]

>> Thus we could go with the patch below, though I doubt it would make a
>> measurable difference (and it actually adds tests for other cases).
>
> It made a considerable measurable difference in LilyPond

You measured with and without the patch I sent?  Or something else?

>> diff --git a/libguile/eq.c b/libguile/eq.c
>> index 627d6f09b..16c5bfb3f 100644
>> --- a/libguile/eq.c
>> +++ b/libguile/eq.c
>> @@ -303,6 +303,8 @@ scm_equal_p (SCM x, SCM y)
>>      return SCM_BOOL_F;
>>    if (SCM_IMP (y))
>>      return SCM_BOOL_F;
>> +  if (scm_is_symbol (x) || scm_is_symbol (y))
>> +    return SCM_BOOL_F;
>>    if (scm_is_pair (x) && scm_is_pair (y))
>>      {
>>        if (scm_is_false (scm_equal_p (SCM_CAR (x), SCM_CAR (y))))
>>
>
> Yes, that looks reasonable.  scm_is_symbol checks some tag subset that
> the code for equal_p later looks at closer as well: if you worry about
> the extra cost of the scm_is_symbol check, one could try folding the
> symbol check into that later code passage, which would slow down the
> symbol check and effect the more costly fallbacks less.  But since those
> fallbacks _are_ more costly, I doubt it would be worth the trouble.

Looking at eq.c, I don=E2=80=99t see what =E2=80=9Ccostly fallbacks=E2=80=
=9D you=E2=80=99re referring
to.  For a symbol, AIUI, we end up here:

  switch (SCM_TYP7 (x))
    {
    default:
      /* Check equality between structs of equal type (see cell-type test a=
bove). */
      if (SCM_STRUCTP (x))
	{
	  if (SCM_INSTANCEP (x))
	    goto generic_equal;
	  else
	    return scm_i_struct_equalp (x, y);
	}
      break;   // <- here, meaning we return SCM_BOOL_F

All the checks leading to this line are type tag comparisons.

Am I overlooking something?

Thanks,
Ludo=E2=80=99.




Message sent to bug-guile@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#41354: equal? has no sensible code path for symbols
Resent-From: David Kastrup <dak@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-guile@HIDDEN
Resent-Date: Tue, 19 Jan 2021 21:54:02 +0000
Resent-Message-ID: <handler.41354.B41354.161109323224894 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 41354
X-GNU-PR-Package: guile
X-GNU-PR-Keywords: 
To: Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>
Cc: 41354 <at> debbugs.gnu.org
Received: via spool by 41354-submit <at> debbugs.gnu.org id=B41354.161109323224894
          (code B ref 41354); Tue, 19 Jan 2021 21:54:02 +0000
Received: (at 41354) by debbugs.gnu.org; 19 Jan 2021 21:53:52 +0000
Received: from localhost ([127.0.0.1]:51979 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1l1ywh-0006TS-MX
	for submit <at> debbugs.gnu.org; Tue, 19 Jan 2021 16:53:51 -0500
Received: from eggs.gnu.org ([209.51.188.92]:53050)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <dak@HIDDEN>) id 1l1ywe-0006TC-A5
 for 41354 <at> debbugs.gnu.org; Tue, 19 Jan 2021 16:53:50 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e]:34831)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <dak@HIDDEN>)
 id 1l1ywY-0002zK-B5; Tue, 19 Jan 2021 16:53:42 -0500
Received: from dynamic-093-131-081-135.93.131.pool.telefonica.de
 ([93.131.81.135]:37130 helo=lola)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <dak@HIDDEN>)
 id 1l1ywX-0006cJ-Q8; Tue, 19 Jan 2021 16:53:42 -0500
From: David Kastrup <dak@HIDDEN>
References: <87v9kuzvht.fsf@HIDDEN> <875zchjen4.fsf@HIDDEN>
 <87o8q9cddl.fsf@HIDDEN> <87367kavs1.fsf@HIDDEN>
 <87blm8c8c3.fsf@HIDDEN> <87ftbj6ua5.fsf@HIDDEN>
Date: Tue, 19 Jan 2021 22:53:37 +0100
In-Reply-To: <87ftbj6ua5.fsf@HIDDEN> ("Ludovic =?UTF-8?Q?Court=C3=A8s?="'s message of "Fri, 29
 May 2020 10:05:06 +0200")
Message-ID: <874kjcr3tq.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -2.3 (--)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Ludovic Court=C3=A8s <ludo@HIDDEN> writes:

> Hi,
>
> David Kastrup <dak@HIDDEN> skribis:
>
>> Ludovic Court=C3=A8s <ludo@HIDDEN> writes:
>
> [...]
>
>>> Thus we could go with the patch below, though I doubt it would make a
>>> measurable difference (and it actually adds tests for other cases).
>>
>> It made a considerable measurable difference in LilyPond
>
> You measured with and without the patch I sent?  Or something else?

It made a considerable measurable difference in LilyPond to use scm_eq
over scm_eqv when one variable was known to be a symbol and most
comparisons would have turned out false.

>
>>> diff --git a/libguile/eq.c b/libguile/eq.c
>>> index 627d6f09b..16c5bfb3f 100644
>>> --- a/libguile/eq.c
>>> +++ b/libguile/eq.c
>>> @@ -303,6 +303,8 @@ scm_equal_p (SCM x, SCM y)
>>>      return SCM_BOOL_F;
>>>    if (SCM_IMP (y))
>>>      return SCM_BOOL_F;
>>> +  if (scm_is_symbol (x) || scm_is_symbol (y))
>>> +    return SCM_BOOL_F;
>>>    if (scm_is_pair (x) && scm_is_pair (y))
>>>      {
>>>        if (scm_is_false (scm_equal_p (SCM_CAR (x), SCM_CAR (y))))
>>>
>>
>> Yes, that looks reasonable.  scm_is_symbol checks some tag subset that
>> the code for equal_p later looks at closer as well: if you worry about
>> the extra cost of the scm_is_symbol check, one could try folding the
>> symbol check into that later code passage, which would slow down the
>> symbol check and effect the more costly fallbacks less.  But since those
>> fallbacks _are_ more costly, I doubt it would be worth the trouble.
>
> Looking at eq.c, I don=E2=80=99t see what =E2=80=9Ccostly fallbacks=E2=80=
=9D you=E2=80=99re referring
> to.  For a symbol, AIUI, we end up here:
>
>   switch (SCM_TYP7 (x))
>     {
>     default:
>       /* Check equality between structs of equal type (see cell-type test=
 above). */
>       if (SCM_STRUCTP (x))
> 	{
> 	  if (SCM_INSTANCEP (x))
> 	    goto generic_equal;
> 	  else
> 	    return scm_i_struct_equalp (x, y);
> 	}
>       break;   // <- here, meaning we return SCM_BOOL_F
>
> All the checks leading to this line are type tag comparisons.
>
> Am I overlooking something?

That "all the checks" amount to quite a bit when the whole point of a
symbol is being faster to compare than structured types?  The main
surprise for me was that a symbol is a non-immediate type even though on
second thought it is clear that the symbol name has to be stored
somewhere associated with the symbol value.  However, from the
performance semantics a symbol should not be markedly different from
immediate types to avoid violating reasonable user expectations about
the Scheme type system: their whole point is to be fast to compare, and
fast comparisons are particularly important where you go through a large
number of them (which usually implies that most comparisons will end up
false).  This is particularly important when both arguments are symbols.

The normal expectation of functions like assv would be that they would
be only marginally slower than assq when the search key is a symbol (and
particularly so if most key/value pairs have a symbol key).  Because the
outcome for eqv(symbol1, symbol2)->#f takes quite longer than the
outcome for eq(symbol1, symbol2)->#f, this expectation is not met.

--=20
David Kastrup





Last modified: Tue, 19 Jan 2021 22:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.