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: Thu, 03 Aug 2023 10:43:16 -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="17866"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Alan Mackenzie , 65017@debbugs.gnu.org, Eric Marsden To: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Aug 03 16:44:10 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 1qRZYf-0004Rf-Us for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 03 Aug 2023 16:44:10 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRZYZ-0001je-Na; Thu, 03 Aug 2023 10:44: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 1qRZYY-0001jV-Ly for bug-gnu-emacs@gnu.org; Thu, 03 Aug 2023 10:44: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 1qRZYY-0006kV-Dn for bug-gnu-emacs@gnu.org; Thu, 03 Aug 2023 10:44:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qRZYY-0007jd-9f for bug-gnu-emacs@gnu.org; Thu, 03 Aug 2023 10:44: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: Thu, 03 Aug 2023 14:44: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.169107381429689 (code B ref 65017); Thu, 03 Aug 2023 14:44:02 +0000 Original-Received: (at 65017) by debbugs.gnu.org; 3 Aug 2023 14:43:34 +0000 Original-Received: from localhost ([127.0.0.1]:52676 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qRZY5-0007in-Hg for submit@debbugs.gnu.org; Thu, 03 Aug 2023 10:43:33 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:28188) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qRZY3-0007iV-Ph for 65017@debbugs.gnu.org; Thu, 03 Aug 2023 10:43:32 -0400 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id F3DD3441895; Thu, 3 Aug 2023 10:43:25 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1691073799; bh=vOKgCw8ShwcaxVWV/4RR/eaJhlEFyse1MlGuoxPLMO8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=J/iXy5z6Y+qPzqAq7wJlSbI2L5nluwLq7FDQ0cfNqk0WNIysbJXxT2Gpj4j+JHzW1 1z8xYePk5kuU4NJl8TeeZZN+nAyh4REp1VI54cLsBnMtWBLQDz1kzBLD0ehcVxsJTs RXFnc54x2loSdfXD6zgWd5Gzi0PME+ZFl99cMu/AGTKYl/BqB5rxq+VZLLsXRD/Wws +7lEl2zzyPvXdjC3b1XxCp8mW3kuNN8x00AUQC0kISGL7AVI/K2cEA4rTl1rZ1B4oW eGfwag0cmmHIo/i4QSN22z4smtX+2f2PSZIPyASYvbQcRHyHvjjiLX2PIbFcpuSgHT NgcDZ7coa0oug== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id D75A04418BF; Thu, 3 Aug 2023 10:43:19 -0400 (EDT) Original-Received: from alfajor (unknown [181.44.118.150]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id A0D831202BC; Thu, 3 Aug 2023 10:43:18 -0400 (EDT) In-Reply-To: <8B08E514-B2D5-48F5-BA90-4F5A9492F8F9@gmail.com> ("Mattias =?UTF-8?Q?Engdeg=C3=A5rd?="'s message of "Thu, 3 Aug 2023 11:39:33 +0200") 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:266590 Archived-At: > We can simplify your nice little test case to > > ------- first file ----------- > (require 'cl-macs) > (defun zeta () (cl-flet () #'equal)) > ------- second file --------- > (defun eta () (cl-flet () (funcall #'equal 12 34))) > ------------------------------ > > and indeed, the leak is in cl--labels-convert-cache which will contain > `equal` as a symbol-with-pos after byte-compiling the first file, and this > causes trouble in the second file. > > cl--labels-convert-cache contains > > (# function #) > > and the function `eta` is consequently defined as > > (closure (t) nil (progn (# 12 34))) > > where 49 is the position of `equal` in the first file. Thanks Mattias. AFAICT the problem is that OT1H `symbols-with-pos-enabled` is non-nil while loading the second file, but OTOH positions aren't stripped from the resulting code. So in `cl--labels-convert` when we check (eq f (car cl--labels-convert-cache)) we get when `f` is just `equal` whereas the cache contains the sympos, but that sympos is not stripped later on. I don't know why `symbols-with-pos-enabled` is non-nil at that point (I thought we only enabled it wile byte-compiling), but assuming there's a good reason for it, I tried to work around the problem with the patch below which is conceptually correct (indeed we should only return (cdr cl--labels-convert-cache) only in the case where `f` is exactly the very same object as (car cl--labels-convert-cache)). Sadly, it doesn't seem to help for a reason that escapes me. The *Messages* buffer says: For information about GNU Emacs and the GNU system, type C-h C-a. Compiling .../tmp/foo1.el... Self-rewrite # to #'# (t) Compiling .../tmp/foo1.el...done Wrote .../tmp/foo1.elc Self-rewrite equal to #'# (t) Self-rewrite # to #'# (t) where the middle "self-rewrite" is the culprit. Apparently (let ((symbols-with-pos-enabled nil)) (eq f (car cl--labels-convert-cache))) returned non-nil when `f` was the bare `equal` and the `car` returned the sympos. How can that be? I thought `eq` should really be the good old "pointer equality" when `symbols-with-pos-enabled` is nil. What am I missing? Stefan diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index 0a3181561bd..bc71f565f3b 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el @@ -2037,7 +2039,12 @@ ;; *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))) + (let ((print-symbols-bare nil)) + (message "Self-rewrite %S to %S (%S)" f (cdr cl--labels-convert-cache) + symbols-with-pos-enabled)) + (cdr cl--labels-convert-cache)) (t (let* ((found (assq f macroexpand-all-environment)) (replacement (and found