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#65017: 29.1; Byte compiler interaction with cl-lib function objects, removes symbol-function Date: Fri, 11 Aug 2023 23:28:01 -0400 Message-ID: References: <8B08E514-B2D5-48F5-BA90-4F5A9492F8F9@gmail.com> 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="12169"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= , 65017@debbugs.gnu.org, Eric Marsden To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Aug 12 05:29:17 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 1qUfJU-00031y-VE for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 12 Aug 2023 05:29:17 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUfJI-0005Al-FL; Fri, 11 Aug 2023 23:29:04 -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 1qUfJG-0005AS-JV for bug-gnu-emacs@gnu.org; Fri, 11 Aug 2023 23:29: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 1qUfJG-000582-BS for bug-gnu-emacs@gnu.org; Fri, 11 Aug 2023 23:29:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qUfJG-0002V7-6R for bug-gnu-emacs@gnu.org; Fri, 11 Aug 2023 23:29: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 03:29:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65017 X-GNU-PR-Package: emacs Original-Received: via spool by 65017-submit@debbugs.gnu.org id=B65017.16918108999544 (code B ref 65017); Sat, 12 Aug 2023 03:29:02 +0000 Original-Received: (at 65017) by debbugs.gnu.org; 12 Aug 2023 03:28:19 +0000 Original-Received: from localhost ([127.0.0.1]:48328 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUfIZ-0002Ts-BW for submit@debbugs.gnu.org; Fri, 11 Aug 2023 23:28:19 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:27020) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUfIU-0002TT-Kc for 65017@debbugs.gnu.org; Fri, 11 Aug 2023 23:28:18 -0400 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id EA6124423D2; Fri, 11 Aug 2023 23:28:08 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1691810882; bh=grHNf1l7+fhBPhaX4S3i+wfl3ztFxZiFNYvlVI6Ouxw=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=N2yZkyukCIjICxniLgSsu7v4RWQifvD2wE8fJ9JYC5OvZujKR941zltuHXC0mOx72 +WV0t3B7Gzmu9DnW6PTBNGH+i0yDomokeM3ZMqorsAKvZWxEVkpgxwpohRwHTEQH2K GPQZuXDBfGTc7KKpn5r2PZmMU7BT6vFmws7Kda86fGmkxJ4MJ5WYB4oh6JQ1qEun6y rK2RWswwK7+D/cv/VsLoEzyk7Eya9I5ImCE+7LQ4aWHQTfq8FSUWdSU7xJ4D/vAISi x5nPS7q4Gyscym9ooJJF9J87yZM9LUQMvEfTiZrtVS5QxVjHwpXtk5hVWbgk1xRy5N yfV3ZhCBHD69Q== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id C16F64423CF; Fri, 11 Aug 2023 23:28:02 -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 9428812019A; Fri, 11 Aug 2023 23:28:02 -0400 (EDT) In-Reply-To: (Alan Mackenzie's message of "Thu, 10 Aug 2023 14:50:03 +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:267241 Archived-At: >> > And if, somehow, it does get used (the current code, I think), then (as >> > you write below) the argument F will get replaced by an F with the wrong >> > position. Am I right, here? >> That's right. > OK. So perhaps binding symbols-with-pos-enabled to nil around that eq > call could be the way to go. Indeed, that's the patch I suggested. I think it's fundamentally right, but it doesn't work (yet) because it bumps into the optimization bug introduced by making `eq` depend on `symbols-with-pos-enabled` :-( >> > Why must the F get replaced by a different F? There must surely be a >> > way, a simpler way than the current cl--labels-convert, to retain the >> > current F (hence, not corrupting its position)? >> There might. The current hack is the best I could come up with. > I'm not criticising the hack, not at all! But it could be better > commented, and the doc string for cl--labels-convert could be more > informative. It would help if you could send a (rough) patch showing what comment you'd have liked to see. > The "why" is missing - why is necessary to handle `function' as > a macro? I couldn't really think of any alternative for it ("it" being to implement `cl-labels` and `cl-flet`). FWIW, the pre-cl-lib code did it differently by duplicating `macroexp--expand-all` wholesale and then tweaking its handling of `function` in an ad-hoc way. BTW, there's a standard solution from Common Lisp to get rid of this hack: implement the `&whole` macro argument. [Macro Lambda Lists](http://clhs.lisp.se/Body/03_dd.htm) > I think it's to inhibit the processing of `function' as function > somewhere else, but where and why? It's not a function but a special operator, which is thus handled in a hard-coded way by `macroexp--expand-all`. >> I'm not completely sure we agree yet on what is "the original bug", but >> obviously I agree with your sentence :-) > I meant bug #65017. I committed a fix for it yesterday using the patch > I posted here on Sunday, and closed the bug. FWIW my notion of "the original bug" should be fixed by the patch below (modulo the above-mentioned optimization bug which makes the patch ineffective). BTW, I pushed an extended version of that patch which additionally does what you suggested we should do (and which I claimed wouldn't work), i.e. flush the cache (I originally couldn't see where to flush it). I believe this does fix the original problem even in the remaining corner cases, despite the optimization bug. Stefan diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index 0a3181561bd..a405ae67691 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el @@ -2037,7 +2037,9 @@ cl--labels-convert ;; *after* handling `function', but we want to stop macroexpansion from ;; being applied infinitely, so we use a cache to return the exact `form' ;; being expanded even though we don't receive it. - ((eq f (car cl--labels-convert-cache)) (cdr cl--labels-convert-cache)) + ((let ((symbols-with-pos-enabled nil)) + (eq f (car cl--labels-convert-cache))) + (cdr cl--labels-convert-cache)) (t (let* ((found (assq f macroexpand-all-environment)) (replacement (and found