From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Circular records: how do I best handle them? (The new correct warning position branch now bootstraps in native compilation!) Date: Thu, 30 Dec 2021 13:37:47 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22916"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Dec 30 19:40:06 2021 Return-path: Envelope-to: ged-emacs-devel@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 1n30LN-0005k5-RN for ged-emacs-devel@m.gmane-mx.org; Thu, 30 Dec 2021 19:40:06 +0100 Original-Received: from localhost ([::1]:47466 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n30LM-0004rN-20 for ged-emacs-devel@m.gmane-mx.org; Thu, 30 Dec 2021 13:40:04 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:48156) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n30JH-00045w-DB for emacs-devel@gnu.org; Thu, 30 Dec 2021 13:37:55 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:34423) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n30JE-00010w-R8 for emacs-devel@gnu.org; Thu, 30 Dec 2021 13:37:54 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id EA89C8065D; Thu, 30 Dec 2021 13:37:50 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 6F00D8035A; Thu, 30 Dec 2021 13:37:49 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1640889469; bh=2RNvlnvnJ/n6ULUFALxNnZO8GjjV6dLtppMdjkpph4w=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=TX8cpPtaPbFMNG9QNgTuG96rstr7ja9NjFZo9xwpOpj7gmDxdw8PloWLKaJFpUd72 GY2r6zDuAtTfGOAabMUpGGH1STPVVhp/16Qbq+zkBlLdBWtKOOOtHBESHAhibNnb9K VDQ88s37arcxOv8jILehuD8Y26K1vKVv7nEpe1852+dJr/TeUkp61OVmobd5JVzGer JY9StPBDGpWSNZhkU17BHl8AG1HR9IRHHITuw5bPh3gbxfLvad9QNS9DKVlYqgJVTB WjQzZAXCSuhOzq4ENevhC7+bdRxc1DD7C1SlUyFRuiNgMhPGpY+YgHGbmaFLCh35oP uyQAVgVkOsb+Q== Original-Received: from ceviche (unknown [216.154.30.173]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 1138F120384; Thu, 30 Dec 2021 13:37:49 -0500 (EST) In-Reply-To: (Alan Mackenzie's message of "Thu, 30 Dec 2021 16:49:52 +0000") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, PLING_QUERY=0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:283677 Archived-At: >> >> Hmm... circularity is quite normal in data structures, yes. >> >> But presumably this is only applied to source code where circularity is >> >> very rare. Could it be that you end up recursing in elements which >> >> actually aren't part of the source code (and hence can't have >> >> symbols-with-positions)? >> > I honestly don't know at the moment. >> I think it's worth the effort to try and track this down. Maybe we can >> completely circumvent the problem. > I don't think there are any such cases. Hmm... I thought this whole circular records thread started because you bumped into such a case. I feel like I'm misunderstanding something. >> So the symposes can end up in 2 places: >> - in the .elc file: no need to strip the pos here, just make sure the >> symbols get printed without their position. > The positions get stripped before the code is dumped to the .elc. Why bother? You can just have a `print-symbols-without-position` which you let-bind around the printing code. >> - elsewhere: that's the problematic part because this only occurs where >> the source code gets stealthy passed elsewhere, e.g. when a macro >> calls (put ARG1 'foo ARG2) during the macro expansion (rather than >> returning that chunk of code in the expansion). > This isn't a problem. If it is a compiled macro doing this, the > positions will already be gone from the symbols. If it is from an > uncompiled macro, XSYMBOL in Feval's subroutines does the Right Thing. I didn't mean sympos coming from the macro but sympos coming from the args passed to the macro. Something like: (defmacro foobar-really (arg1 arg2) (puthash arg1 arg2 foobar-remember) `(progn (do-something ,arg1) (do-something-else ,arg2))) The `remember` property will end up containing symbols-with-pos if `arg2` contains symbols. > It's used all over the place. In eval-when/and-compile, it is used > before the evaluation. It is used before dumping the byte compiled code > to the file.elc, and before passing this code to the native compiler. > Several (?most) of the byte-compile-file-form-... functions use it. > It's used in the newish keymap functions near the end of bytecomp.el, in > byte-compile-annotate-call-tree, etc. Also in cl-define-compiler-macro, > and internal-macro-expand-for-load. Interesting. Why do you need it at so many places? What is it usually used for? > Additionally, also from Fput, to prevent symbols with positions > getting into symbol property lists. IIUC this is for the kind of example I showed above (tho I used `puthash` instead of `put`)? > Yes, I have to do this. I am still debating whether just to do it > (which might slow things down quite a bit), or to do it in a > condition-case handler after the recursion has exceeded the 1,600 > max-lisp-eval-depth. I'm inclined towards the latter at the moment. Using a (weak) hash-table may actually speed things up if you call it from lots and lots of places and it thus ends up being applied several times (redundantly) to the same data. > For other Lisp objects with a read syntax, such as char tables and > decorated strings, I intend to amend the reader just to output plain > symbols for them. Sounds reasonable. Stefan