From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrea Corallo Newsgroups: gmane.emacs.bugs Subject: bug#72279: [PATCH] Non-local exits from outside the lexical scope are caught by cl-block Date: Thu, 25 Jul 2024 11:15:12 -0400 Message-ID: References: <87wmla4rqq.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13499"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 72279@debbugs.gnu.org, Stefan Monnier To: Thuna Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jul 25 17:16:34 2024 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 1sX0Co-0003G0-Gc for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 25 Jul 2024 17:16:34 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sX0CY-0005Bw-Tg; Thu, 25 Jul 2024 11:16:19 -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 1sX0CB-0003rs-8c for bug-gnu-emacs@gnu.org; Thu, 25 Jul 2024 11:16:03 -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 1sX0CA-0000Y6-Ux for bug-gnu-emacs@gnu.org; Thu, 25 Jul 2024 11:15:55 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sX0CH-00071a-Uv for bug-gnu-emacs@gnu.org; Thu, 25 Jul 2024 11:16:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andrea Corallo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 25 Jul 2024 15:16:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72279 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 72279-submit@debbugs.gnu.org id=B72279.172192053026954 (code B ref 72279); Thu, 25 Jul 2024 15:16:01 +0000 Original-Received: (at 72279) by debbugs.gnu.org; 25 Jul 2024 15:15:30 +0000 Original-Received: from localhost ([127.0.0.1]:37584 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sX0Bl-00070d-Ut for submit@debbugs.gnu.org; Thu, 25 Jul 2024 11:15:30 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:48766) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sX0Bj-00070Q-3s for 72279@debbugs.gnu.org; Thu, 25 Jul 2024 11:15:29 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sX0BV-0000JR-Mo; Thu, 25 Jul 2024 11:15:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=11u8DIYXQUuduuukfVa9Dl+jjZi0pztrZ0Ken5BG/3k=; b=UZ34J+2knSoRI+WrwQiV HWWtds1fzoC1cTmpUpyWdhAbnCbzNawolgl1/H2eKCURt7A3RO2cADJOob86lP1kX1bEFc2yUoZ46 Oya37fSKprJwAVSwKFLgfJWqrEmo3TFDbepZz7rHJIRX4G6mIn7Vr9YNyVJAQuZTbU+RjlTvlPud3 /vASfSLCj2BY46QsaxF2PGngYLrUppmGEIg7IVEyI5rgW8EqiVE67UduimO6mPDBPwwiuoKAcpjIg GLROJta6qH//LspQtAn8/nHpCquavfg4oTUT9MjAMJwLlCKWRU+EYOeTbWf3MurgAPAVozydH1n2l qjUIqTgrQ8AEWw==; Original-Received: from acorallo by fencepost.gnu.org with local (Exim 4.90_1) (envelope-from ) id 1sX0BU-0007Qz-Sp; Thu, 25 Jul 2024 11:15:13 -0400 In-Reply-To: <87wmla4rqq.fsf@gmail.com> (Thuna's message of "Wed, 24 Jul 2024 19:36:13 +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:289313 Archived-At: Thuna writes: > Since the thrown and caught tags in `cl-block' and `cl-return-from' are > interned and deterministic, a `cl-block' catches `cl-return-from's with > the corresponding names even from outside the current lexical scope. > > The only mechanism in place to stop this is the compiler macro around > cl--block-catch, which removes the block if no approriate returns are > found, however not only is this bound to break if the compiler macro > fails to expand, a valid exit is all that is needed to work around this. > > (defun foo () (cl-return "ruh roh")) > (cl-block nil (foo) (cl-return t)) ; => "ruh ruh" Hi Thuna, yes I agree this is not optimal. We should not even get to evaluating the second form as we should error on the first (I think your patch does that). > The first patch attached attempts to solve this by moving the > functionality of the wrapper compiler macros to the macros themselves > and by using uninterned symbols for the thrown and caught tags, > communicated by the block to the corresponding returns. All the > existing tests seemed to run just fine but I did not do any > comprehensive testing (and there doesn't appear to be any relevant > suites either). Have you tried some general use with Emacs compiled with this patch? > I do take minor issue with `macroexpand-all'ing all things inside a > block, making debugging via macrostep really annoying, but I don't know > of a better solution, outside of communicating the tag during > evaluation, which would look something like the second patch. IIUC installing first.patch we keep the same capability of cleaning-up all un-necessary catches if no approriate throws are found correct? > PS. I would also like to have a discussion about a problem that I have > noticed when trying to build with the second patch, maybe here maybe in > another bug: Because struct slots are defined using `cl-defsubst', the > whole body is wrapped in a `cl-block'. The only reason `setf' works > with such slots is because `cl-block' expands into the body itself when > there are no `cl-return's. If it were to instead expand into a `catch' > - whether because there is a `cl-return' or because `cl-block' is > modified to always expandi into a `catch' as it is in my second patch - > the setf will expand into (setf catch) which is not defined. I see two > possible solutions, either define a (setf catch) or switch to defsubst > instead of cl-defsubst. > >>>From 4027c50645260a202e45a2a074dfeb48468394c1 Mon Sep 17 00:00:00 2001 > From: Thuna > Date: Wed, 24 Jul 2024 18:41:25 +0200 > Subject: [PATCH 1/2] Use uninterned tags in cl-block, remove block wrappers > [...] > diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el > index 2e501005bf7..31b88aec889 100644 > --- a/lisp/emacs-lisp/cl-macs.el > +++ b/lisp/emacs-lisp/cl-macs.el > @@ -889,6 +889,8 @@ cl-etypecase > > ;;; Blocks and exits. > > +(defvar cl--active-block-names nil) I think would be nice to document this variable with how its content is supposed to look like. I'm Ccing Stefan maybe he has opinions on these patches. Also I don't see you in the copyright file. Would you like to do the FSF paperwork in order to be able to contribute non trivial patches to Emacs? Thanks! Andrea