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 01:36:08 -0400 Message-ID: References: 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="12411"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 65051@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Aug 12 07:37:25 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 1qUhJS-0002w2-63 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 12 Aug 2023 07:37:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUhJB-0003nB-R6; Sat, 12 Aug 2023 01:37:05 -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 1qUhJ8-0003mx-Dc for bug-gnu-emacs@gnu.org; Sat, 12 Aug 2023 01:37:02 -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 1qUhJ8-0002Gd-5k for bug-gnu-emacs@gnu.org; Sat, 12 Aug 2023 01:37:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qUhJ7-000145-Pz for bug-gnu-emacs@gnu.org; Sat, 12 Aug 2023 01:37:01 -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 05:37: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.16918185844020 (code B ref 65051); Sat, 12 Aug 2023 05:37:01 +0000 Original-Received: (at 65051) by debbugs.gnu.org; 12 Aug 2023 05:36:24 +0000 Original-Received: from localhost ([127.0.0.1]:48431 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUhIV-00012k-T4 for submit@debbugs.gnu.org; Sat, 12 Aug 2023 01:36:24 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:47665) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUhIS-00012P-3X for 65051@debbugs.gnu.org; Sat, 12 Aug 2023 01:36:22 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 6CBB7100213; Sat, 12 Aug 2023 01:36:14 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1691818568; bh=QNQXHQG83rpoK7tVBLl7kH9QEOsK2NGtHCCzHHckfBc=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=BVAj1GkabGS3vyvYnZz8LPvjlA4TRLkXRGOg/K5Nc50w1irVH3NplRtjOkcj3CNsA RSuMo4uzoBoP9g2C58zGdiAmhg73IfD0J/cwBR9mfOmE+THcox4CV1XF2mQZ3J+SsD wr7LbebCUKhMJ12zs4LMOs/sLDX16qNjHklvFl4myF8bZ5xt306/ZX4HCxMYFBSbKQ iG95nyeNdzQeQC55VddpAQOH9ZrbPmNAxNGkIWAuHge2qq5nLFNmc21/oTW4AYi1hb Toy/zivgLK2f5M/4KRooyHU6iY1W+wiJg7KdYNJNqLyYB9mGkH2LloKkpWE7rDENLe VWRYlWRv9dpzA== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id C2508100106; Sat, 12 Aug 2023 01:36:08 -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 9D59F120394; Sat, 12 Aug 2023 01:36:08 -0400 (EDT) In-Reply-To: (Alan Mackenzie's message of "Thu, 10 Aug 2023 18:35:27 +0000") 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:267247 Archived-At: > I'm proposing correctness, according to a coherent definition of > symbols-with-pos-enabled. I was surprised indeed, and continue to be > surprised, that you do not see this correction as a correction. To me, > it's obvious. I guess it's because you see it as a feature that (symbol-function (position-symbol 'a 3)) signals an error when `symbols-with-pos-enabled` is nil, whereas I see it as a misfeature we should try and fix. > That is the case, yes. There are no current use-cases for SWPs with > s-w-p-enabled nil. Right. So all the code which behaves differently when encountering an SWP depending on the value of `s-w-p-enabled` has only one of the two branches tested. My preference for making the behavior oblivious to `s-w-p-enabled` (except for those rare cases where it's needed for performance reasons) removes these untested code paths. In any case, here's my "counter offer" (BTW, why we do handle SWP specially in `time-convert`?). Stefan diff --git a/doc/lispref/symbols.texi b/doc/lispref/symbols.texi index 34db0caf3a8..0eb3e8f211d 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}. +They 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,20 @@ 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. +positions 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 is not affected, + +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 d7b2e7908b6..5239eb73026 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 diff --git a/src/timefns.c b/src/timefns.c index 151f5b482a3..7e030da3fcd 100644 --- a/src/timefns.c +++ b/src/timefns.c @@ -1767,8 +1767,6 @@ DEFUN ("time-convert", Ftime_convert, Stime_convert, 1, 2, 0, enum timeform input_form = decode_lisp_time (time, false, &t, 0); if (NILP (form)) form = current_time_list ? Qlist : Qt; - if (symbols_with_pos_enabled && SYMBOL_WITH_POS_P (form)) - form = SYMBOL_WITH_POS_SYM (form); if (BASE_EQ (form, Qlist)) return ticks_hz_list4 (t.ticks, t.hz); if (BASE_EQ (form, Qinteger))