From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Adam Porter Newsgroups: gmane.emacs.bugs Subject: bug#69521: 29.1; Adding a DECLARE spec equivalent to DECLARE-FUNCTION Date: Sun, 3 Mar 2024 04:49:02 -0600 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11615"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird To: 69521@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Mar 03 11:50:00 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 1rgjPs-0002mD-3e for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 03 Mar 2024 11:50:00 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgjPT-0001ta-Lw; Sun, 03 Mar 2024 05:49:35 -0500 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 1rgjPR-0001tO-Bk for bug-gnu-emacs@gnu.org; Sun, 03 Mar 2024 05:49:33 -0500 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 1rgjPR-0001EB-3d for bug-gnu-emacs@gnu.org; Sun, 03 Mar 2024 05:49:33 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rgjPt-0004c1-MT for bug-gnu-emacs@gnu.org; Sun, 03 Mar 2024 05:50:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Adam Porter Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 03 Mar 2024 10:50:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 69521 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.170946298217698 (code B ref -1); Sun, 03 Mar 2024 10:50:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 3 Mar 2024 10:49:42 +0000 Original-Received: from localhost ([127.0.0.1]:39813 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rgjPZ-0004bO-Pj for submit@debbugs.gnu.org; Sun, 03 Mar 2024 05:49:42 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:36102) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rgjPV-0004bB-3e for submit@debbugs.gnu.org; Sun, 03 Mar 2024 05:49:40 -0500 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 1rgjP1-0001ri-S8 for bug-gnu-emacs@gnu.org; Sun, 03 Mar 2024 05:49:07 -0500 Original-Received: from quail.birch.relay.mailchannels.net ([23.83.209.151]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgjP0-0001BV-Gw for bug-gnu-emacs@gnu.org; Sun, 03 Mar 2024 05:49:07 -0500 X-Sender-Id: dreamhost|x-authsender|adam@alphapapa.net Original-Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 33B6CC11BE for ; Sun, 3 Mar 2024 10:49:04 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a203.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id C34E3C10CD for ; Sun, 3 Mar 2024 10:49:03 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1709462943; a=rsa-sha256; cv=none; b=HBBVuQdDxLNd50EkN4wYELcd0dcegBjpPHg8smKqO5Z9UQvMMxn84evOnjGEK1+LqBSS+V rkTiBsWLVledvCqPSZPqs/6YJnRbtrjUVojJ7MQgzcD0D9yaWLFaU6ny5Z6ym5hY/Nikkj uTFSrlHZH2IwsvKNOcbURiDgpS9jxvA+8a6XoQsEZxlky8AUBjnWH5/zvNCODzHHmcgIif ocjM5XJUf9tSntdOFOAS1elJgwvqldaO4PhxbtMusEK7cddk9D1Z27bCff9F5h17lue3tB zN/7hdWzLDfJdalH2EW9x0Y1G8oP0hC7aw/QreyASBIMAZMxb39zztSaNo+1Gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1709462943; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding:dkim-signature; bh=rQjqMxpId+M34TvRrtskiJTg/96Q1HmW+40Kg5sYFO4=; b=nMqzlkf22JfaAnUDrEKVGZq1XV2RYpuZWi1XpNAwsictu8ue0ks5jswg8G9HaEK47H4TFB GI+7otPZHMT4mWG+oiTjBbknkvm8vg9iZzwsFusBZ1dJmO++/Bp5loq7TztOAdENEjbYNu H5oE/ktK5ZGCx2Hvz9GZys38gH/IKl4vPX0DwhS9Vn5fwS7tMGZ3xeIB9km2nh/xpHA1/7 y0ygaZU1lb5Z0deRVF/YestG86r9j+H7DGyTAn2uFC8Lqmxd0OoAXzf+x4mfG5b/A3VbtR V7gszmXZ1ti4hD9VShbCdnEzNgilLerpjF8kySa4FzotCidojkHQEWiIBTploQ== ARC-Authentication-Results: i=1; rspamd-7f9dd9fb96-cdljl; auth=pass smtp.auth=dreamhost smtp.mailfrom=adam@alphapapa.net X-Sender-Id: dreamhost|x-authsender|adam@alphapapa.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|adam@alphapapa.net X-MailChannels-Auth-Id: dreamhost X-Trouble-Wiry: 5ef3f8f50a38359b_1709462944029_819258068 X-MC-Loop-Signature: 1709462944028:2880327590 X-MC-Ingress-Time: 1709462944027 Original-Received: from pdx1-sub0-mail-a203.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.111.192.177 (trex/6.9.2); Sun, 03 Mar 2024 10:49:04 +0000 Original-Received: from [10.28.0.30] (unknown [45.131.192.18]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: adam@alphapapa.net) by pdx1-sub0-mail-a203.dreamhost.com (Postfix) with ESMTPSA id 4TndqM287fzGs for ; Sun, 3 Mar 2024 02:49:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alphapapa.net; s=dreamhost; t=1709462943; bh=rQjqMxpId+M34TvRrtskiJTg/96Q1HmW+40Kg5sYFO4=; h=Date:To:From:Subject:Content-Type:Content-Transfer-Encoding; b=OBl9Ds3veh2qtof67zaeyFF3psSZzCee/uhE/L358nAzl/T/UZONguAxhSTaKPFft 21rc/gOcm9q1842yZbd3cwjTA9gu4V1eJbR1SPOo8TJsHjXjatfMH77KMjcFCvD3fX 6GJl+Qtd5LHizxdnsvDbl7AP4fj94H8m7Y22PVxitwxGS2sR2mdzGqSWbXIPKFLfZZ DPS8vXd6Zu8gnE+ua6FAZ4paNmq/7sUw/hQ7//n3czan0SXgMNu86NrsZKTGXVHlrB 6zZglb+AoEoGgGoU0dCxAxNyBefuZ8UDcmvTjatWnMZN9ymOWBDJ4dKJi+nkI++c/B lAXaxt978MqOg== Content-Language: en-US Received-SPF: neutral client-ip=23.83.209.151; envelope-from=adam@alphapapa.net; helo=quail.birch.relay.mailchannels.net X-Spam_score_int: 0 X-Spam_score: -0.0 X-Spam_bar: / X-Spam_report: (-0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL=1.31, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action 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:280933 Archived-At: Hi, In light of [this thread], this seems like a good time to propose this idea: to enhance the `declare' form with a `function' spec equivalent to the top-level `declare-function' form. This allows keeping the declaration inside the function that makes it necessary, which has a few advantages: 1. It clearly indicates which function makes the declaration necessary (i.e. which function contains calls to the function in another library). 2. If the function is moved to another file, the declaration moves with it. 3. If the function is removed, the declaration is removed with it. 4. It reduces the number of top-level forms. Also, it seems like a natural fit, i.e. `declare-function' to `(declare (function ...))'. As an experiment, I implemented this in [Ement] about 10 months ago, and I've neither seen nor heard of any problems with it. Here's the code that implements it: ┌──── │ (eval-and-compile │ (defun ement--byte-run--declare-function (_name _args &rest values) │ "Return a `declare-function' form with VALUES. │ Allows the use of a form like: │ │ (declare (function FN FILE ...)) │ │ inside of a function definition, effectively keeping its │ `declare-function' form inside the function definition, ensuring │ that stray such forms don't remain if the function is removed." │ `(declare-function ,@values)) │ │ (cl-pushnew '(function ement--byte-run--declare-function) defun-declarations-alist :test #'equal) │ (cl-pushnew '(function ement--byte-run--declare-function) macro-declarations-alist :test #'equal)) └──── In use, it looks like this: ┌──── │ (defun ement-notifications--make (notification) │ "Return an `ement-notification' struct for NOTIFICATION. │ NOTIFICATION is an alist representing a notification returned │ from the \"/notifications\" endpoint. The notification's event │ is passed through `ement--make-event'." │ (declare (function ement--make-event "ement")) │ (pcase-let (((map room_id _actions _ts event read) notification)) │ (make-ement-notification :room-id room_id :readp read │ :event (ement--make-event event)))) └──── Would this be an acceptable addition to Emacs Lisp? If so, I'd be glad to prepare a patch. Thanks, Adam [this thread] [Ement]