From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Robin Tarsiger Newsgroups: gmane.emacs.devel Subject: Re: cl-block less lexical than expected Date: Tue, 4 Jan 2022 13:29:23 -0600 Message-ID: <070acea8-3299-83ca-f321-a08a93005225@dasyatidae.com> References: <78900c46-4c9a-b690-95d3-a02f27be9e59@dasyatidae.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22821"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.1 To: Emacs-Devel List Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jan 04 20:30:52 2022 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 1n4pWF-0005i9-Fx for ged-emacs-devel@m.gmane-mx.org; Tue, 04 Jan 2022 20:30:52 +0100 Original-Received: from localhost ([::1]:53360 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n4pWD-0002JL-Io for ged-emacs-devel@m.gmane-mx.org; Tue, 04 Jan 2022 14:30:49 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:32966) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n4pUw-0001bY-Co for emacs-devel@gnu.org; Tue, 04 Jan 2022 14:29:30 -0500 Original-Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:38167) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n4pUu-0001Zg-GF for emacs-devel@gnu.org; Tue, 04 Jan 2022 14:29:30 -0500 Original-Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 673F5320221D for ; Tue, 4 Jan 2022 14:29:25 -0500 (EST) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 04 Jan 2022 14:29:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dasyatidae.com; h=message-id:date:mime-version:subject:to:references:from :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=u KBoDhhOietrDFlKJi+xWUKfLfM6dtBsG1DsSNAywLU=; b=jrk67p5D/lSny6AJN R5vU1aH5eovvCn2D9DQyI1QVqaBdgmh2fgi1F+RgiGVeHd8Eun6Wo5+1DDF733no LuN/SF7wYKUP57nk7ET6MIwrsgMMZmVMr7+3yT7k/gFwcJIFlw7fDTN7U2r8ELmH Mlbgsbo+JG0sncSepESzLplzm4xjo3D9nO+UskYtjwNO/f/7If3PWDWi5tJ+oYjC iyyoJYS25uqMf0N+ClGdPSdscx+Ig1Yj4f+dMFAcbgeuMVBcwJtxKe1RDNRodBiP C8GpuEU4OQJnGNtGKE8mdrMBcT50C6hF2h+GdBQ35IdLUSPdnB9Z5bX5/B+McbPy 6eCBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=uKBoDhhOietrDFlKJi+xWUKfLfM6dtBsG1DsSNAyw LU=; b=aGVZCsRq7fYQdhBFVIpACTfbIF3u5DibsXfHdi6B0WO9/Thbvp9n+JKwL eKGS6pQx0MKJLwrPRkNkWzj8FWr7tWSv8GR2KzZXh7LC0jHMd7PmbXVJa+6yBDxz ZPfkw5o+7XZTN5DpCznxESCYdPySSmucS58a9+VPRSDYr6Y7FZWRdRsJd1ywgFyg S4C2js02vZ63HEMateFkFWs8qpOhuBE8IaOWVZiU8jX5LOhBzPWFrOEEX70KuPaw jP4QNnHxwobofZthTf82wG7WnYyoxmlx9vCXcgcAnTnR0uEhmGFa6HzwzcI81TmO Jwm+IwsCk4TY8TKbnxoD5mgrTbXTw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrudeffedguddviecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfuvfhfhfgjtgfgsehtjeertddtfeejnecuhfhrohhmpeftohgs ihhnucfvrghrshhighgvrhcuoehrthhtsegurghshigrthhiuggrvgdrtghomheqnecugg ftrfgrthhtvghrnhepgeefgeejteetfefhudehvdehveehhedujeeguefgueelueduvdek veelgeeugedunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homheprhhtthesuggrshihrghtihgurggvrdgtohhm X-ME-Proxy: Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 4 Jan 2022 14:29:24 -0500 (EST) Content-Language: en-US-large In-Reply-To: Received-SPF: pass client-ip=64.147.123.25; envelope-from=rtt@dasyatidae.com; helo=wout2-smtp.messagingengine.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-3.354, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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:284194 Archived-At: I wrote: > I have to think that since catch and throw both take evaluated > expressions for their tags, a more suitable implementation might > do a static transformation to choose an out-of-the-way lexical > _variable_ name which would then be let-bound to a gensym during > the body. cl-return-from could then try to evaluate the variable > to get the tag; Stefan Monnier wrote: > Sounds good. As you noted, this was not an option when these macros > were written because of the need for statically scoped variables. So I've been experimenting a little with modifying cl-macs.el to make this happen. I think I have it about right, but here's what I've found that's tricky: - cl--block-wrapper currently assumes it's receiving exactly a form produced by cl--block and invasively unwraps it, so they have to be kept in sync. This isn't too bad when it's just a catch form, but the new form is much more highly nested. I imagine having cl--block-wrapper do most of the expansion itself and be implemented as macro+cmacro rather than passthrough+cmacro would be cleaner here? - The new form is more highly nested not just because of the let to keep the tag in a variable, but because of an unwind-protect used to clear out the variable when the body is exited. This is so that lambdas that cl-return-from the enclosing block function properly when called while the block is executing, but can _not_ erroneously return from a separate activation of the same block if called after the original activation of the block has exited. Instead, they will wind up throwing to a dummy tag and signaling a recognizable error thereby. Naturally, the existing code misbehaves in this scenario as well. - I currently have cl-block warn if lexical-binding is nil. I did a quick pass over the Lisp files included with Emacs to make sure all files with cl-block-alikes used lexical-binding, but I don't know what impact this would have on external packages. - It would be nice to have cl-return-from warn if it doesn't see the name in the list of extant blocks that the cl--block-wrapper cmacro already uses to optimize away the catch, but that's not reliable enough, right? It doesn't play nicely with macrostep, for instance. Is there a better way to do this? - Documenting the new behavior is a bit weird due to the potential interaction with lexical-binding. I have a few paragraphs in the docstrings Texinfo manual indicating that cl-return-from may behave erratically if there are any non-lexical-binding cl-blocks in effect. The existing documentation is not quite correct anyway. More general questions for the list: - Is this a worthwhile thing to fix in Emacs? I would say yes, else I wouldn't be trying it, but I don't know if other people agree. The complexity increase in documentation from interactions with non-lexical-binding code is awkward, especially. How much do we need to worry about that? Is the general trend for lexical-binding to be strongly recommended enough that not giving details of what happens if it's off (other than that the correct use cases should still work) is okay? - If so, do I sound reasonably on the right track above? Would it be helpful to present a draft patch? - The reason I have not already presented a draft patch is because in futures where the code is integrated into Emacs, I would have to perform a copyright assignment. I do not object to this, but I also do not use my government-recognized name as my social name in this context. I am okay with the FSF keeping a record of my government name for legal purposes, but I would rather it not be included in publications anyplace too obvious. Is this a request that I can expect to be honored? What would be the impact of this on the assignment procedure? I am a US citizen. -RTT