GNU bug report logs - #52220
29.0.50; [PATCH] Declare struct predicates as pure functions

Previous Next

Package: emacs;

Reported by: Andrea Corallo <akrl <at> sdf.org>

Date: Wed, 1 Dec 2021 10:30:02 UTC

Severity: normal

Tags: patch

Found in version 29.0.50

Done: Andrea Corallo <akrl <at> sdf.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 52220 in the body.
You can then email your comments to 52220 AT debbugs.gnu.org in the normal way.

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#52220; Package emacs. (Wed, 01 Dec 2021 10:30:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Andrea Corallo <akrl <at> sdf.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 01 Dec 2021 10:30:02 GMT) Full text and rfc822 format available.

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

From: Andrea Corallo <akrl <at> sdf.org>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.50; [PATCH] Declare struct predicates as pure functions
Date: Wed, 01 Dec 2021 10:29:42 +0000
[Message part 1 (text/plain, inline)]
Hi all,

shouldn't we declare structure predicates as pure functions?

Proposed patch attached.

Thanks

  Andrea

[0001-lisp-emacs-lisp-cl-macs.el-cl-defstruct-Decl-struct-.patch (text/x-diff, inline)]
From 8382e2078295d6feb4abbe72cf671a61a84fc640 Mon Sep 17 00:00:00 2001
From: Andrea Corallo <akrl <at> sdf.org>
Date: Wed, 1 Dec 2021 11:23:25 +0100
Subject: [PATCH] * lisp/emacs-lisp/cl-macs.el (cl-defstruct): Decl struct
 predicates as pure

---
 lisp/emacs-lisp/cl-macs.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el
index 1852471bcb..9c9a778f04 100644
--- a/lisp/emacs-lisp/cl-macs.el
+++ b/lisp/emacs-lisp/cl-macs.el
@@ -3050,7 +3050,7 @@ cl-defstruct
                             `(,predicate cl-x))))
     (when pred-form
       (push `(,defsym ,predicate (cl-x)
-               (declare (side-effect-free error-free))
+               (declare (side-effect-free error-free) (pure t))
                ,(if (eq (car pred-form) 'and)
                     (append pred-form '(t))
                   `(and ,pred-form t)))
-- 
2.20.1


Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52220; Package emacs. (Wed, 01 Dec 2021 20:34:01 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Andrea Corallo <akrl <at> sdf.org>
Cc: 52220 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#52220: 29.0.50; [PATCH] Declare struct predicates as pure
 functions
Date: Wed, 01 Dec 2021 21:32:43 +0100
Andrea Corallo <akrl <at> sdf.org> writes:

> shouldn't we declare structure predicates as pure functions?

I think that's correct?  The predicates take the struct as the argument,
so they seem like pure functions to me.  I've added Stefan to the CCs;
perhaps there's some subtlety here I don't see.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52220; Package emacs. (Wed, 01 Dec 2021 21:06:01 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 52220 <at> debbugs.gnu.org, Andrea Corallo <akrl <at> sdf.org>
Subject: Re: bug#52220: 29.0.50; [PATCH] Declare struct predicates as pure
 functions
Date: Wed, 01 Dec 2021 16:05:11 -0500
Lars Ingebrigtsen [2021-12-01 21:32:43] wrote:
> Andrea Corallo <akrl <at> sdf.org> writes:
>> shouldn't we declare structure predicates as pure functions?
> I think that's correct?

Sounds right, yes.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52220; Package emacs. (Wed, 01 Dec 2021 21:17:01 GMT) Full text and rfc822 format available.

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

From: Andrea Corallo <akrl <at> sdf.org>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 52220 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#52220: 29.0.50; [PATCH] Declare struct predicates as pure
 functions
Date: Wed, 01 Dec 2021 21:16:01 +0000
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> Andrea Corallo <akrl <at> sdf.org> writes:
>
>> shouldn't we declare structure predicates as pure functions?
>
> I think that's correct?  The predicates take the struct as the argument,
> so they seem like pure functions to me.  I've added Stefan to the CCs;
> perhaps there's some subtlety here I don't see.

Yes we have all conventional predicates as pure, the only difference is
that here the result of the predicate depends also on the global state.

IOW redefining a structure could change the result of a predicate, but
my guess is that we don't want to be robust against that (structs in
general AFAIK are not robust against run-time redefinition).

  Andrea




Reply sent to Andrea Corallo <akrl <at> sdf.org>:
You have taken responsibility. (Wed, 01 Dec 2021 21:24:02 GMT) Full text and rfc822 format available.

Notification sent to Andrea Corallo <akrl <at> sdf.org>:
bug acknowledged by developer. (Wed, 01 Dec 2021 21:24:02 GMT) Full text and rfc822 format available.

Message #19 received at 52220-done <at> debbugs.gnu.org (full text, mbox):

From: Andrea Corallo <akrl <at> sdf.org>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 52220-done <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#52220: 29.0.50; [PATCH] Declare struct predicates as pure
 functions
Date: Wed, 01 Dec 2021 21:23:02 +0000
Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs <at> gnu.org> writes:

> Lars Ingebrigtsen [2021-12-01 21:32:43] wrote:
>> Andrea Corallo <akrl <at> sdf.org> writes:
>>> shouldn't we declare structure predicates as pure functions?
>> I think that's correct?
>
> Sounds right, yes.
>
>
>         Stefan

Right, installed as c35c86a353, closing.

Thanks

  Andrea




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 30 Dec 2021 12:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 79 days ago.

Previous Next


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