GNU bug report logs - #76533
[PATCH] Make cl-proclaim and cl-declaim obsolete

Previous Next

Package: emacs;

Reported by: Stefan Kangas <stefankangas <at> gmail.com>

Date: Mon, 24 Feb 2025 21:27:02 UTC

Severity: wishlist

Tags: patch

To reply to this bug, email your comments to 76533 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#76533; Package emacs. (Mon, 24 Feb 2025 21:27:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stefan Kangas <stefankangas <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 24 Feb 2025 21:27:02 GMT) Full text and rfc822 format available.

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

From: Stefan Kangas <stefankangas <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Cc: mattias.engdegard <at> gmail.com, monnier <at> iro.umontreal.ca
Subject: [PATCH] Make cl-proclaim and cl-declaim obsolete
Date: Mon, 24 Feb 2025 21:26:06 +0000
[Message part 1 (text/plain, inline)]
Severity: wishlist

In Bug#63288, we discussed making cl-proclaim and cl-declaim obsolete.
There consensus seems to be that this would be good.

The main use of cl-proclaim and cl-declaim is to enable some CL-Lib
specific optimizations by setting cl--optimize-speed and
cl--optimize-safety, and to set some byte-compiler variables.

It does seem quite strange to have such fundamental parts implemented in
cl-lib.el; if they are generally useful they should be made part of
Emacs Lisp proper and integrated as such.  If they are not, we should
just remove them.  In all cases, I think we should avoid maintaining
hard-to-understand and complex hacks in CL-Lib.

However, simply removing these CL-Lib specific variables makes the
compiled file size of eieieo-core.el (our only user of cl-declaim)
increase by almost 20%:

-rw-r--r--  1 skangas  staff  40705 Feb 24 21:31 eieio-core.elc
-rw-r--r--  1 skangas  staff  45572 Feb 24 21:31 lisp/emacs-lisp/eieio-core.elc

I'm a bit reluctant to make eieio slower, even if only a little, since
it's already known for not being fast.  So until we have a replacement
for cl--optimize-speed and cl--optimize-safety, I guess we'll have to
live with them.

Meanwhile, marking cl-proclaim and cl-declaim obsolete should at least
discourage using cl-lib for performance hacks, and hopefully encourage
more work on improving the byte-compiler instead.

The attached is the best patch I could come up with for now.

