From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#65051: internal_equal manipulates symbols with position without checking symbols-with-pos-enabled. Date: Mon, 7 Aug 2023 10:58:41 +0200 Message-ID: <65A42652-DB4A-4FA6-8ADA-0D5BEB00F54C@gmail.com> References: <2F680A0A-54B5-42C2-B27B-4E5C6332517A@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39621"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 65051@debbugs.gnu.org, Eli Zaretskii , Stefan Monnier To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Aug 07 10:59:13 2023 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 1qSw53-000A8t-Ig for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 07 Aug 2023 10:59:13 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSw4t-0003C4-FW; Mon, 07 Aug 2023 04:59:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qSw4r-0003Bt-UD for bug-gnu-emacs@gnu.org; Mon, 07 Aug 2023 04:59:01 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSw4r-0001ST-Lc for bug-gnu-emacs@gnu.org; Mon, 07 Aug 2023 04:59:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qSw4r-0007LV-HR for bug-gnu-emacs@gnu.org; Mon, 07 Aug 2023 04:59:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 07 Aug 2023 08:59:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65051 X-GNU-PR-Package: emacs Original-Received: via spool by 65051-submit@debbugs.gnu.org id=B65051.169139873228222 (code B ref 65051); Mon, 07 Aug 2023 08:59:01 +0000 Original-Received: (at 65051) by debbugs.gnu.org; 7 Aug 2023 08:58:52 +0000 Original-Received: from localhost ([127.0.0.1]:60542 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qSw4i-0007L8-A1 for submit@debbugs.gnu.org; Mon, 07 Aug 2023 04:58:52 -0400 Original-Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]:42416) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qSw4g-0007Ku-8i for 65051@debbugs.gnu.org; Mon, 07 Aug 2023 04:58:51 -0400 Original-Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-4fe44955decso5140228e87.1 for <65051@debbugs.gnu.org>; Mon, 07 Aug 2023 01:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691398724; x=1692003524; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:from:to:cc:subject :date:message-id:reply-to; bh=p5tZpBzGAmU8W4+8GZb5t659RzPPlAAdI2TbK8cH9zo=; b=dSJfDtzYYmb38T/ryi+wWAMRCDZYGMpDyDMZ7ZtObpNT+t/wOrncWtUZSgvh/oMpLk KBcsMDdCGfXvyVk/ldZKDa5wm2KuDm86vJ70gxoj4biR1zZQ1SXC9MFXAnwHaocQuSlz X0dY1W/8jpF+7TiBZNmc2YqZDyraOIkmqbJUhSCe9jotvrionOYZvMHUPBbtPC34/RHm BYbMsPzXQ3f7mKgpZq7G5DyK6BD7BCROiNaArFmF0r2wOnPdewzUBk3iLoe6ANGw5Hpv TlTvvecUa12HkX3ucmaKYCSdd3PzRn5yFGqdigf2Ez3VFCXp3HcyzQMmAKASHzpKSLlc UxdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691398724; x=1692003524; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=p5tZpBzGAmU8W4+8GZb5t659RzPPlAAdI2TbK8cH9zo=; b=ZUXOeo0zhzAlpO+mUf9cH+5mQVS48uQmAkwU0AOarWuFxIEHj2wSmW27q9zhYB4A89 TA7635G/S7YYupoyjANWwiYZidcNCCynm4rCnhxtya7lIecNAAwvBXybBaDHMApwKcca wDF2OK5eJi9Dlb25QXIhiZPMkaMVYvBIbCrwVdeXBIK4Uv765ZX/5Ej0msEKKaXFfnq+ 6OAawImxDmxpfiBSHS6pfkuPOcFMoW+9JcD0re9+boaBqOtETaKK09UkqT2K+SA7Om6G duVbcN2YZRlYNPKnPqOEq69wBGiRaixPElBoEt7aOHnEXYlz5IceQHRW3XM0ttuVVBbS llOQ== X-Gm-Message-State: AOJu0YyEwmC2ne8VJUHoKOehiKtyIVclSiSDyVnhQWKfDbXVzRUiR8WA dgbyeT8V9ZmRM0qg280AgDA= X-Google-Smtp-Source: AGHT+IGB81GXO2AaG6qrwhTa3HAM5qcINtiLJg9b2Mbd3UMKDVHOM3u++cdj87NYNIuopMkz5OOikQ== X-Received: by 2002:a05:6512:12cb:b0:4fb:c9e1:5286 with SMTP id p11-20020a05651212cb00b004fbc9e15286mr2714645lfg.7.1691398723724; Mon, 07 Aug 2023 01:58:43 -0700 (PDT) Original-Received: from smtpclient.apple (c188-150-165-235.bredband.tele2.se. [188.150.165.235]) by smtp.gmail.com with ESMTPSA id w10-20020a19c50a000000b004fe1f37035csm1411626lfe.224.2023.08.07.01.58.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Aug 2023 01:58:43 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3654.120.0.1.15) 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:266874 Archived-At: 6 aug. 2023 kl. 17.02 skrev Alan Mackenzie : >>> 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 >=20 >> Not sure why we want to say how they are stored here. They can be >> stored in bubble memory for all the user cares. >=20 > 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. >>> +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. >=20 >> Since the components are bare symbols and fixnums, equality and >> identity for them are equivalent, right? >=20 > 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.) >> 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. >=20 > 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. >>> + 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)); >=20 >> Why recurse here if the components are a bare symbol and a fixnum, >> respectively? >=20 > 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. >> However we should make an effort to prevent the compiler from >> optimising (eq X X) -> t etc, which it is completely entitled to = doing, >> .... >=20 > 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`. >> .... and also test both the interpreted and compiled version of `eq` >> and `equal`. >=20 > 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? >=20 > I don't have such a test in my repository anywhere. Are you sure you > wrote it right? It was added in 44d7fd3805.