GNU bug report logs - #69521
29.1; Adding a DECLARE spec equivalent to DECLARE-FUNCTION

Previous Next

Package: emacs;

Reported by: Adam Porter <adam <at> alphapapa.net>

Date: Sun, 3 Mar 2024 10:50:01 UTC

Severity: wishlist

Merged with 74765

Found in versions 29.1, 30.0.92

To reply to this bug, email your comments to 69521 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#69521; Package emacs. (Sun, 03 Mar 2024 10:50:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Adam Porter <adam <at> alphapapa.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 03 Mar 2024 10:50:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Adam Porter <adam <at> alphapapa.net>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.1; Adding a DECLARE spec equivalent to DECLARE-FUNCTION
Date: Sun, 3 Mar 2024 04:49:02 -0600
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]
<https://lists.gnu.org/archive/html/emacs-devel/2024-03/msg00057.html>

[Ement] <https://elpa.gnu.org/packages/ement.html>




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69521; Package emacs. (Sun, 03 Mar 2024 11:22:02 GMT) Full text and rfc822 format available.

Message #8 received at 69521 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Adam Porter <adam <at> alphapapa.net>
Cc: 69521 <at> debbugs.gnu.org
Subject: Re: bug#69521: 29.1;
 Adding a DECLARE spec equivalent to DECLARE-FUNCTION
Date: Sun, 03 Mar 2024 13:18:14 +0200
severity 69521 wishlist
thanks

> Date: Sun, 3 Mar 2024 04:49:02 -0600
> From: Adam Porter <adam <at> alphapapa.net>
> 
> 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:

Thanks, but I think this should be discussed on emacs-devel first.
The bug tracker is not a good vessel of discussing ideas; in
particular. quite a few of people who should be part of such a
discussion don't read bug-gnu-emacs regularly, and must be explicitly
CC'ed to take notice.

So I suggest to start the discussion on emacs-devel, and only switch
here if/when the idea and its implementation aspects are clear enough
to post a patch.

Thanks.




Severity set to 'wishlist' from 'normal' Request was from Eli Zaretskii <eliz <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 03 Mar 2024 11:22:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69521; Package emacs. (Sun, 03 Mar 2024 21:05:02 GMT) Full text and rfc822 format available.

Message #13 received at 69521 <at> debbugs.gnu.org (full text, mbox):

From: Adam Porter <adam <at> alphapapa.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 69521 <at> debbugs.gnu.org
Subject: Re: bug#69521: 29.1; Adding a DECLARE spec equivalent to
 DECLARE-FUNCTION
Date: Sun, 3 Mar 2024 15:04:05 -0600
On 3/3/24 05:18, Eli Zaretskii wrote:

> Thanks, but I think this should be discussed on emacs-devel first.
> The bug tracker is not a good vessel of discussing ideas; in
> particular. quite a few of people who should be part of such a
> discussion don't read bug-gnu-emacs regularly, and must be explicitly
> CC'ed to take notice.
> 
> So I suggest to start the discussion on emacs-devel, and only switch
> here if/when the idea and its implementation aspects are clear enough
> to post a patch.

Ok, I filed the bug report because I had mentioned it in that thread and 
it seemed to get overlooked.  Now I've posted a new thread.  Please see:

https://lists.gnu.org/archive/html/emacs-devel/2024-03/msg00118.html




Added tag(s) moreinfo. Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Sat, 01 Mar 2025 03:18:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69521; Package emacs. (Sun, 02 Mar 2025 03:50:02 GMT) Full text and rfc822 format available.

Message #18 received at 69521 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Adam Porter <adam <at> alphapapa.net>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 69521 <at> debbugs.gnu.org
Subject: Re: bug#69521: 29.1;
 Adding a DECLARE spec equivalent to DECLARE-FUNCTION
Date: Sat, 1 Mar 2025 19:49:40 -0800
Adam Porter <adam <at> alphapapa.net> writes:

> On 3/3/24 05:18, Eli Zaretskii wrote:
>
>> Thanks, but I think this should be discussed on emacs-devel first.
>> The bug tracker is not a good vessel of discussing ideas; in
>> particular. quite a few of people who should be part of such a
>> discussion don't read bug-gnu-emacs regularly, and must be explicitly
>> CC'ed to take notice.
>> So I suggest to start the discussion on emacs-devel, and only switch
>> here if/when the idea and its implementation aspects are clear enough
>> to post a patch.
>
> Ok, I filed the bug report because I had mentioned it in that thread and it
> seemed to get overlooked.  Now I've posted a new thread.  Please see:
>
> https://lists.gnu.org/archive/html/emacs-devel/2024-03/msg00118.html

In that thread, Basil wrote:

    My vote is for instead teaching the compiler to treat
    declare-function more like it treats defvar, in that the effect of
    declare-function should be made local to the current lexical scope.
    [It is already possible to write this way, and I've been known to,
    but sadly the effect is global.]  This wish has been raised and
    agreed on here (at least in passing) before.

    This would reap all the benefits of points 1-4, as well as an
    additional one: that declare-function is lexically closer to the
    implementation through which the need for the declaration arises.  I
    think a declaration at the top of a function is more likely to be
    forgotten and become stale as the implementation changes.

FWIW, I'd very much welcome such a change.

Adam, are you interested in working on that?




Removed tag(s) moreinfo. Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Sun, 02 Mar 2025 03:50:03 GMT) Full text and rfc822 format available.

Forcibly Merged 69521 74765. Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Sun, 02 Mar 2025 04:33:03 GMT) Full text and rfc822 format available.

This bug report was last modified 104 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.