WDYT?
[0001-Make-cl-proclaim-and-cl-declaim-obsolete.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76533; Package emacs. (Tue, 25 Feb 2025 20:30:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: 76533 <at> debbugs.gnu.org, mattias.engdegard <at> gmail.com
Subject: Re: [PATCH] Make cl-proclaim and cl-declaim obsolete
Date: Tue, 25 Feb 2025 15:29:30 -0500
> However, simply removing these CL-Lib specific variables makes the
> compiled file size of eieieo-core.el (our only user of cl-declaim)
> increase by almost 20%:
>
> -rw-r--r--  1 skangas  staff  40705 Feb 24 21:31 eieio-core.elc
> -rw-r--r--  1 skangas  staff  45572 Feb 24 21:31 lisp/emacs-lisp/eieio-core.elc

It also makes it slower, yes.
The patch below removes this use of `cl-declaim` without the
corresponding performance impact.


        Stefan


diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el
index c3c8361b38e..db4c52d8789 100644
--- a/lisp/emacs-lisp/cl-macs.el
+++ b/lisp/emacs-lisp/cl-macs.el
@@ -2999,6 +2999,8 @@ cl--struct-default-parent
 
 (defvar cl--struct-inline t
   "If non-nil, `cl-defstruct' will define inlinable functions.")
+(make-obsolete-variable
+ 'cl--struct-inline "use :noinline keyword instead" "31.1")
 
 ;;;###autoload
 (defmacro cl-defstruct (struct &rest descs)
@@ -3012,7 +3014,8 @@ cl-defstruct
 OPTIONS...), where each OPTION is either a single keyword
 or (KEYWORD VALUE) where KEYWORD can be one of `:conc-name',
 `:constructor', `:copier', `:predicate', `:type', `:named',
-`:initial-offset', `:print-function', `:noinline', or `:include'.
+`:initial-offset', `:print-function', `:noinline', `:include',
+or `:unsafe-accessors'.
 See Info node `(cl)Structures' for the description of the
 options.
 
@@ -3125,6 +3128,8 @@ cl-defstruct
 	       (setq named t))
 	      ((eq opt :noinline)
 	       (setq defsym 'defun) (setq cldefsym 'cl-defun))
+	      ((eq opt :unsafe-accessors)
+	       (setq safety 0))
 	      ((eq opt :initial-offset)
 	       (setq descs (nconc (make-list (car args) '(cl-skip-slot))
 				  descs)))
diff --git a/lisp/emacs-lisp/eieio-core.el b/lisp/emacs-lisp/eieio-core.el
index f95fd65fa5c..fe7cd33aa77 100644
--- a/lisp/emacs-lisp/eieio-core.el
+++ b/lisp/emacs-lisp/eieio-core.el
@@ -79,12 +79,8 @@ eieio--unbound-form
 ;; while it is being built itself.
 (defvar eieio-default-superclass nil)
 
-(progn
-  ;; Arrange for field access not to bother checking if the access is indeed
-  ;; made to an eieio--class object.
-  (eval-when-compile (cl-declaim (optimize (safety 0))))
-
 (cl-defstruct (eieio--class
+               :unsafe-accessors
                (:constructor nil)
                (:constructor eieio--class-make (name))
                (:include cl--class)
@@ -101,12 +97,6 @@ eieio-default-superclass
   options ;; storage location of tagged class option
           ; Stored outright without modifications or stripping
   )
-  ;; Set it back to the default value.  NOTE: Using the default
-  ;; `safety' value does NOT give the default
-  ;; `byte-compile-delete-errors' value.  Therefore limit this (and
-  ;; the above `cl-declaim') to compile time so that we don't affect
-  ;; code which only loads this library.
-  (eval-when-compile (cl-declaim (optimize (safety 1)))))
 
 
 (eval-and-compile





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76533; Package emacs. (Tue, 25 Feb 2025 22:51:02 GMT) Full text and rfc822 format available.

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

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 76533 <at> debbugs.gnu.org, mattias.engdegard <at> gmail.com
Subject: Re: [PATCH] Make cl-proclaim and cl-declaim obsolete
Date: Tue, 25 Feb 2025 22:49:51 +0000
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

>> However, simply removing these CL-Lib specific variables makes the
>> compiled file size of eieieo-core.el (our only user of cl-declaim)
>> increase by almost 20%:
>>
>> -rw-r--r--  1 skangas  staff  40705 Feb 24 21:31 eieio-core.elc
>> -rw-r--r--  1 skangas  staff  45572 Feb 24 21:31 lisp/emacs-lisp/eieio-core.elc
>
> It also makes it slower, yes.
> The patch below removes this use of `cl-declaim` without the
> corresponding performance impact.

Thanks, LGTM.  Should the new keyword argument be documented?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76533; Package emacs. (Wed, 26 Feb 2025 04:12:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: 76533 <at> debbugs.gnu.org, mattias.engdegard <at> gmail.com
Subject: Re: [PATCH] Make cl-proclaim and cl-declaim obsolete
Date: Tue, 25 Feb 2025 23:11:03 -0500
> Thanks, LGTM.  Should the new keyword argument be documented?

Nah, better keep it for ourselves.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76533; Package emacs. (Wed, 26 Feb 2025 04:27:01 GMT) Full text and rfc822 format available.

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

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 76533 <at> debbugs.gnu.org, mattias.engdegard <at> gmail.com
Subject: Re: [PATCH] Make cl-proclaim and cl-declaim obsolete
Date: Wed, 26 Feb 2025 04:26:21 +0000
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

>> Thanks, LGTM.  Should the new keyword argument be documented?
>
> Nah, better keep it for ourselves.

OK, then please install.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76533; Package emacs. (Wed, 26 Feb 2025 04:41:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: 76533 <at> debbugs.gnu.org, mattias.engdegard <at> gmail.com
Subject: Re: [PATCH] Make cl-proclaim and cl-declaim obsolete
Date: Tue, 25 Feb 2025 23:39:47 -0500
>>> Thanks, LGTM.  Should the new keyword argument be documented?
>> Nah, better keep it for ourselves.
> OK, then please install.

Hmm... did you miss the smiley in my message, or did I miss yours?


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76533; Package emacs. (Wed, 26 Feb 2025 04:58:02 GMT) Full text and rfc822 format available.

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

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 76533 <at> debbugs.gnu.org, mattias.engdegard <at> gmail.com
Subject: Re: [PATCH] Make cl-proclaim and cl-declaim obsolete
Date: Wed, 26 Feb 2025 04:57:16 +0000
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

>>>> Thanks, LGTM.  Should the new keyword argument be documented?
>>> Nah, better keep it for ourselves.
>> OK, then please install.
>
> Hmm... did you miss the smiley in my message, or did I miss yours?

I probably missed yours. 😀

But more seriously, I don't think I have an opinion about documenting
this.  Maybe we should for the usual reasons, but if it's really only
useful in this one niche use case, I'd be fine with keeping it internal
(and thus undocumented) too.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76533; Package emacs. (Wed, 26 Feb 2025 14:20:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: 76533 <at> debbugs.gnu.org, mattias.engdegard <at> gmail.com
Subject: Re: [PATCH] Make cl-proclaim and cl-declaim obsolete
Date: Wed, 26 Feb 2025 09:19:33 -0500
>>>> Nah, better keep it for ourselves.
>>> OK, then please install.
>> Hmm... did you miss the smiley in my message, or did I miss yours?
> I probably missed yours. 😀
> But more seriously, I don't think I have an opinion about documenting
> this.  Maybe we should for the usual reasons, but if it's really only
> useful in this one niche use case, I'd be fine with keeping it internal
> (and thus undocumented) too.

No, I think it's useful generally enough that I chose this behavior as
the default behavior for OClosures (without even a way to override it).
I think I'll be tempted to use it at more places (I always considered
the `cl-declaim` way much to get this behavior much too ugly).


        Stean





This bug report was last modified 113 days ago.

Previous Next


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