From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#70221: [PATCH] New function `funcall-later` Date: Sun, 07 Apr 2024 08:28:25 +0300 Message-ID: <86r0fh213a.fsf@gnu.org> References: <86zfu73smn.fsf@gnu.org> <864jce34yv.fsf@gnu.org> <86wmpa1n7s.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39601"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 70221@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Apr 07 07:29:26 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 1rtL5p-000A6Z-LD for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 07 Apr 2024 07:29:25 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtL5N-0000wt-PT; Sun, 07 Apr 2024 01:28:57 -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 1rtL5L-0000wg-Ut for bug-gnu-emacs@gnu.org; Sun, 07 Apr 2024 01:28:56 -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 1rtL5L-0007Ht-GY for bug-gnu-emacs@gnu.org; Sun, 07 Apr 2024 01:28:55 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rtL5R-00083D-J3 for bug-gnu-emacs@gnu.org; Sun, 07 Apr 2024 01:29:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 07 Apr 2024 05:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70221 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 70221-submit@debbugs.gnu.org id=B70221.171246772230855 (code B ref 70221); Sun, 07 Apr 2024 05:29:01 +0000 Original-Received: (at 70221) by debbugs.gnu.org; 7 Apr 2024 05:28:42 +0000 Original-Received: from localhost ([127.0.0.1]:41375 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rtL58-00081b-9O for submit@debbugs.gnu.org; Sun, 07 Apr 2024 01:28:42 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60888) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rtL55-00081O-VZ for 70221@debbugs.gnu.org; Sun, 07 Apr 2024 01:28:40 -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 1rtL4t-0007GN-Hs; Sun, 07 Apr 2024 01:28:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=A1JwZLgLXhEyNCfxG1UoGHujEsVB8Hymk4tHw62yTqw=; b=lZE+aqaeljqv xH7MEi4o2TWb2tJYoWzsCo5DMHIti4tS0gKQTjcmAelRf8O54tX9eWwkInNMYX/gjgnUEOPMdpJjj /4vka03G5crlnIkv4arK34hKun+9ZNaLxmBpqLAgrW+7R89Ty8lzH6QSPLJLjY4CzCdNqefDFMBx0 VQgwNJlSZG7hqaxzuS7W5cktsjUJcBqgMaq7JkS37C2djo+2+JODEYYa90gdfvFxtFQWfN/x3+/Ts TuQOZ/VB7B4qUu9cWhYKVxwV/wPJfTaSZrtRTF9x/ah0plv7BB/EXj0bVUSA+L7M8zSVLv0iGokmU kWmDB2oSm/++6xX2zhtuGQ==; In-Reply-To: (message from Stefan Monnier on Sat, 06 Apr 2024 16:00:53 -0400) 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:282837 Archived-At: > From: Stefan Monnier > Cc: 70221@debbugs.gnu.org > Date: Sat, 06 Apr 2024 16:00:53 -0400 > > >> `condition-case-unless-debug` is very different from `safe_calln`. > >> It doesn't prevent non-local exits nor prevent showing a debugger. > > It catches errors, doesn't it? > > What's good about it? > > > That's what bothers me with CALLN. > > With CALLN the errors don't get caught by `safe_calln` so they get > caught further up the stack, which seems fine by me. > What problem/scenario are you thinking about? That we throw to top-level from a normal processing loop. Why should we not prevent that if we can? Why are you so objected to doing what we have always done there? > >> >> I can't see any good reason why we'd need to protect the > >> >> C code from non-local exits in `timer_check_2`. > >> > Because it will prevent timers from being called? > >> > >> Why would it? after the non-exit is caught somewhere up the stack, we'd > >> eventually come back to `timer_check_2` and run the timer then. > > > > Unless the same buggy funcall-later is again in the list, right? > > No: we bump it off the list before the CALLN, specifically to > avoid this problem. They don't auto-repeat like some timers. The Lisp program that initiated it could initiate another one soon enough. Why risk that when the solution is so easy? I really don't understand your objections here. Is there any harm that can possibly be done by catching errors, like timers do? If not, why not do it? > >> > From my POV, any code that runs from some background facility must > >> > inhibit QUIT, because the user can type C-g at any moment. > >> Agreed, and `funcall-later` doesn't run it "in the background", it runs > >> it at the end of the current code. > > How is this different from running timers? > > Non-0s timers are run in the context of some future command (or in the > middle of "idle" time). `funcall-later` are run before we get to idle > time or to the next user input The funcall-later functions are run in exactly the same context. Look at the code: they are called inside the same loop in timer_check_2. So the context is exactly the same. > so if the user hits C-g during them, it's no different from hitting > C-g during the main part of the command. It's realy more like > `post-command-hook` (incidentally, I've been thinking that maybe we > should call `internal--run-pending-funcalls` when we run > `post-command-hook`). Whatever happens with zero timers happens also with funcall-later functions. So the same considerations apply. From the user POV, Emacs is idle, so the user can press C-g at any moment. E.g., it is customary to press C-g when Emacs sits at the prompt in the minibuffer: both timers and funcall-later functions can be run at that time. > >> - It determines which part of the time-behavior we should consider as > >> something we want to document and guarantee, as opposed to the part > >> which is incidental and which we may prefer to document as not to be > >> relied on. > > I'm not sure I understand where you are going with this. It seems > > very easy to tell when the delayed functions will be called, so why > > are we arguing? > > I'm not sure the current implementation provides the behavior we want. > So I think it's worthwhile thinking about what it is that we want. > E.g. another implementation could be to have a separate thread running > those functions. Or as mentioned above we could run them from > `post-command-hook`. ... As long as the code is on the branch, I don't really care. But the moment it lands on master, it should have the proper documentation, and if by that time the implementation doesn't change, I insist on saying something about when these functions are called, because I think it's important. If the implementation does change, I will, of course, revisit my opinion (hopefully, during the review of the modified code that is to follow).