From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#65051: internal_equal manipulates symbols with position without checking symbols-with-pos-enabled. Date: Sat, 12 Aug 2023 14:46:24 -0400 Message-ID: References: <83msywg5a0.fsf@gnu.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34790"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 65051@debbugs.gnu.org, acm@muc.de To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Aug 12 20:47:15 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 1qUtdq-0008qT-8r for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 12 Aug 2023 20:47:14 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUtdj-0000Bm-CU; Sat, 12 Aug 2023 14:47:07 -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 1qUtdf-0000B2-Ab for bug-gnu-emacs@gnu.org; Sat, 12 Aug 2023 14:47:03 -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 1qUtde-0006o8-Q1 for bug-gnu-emacs@gnu.org; Sat, 12 Aug 2023 14:47:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qUtde-0005Ot-Ey for bug-gnu-emacs@gnu.org; Sat, 12 Aug 2023 14:47:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 12 Aug 2023 18:47:02 +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.169186599720689 (code B ref 65051); Sat, 12 Aug 2023 18:47:02 +0000 Original-Received: (at 65051) by debbugs.gnu.org; 12 Aug 2023 18:46:37 +0000 Original-Received: from localhost ([127.0.0.1]:57466 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUtdE-0005Nd-Ex for submit@debbugs.gnu.org; Sat, 12 Aug 2023 14:46:36 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:54688) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUtdB-0005NH-Ei for 65051@debbugs.gnu.org; Sat, 12 Aug 2023 14:46:34 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id EE46880625; Sat, 12 Aug 2023 14:46:26 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1691865985; bh=RvXGsOMZShvfcTJDUeFD7Xoegps4Q/5ndUjLaoHENX8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=nebrTUI3yEzQh/vGGohTIEqHKDhV85FzC/ORU/L9eR/rzt1Xcx3kP9lVxm+IliU4o F0JiRgs4WqtQOcYGfuyOPEb+Eqc/ZqEiK6TdENN0advQU5od4KItWULSi/yBNtH3KU 6H4Ku4IWmWoms6GF8+gZQt71A04EWwCobkr3zNmgM7G7ZPNAz89Sx2nVq4EbqQycMB 5bPEouH7Vd0sRGrucxDxojLz/2Tp9Vu4ye7vM4LmParPEVoSl8VhBv6pd/vFN7YQIF kLNgSzNlCn+MzfrFtYDiSWIY53T6ECq00VVK1G4mE7Oh/xzh0CMYqCVThRmGvDP2aZ 8mEmRUYqXMt/g== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id A2F3D803A2; Sat, 12 Aug 2023 14:46:25 -0400 (EDT) Original-Received: from pastel (69-165-141-248.dsl.teksavvy.com [69.165.141.248]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 73070120247; Sat, 12 Aug 2023 14:46:25 -0400 (EDT) In-Reply-To: <83msywg5a0.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 12 Aug 2023 09:10:15 +0300") 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:267329 Archived-At: Thanks, Stefan diff --git a/doc/lispref/symbols.texi b/doc/lispref/symbols.texi index 34db0caf3a8..d2e397faf80 100644 --- a/doc/lispref/symbols.texi +++ b/doc/lispref/symbols.texi @@ -782,11 +782,16 @@ Symbols with Position @cindex symbol with position @cindex bare symbol -A @dfn{symbol with position} is a symbol, the @dfn{bare symbol}, -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. +A @dfn{symbol with position} is a pair of a symbol, the @dfn{bare +symbol}, together with an unsigned integer called the @dfn{position}. +Symbol with position cannot themselves have entries in obarrays +(contrary to their bare symbols; @pxref{Creating Symbols}). + +Symbols with position are for the use of the byte compiler, which +records in them the position of each symbol occurrence and uses those +positions in warning and error messages. They shouldn't normally be +used otherwise. Doing so can cause unexpected results with basic +Emacs functions such as @code{eq} and @code{equal}. The printed representation of a symbol with position uses the hash notation outlined in @ref{Printed Representation}. It looks like @@ -798,11 +803,21 @@ Symbols with Position For most purposes, when the flag variable @code{symbols-with-pos-enabled} is non-@code{nil}, symbols with -positions behave just as bare symbols do. For example, @samp{(eq -# foo)} has a value @code{t} when that variable -is set (but @code{nil} when it isn't set). Most of the time in Emacs this -variable is @code{nil}, but the byte compiler binds it to @code{t} -when it runs. +position behave just as their bare symbols would. For example, +@samp{(eq # foo)} has a value @code{t} when the +variable is set; likewise, @code{equal} will treat a symbol with +position argument as its bare symbol. + +When @code{symbols-with-pos-enabled} is @code{nil}, any symbols with +position continue to exist, but do not always behave as symbols. +Most importantly @code{eq} only returns @code{t} when given truly +identical arguments, for performance reasons. @code{equal} on the +other hand continues to treat a symbol with +position argument as its bare symbol. + +Most of the time in Emacs @code{symbols-with-pos-enabled} is +@code{nil}, but the byte compiler and the native compiler bind it to +@code{t} when they run. Typically, symbols with position are created by the byte compiler calling the reader function @code{read-positioning-symbols} diff --git a/src/fns.c b/src/fns.c index ac30670b3ac..fde4ef6b08b 100644 --- a/src/fns.c +++ b/src/fns.c @@ -5166,7 +5166,7 @@ sxhash_obj (Lisp_Object obj, int depth) hash = sxhash_combine (hash, sxhash_obj (XOVERLAY (obj)->plist, depth)); return SXHASH_REDUCE (hash); } - else if (symbols_with_pos_enabled && pvec_type == PVEC_SYMBOL_WITH_POS) + else if (pvec_type == PVEC_SYMBOL_WITH_POS) return sxhash_obj (XSYMBOL_WITH_POS (obj)->sym, depth + 1); else /* Others are 'equal' if they are 'eq', so take their