unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#44792: [PATCH] Remove specific byte-compiler warnings for cl.el
@ 2020-11-22 11:09 Stefan Kangas
  2020-11-22 15:15 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Kangas @ 2020-11-22 11:09 UTC (permalink / raw)
  To: 44792; +Cc: monnier

[-- Attachment #1: Type: text/plain, Size: 877 bytes --]

Severity: wishlist

The old `cl.el' library was marked obsolete in Emacs 27.1.  We now get
two warnings if we try to require it, for example:

foo.el:3:1: Warning: Package cl is deprecated
foo.el:3:1: Warning: cl package required at runtime

I don't think there is any need to maintain the specific warnings about
the `cl' package.  The regular deprecation warnings should be
sufficient: they discourage use of cl.el altogether.

The attached patch removes all specific warnings about cl.  It also
updates the documentation to be even more discouraging regarding use of
cl.el and the even older cl-compat.el.

Finally, I noticed that the help screen for functions and variables from
cl.el do not actually say explicitly that they are obsolete.  The patch
marks most function and variable aliases in cl.el as obsolete.  This is
minor, but I believe somewhat helpful.

Thoughts?

[-- Attachment #2: 0001-Remove-specific-byte-compiler-warnings-for-cl.el.patch --]
[-- Type: text/x-diff, Size: 13759 bytes --]

From dcdd1b5331de0c2ab66f58520912878757d6ec37 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefan@marxist.se>
Date: Sun, 22 Nov 2020 10:45:07 +0100
Subject: [PATCH] Remove specific byte-compiler warnings for cl.el

* lisp/emacs-lisp/bytecomp.el (byte-compile-warning-types)
(byte-compile-warnings, byte-compile-cl-file-p)
(byte-compile-eval, byte-compile-eval-before-compile)
(byte-compile-arglist-warn, byte-compile-find-cl-functions)
(byte-compile-cl-warn, displaying-byte-compile-warnings)
(byte-compile-file-form-require, byte-compile-form): Remove all
specific cl.el warnings, as that library is now obsolete.  The
regular obsoletion warnings are sufficiently discouraging.
* lisp/emacs-lisp/advice.el (ad-compile-function): Don't try to
silence the now removed warning.
* doc/lispref/tips.texi (Coding Conventions):
* doc/misc/cl.texi (Organization): Make recommendation to not use
cl.el and cl-compat.el stronger.
* lisp/obsolete/cl.el: Make alias help say that they are obsolete.
* lisp/obsolete/cl-compat.el (build-klist, safe-idiv)
(pair-with-newsyms): Silence byte-compiler.
---
 doc/lispref/tips.texi       | 13 +-----
 doc/misc/cl.texi            | 15 ++-----
 lisp/emacs-lisp/advice.el   |  2 -
 lisp/emacs-lisp/bytecomp.el | 89 +++----------------------------------
 lisp/obsolete/cl-compat.el  | 17 ++++---
 lisp/obsolete/cl.el         |  4 +-
 6 files changed, 24 insertions(+), 116 deletions(-)

diff --git a/doc/lispref/tips.texi b/doc/lispref/tips.texi
index 40d01d4746..c9a43e0cde 100644
--- a/doc/lispref/tips.texi
+++ b/doc/lispref/tips.texi
@@ -139,17 +139,8 @@ Coding Conventions
 
 @item
 If you need Common Lisp extensions, use the @code{cl-lib} library
-rather than the old @code{cl} library.  The latter does not
-use a clean namespace (i.e., its definitions do not
-start with a @samp{cl-} prefix).  If your package loads @code{cl} at
-run time, that could cause name clashes for users who don't use that
-package.
-
-There is no problem with using the @code{cl} package at @emph{compile}
-time, with @code{(eval-when-compile (require 'cl))}.  That's
-sufficient for using the macros in the @code{cl} package, because the
-compiler expands them before generating the byte-code.  It is still
-better to use the more modern @code{cl-lib} in this case, though.
+rather than the old @code{cl} library.  The latter library is
+deprecated and will be removed in a future version of Emacs.
 
 @item
 When defining a major mode, please follow the major mode
diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi
index 2b38544dc8..084edd11b2 100644
--- a/doc/misc/cl.texi
+++ b/doc/misc/cl.texi
@@ -210,17 +210,10 @@ Organization
 @c There is also cl-mapc, which was called cl-mapc even before cl-lib.el.
 @c But not autoloaded, so maybe not much used?
 
-Since the old @file{cl.el} does not use a clean namespace, Emacs has a
-policy that packages distributed with Emacs must not load @code{cl} at
-run time.  (It is ok for them to load @code{cl} at @emph{compile}
-time, with @code{eval-when-compile}, and use the macros it provides.)
-There is no such restriction on the use of @code{cl-lib}.  New code
-should use @code{cl-lib} rather than @code{cl}.
-
-There is one more file, @file{cl-compat.el}, which defines some
-routines from the older Quiroz @file{cl.el} package that are not otherwise
-present in the new package.  This file is obsolete and should not be
-used in new code.
+The old file @file{cl.el}, as well as the even older
+@file{cl-compat.el}, are deprecated and will be removed in a future
+version of Emacs.  Any existing code that uses them should be updated
+to use @file{cl-lib.el} instead.
 
 @node Naming Conventions
 @section Naming Conventions
diff --git a/lisp/emacs-lisp/advice.el b/lisp/emacs-lisp/advice.el
index bb45bb37d1..948443fc18 100644
--- a/lisp/emacs-lisp/advice.el
+++ b/lisp/emacs-lisp/advice.el
@@ -2224,8 +2224,6 @@ ad-compile-function
   (let ((byte-compile-warnings byte-compile-warnings)
         ;; Don't pop up windows showing byte-compiler warnings.
         (warning-suppress-types '((bytecomp))))
-    (if (featurep 'cl)
-        (byte-compile-disable-warning 'cl-functions))
     (byte-compile (ad-get-advice-info-field function 'advicefunname))))
 
 ;; @@@ Accessing argument lists:
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index e6f6a12b53..2af8d4adb9 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -296,7 +296,7 @@ byte-compile-error-on-warn
 
 (defconst byte-compile-warning-types
   '(redefine callargs free-vars unresolved
-	     obsolete noruntime cl-functions interactive-only
+             obsolete noruntime interactive-only
 	     make-local mapcar constants suspicious lexical lexical-dynamic)
   "The list of warning types used when `byte-compile-warnings' is t.")
 (defcustom byte-compile-warnings t
@@ -312,8 +312,6 @@ byte-compile-warnings
   obsolete    obsolete variables and functions.
   noruntime   functions that may not be defined at runtime (typically
               defined only under `eval-when-compile').
-  cl-functions    calls to runtime functions (as distinguished from macros and
-                  aliases) from the old CL package (not the newer cl-lib).
   interactive-only
 	      commands that normally shouldn't be called from Lisp code.
   lexical     global/dynamic variables lacking a prefix.
@@ -968,11 +966,6 @@ byte-compile-lapcode
 \f
 ;;; compile-time evaluation
 
-(defun byte-compile-cl-file-p (file)
-  "Return non-nil if FILE is one of the CL files."
-  (and (stringp file)
-       (string-match "^cl\\.el" (file-name-nondirectory file))))
-
 (defun byte-compile-eval (form)
   "Eval FORM and mark the functions defined therein.
 Each function's symbol gets added to `byte-compile-noruntime-functions'."
@@ -1003,18 +996,7 @@ byte-compile-eval
 		(when (and (symbolp s) (not (memq s old-autoloads)))
 		  (push s byte-compile-noruntime-functions))
 		(when (and (consp s) (eq t (car s)))
-		  (push (cdr s) old-autoloads)))))))
-      (when (byte-compile-warning-enabled-p 'cl-functions)
-	(let ((hist-new load-history))
-	  ;; Go through load-history, looking for the cl files.
-	  ;; Since new files are added at the start of load-history,
-	  ;; we scan the new history until the tail matches the old.
-	  (while (and (not byte-compile-cl-functions)
-		      hist-new (not (eq hist-new hist-orig)))
-	    ;; We used to check if the file had already been loaded,
-	    ;; but it is better to check non-nil byte-compile-cl-functions.
-	    (and (byte-compile-cl-file-p (car (pop hist-new)))
-		 (byte-compile-find-cl-functions))))))))
+                  (push (cdr s) old-autoloads))))))))))
 
 (defun byte-compile-eval-before-compile (form)
   "Evaluate FORM for `eval-and-compile'."
@@ -1025,9 +1007,7 @@ byte-compile-eval-before-compile
       ;; There are other ways to do this nowadays.
       (let ((tem current-load-list))
 	(while (not (eq tem hist-nil-orig))
-	  (when (equal (car tem) '(require . cl))
-            (byte-compile-disable-warning 'cl-functions))
-	  (setq tem (cdr tem)))))))
+          (setq tem (cdr tem)))))))
 \f
 ;;; byte compiler messages
 
@@ -1577,45 +1557,6 @@ byte-compile-arglist-warn
            (if (equal sig1 '(1 . 1)) "argument" "arguments")
            (byte-compile-arglist-signature-string sig2)))))))
 
-(defvar byte-compile-cl-functions nil
-  "List of functions defined in CL.")
-
-;; Can't just add this to cl-load-hook, because that runs just before
-;; the forms from cl.el get added to load-history.
-(defun byte-compile-find-cl-functions ()
-  (unless byte-compile-cl-functions
-    (dolist (elt load-history)
-      (and (byte-compile-cl-file-p (car elt))
-	   (dolist (e (cdr elt))
-	     ;; Includes the cl-foo functions that cl autoloads.
-	     (when (memq (car-safe e) '(autoload defun))
-	       (push (cdr e) byte-compile-cl-functions)))))))
-
-(defun byte-compile-cl-warn (form)
-  "Warn if FORM is a call of a function from the CL package."
-  (let ((func (car-safe form)))
-    (if (and byte-compile-cl-functions
-	     (memq func byte-compile-cl-functions)
-	     ;; Aliases which won't have been expanded at this point.
-	     ;; These aren't all aliases of subrs, so not trivial to
-	     ;; avoid hardwiring the list.
-	     (not (memq func
-			'(cl--block-wrapper cl--block-throw
-			  multiple-value-call nth-value
-			  copy-seq first second rest endp cl-member
-			  ;; These are included in generated code
-			  ;; that can't be called except at compile time
-			  ;; or unless cl is loaded anyway.
-			  cl--defsubst-expand cl-struct-setf-expander
-			  ;; These would sometimes be warned about
-			  ;; but such warnings are never useful,
-			  ;; so don't warn about them.
-			  macroexpand
-			  cl--compiling-file))))
-	(byte-compile-warn "function `%s' from cl package called at runtime"
-			   func)))
-  form)
-
 (defun byte-compile-print-syms (str1 strn syms)
   (when syms
     (byte-compile-set-symbol-position (car syms) t))
@@ -1713,7 +1654,6 @@ displaying-byte-compile-warnings
 	   (and (markerp warning-series)
 		(eq (marker-buffer warning-series)
 		    (get-buffer byte-compile-log-buffer)))))
-     (byte-compile-find-cl-functions)
      (if (or (eq warning-series 'byte-compile-warning-series)
 	     warning-series-started)
 	 ;; warning-series does come from compilation,
@@ -2505,8 +2445,7 @@ byte-compile-file-form-custom-declare-variable
 (put 'require 'byte-hunk-handler 'byte-compile-file-form-require)
 (defun byte-compile-file-form-require (form)
   (let ((args (mapcar 'eval (cdr form)))
-	(hist-orig load-history)
-	hist-new prov-cons)
+        hist-new prov-cons)
     (apply 'require args)
 
     ;; Record the functions defined by the require in `byte-compile-new-defuns'.
@@ -2519,21 +2458,7 @@ byte-compile-file-form-require
       (dolist (x (car hist-new))
         (when (and (consp x)
                    (memq (car x) '(defun t)))
-          (push (cdr x) byte-compile-new-defuns))))
-
-    (when (byte-compile-warning-enabled-p 'cl-functions)
-      ;; Detect (require 'cl) in a way that works even if cl is already loaded.
-      (if (member (car args) '("cl" cl))
-	  (progn
-	    (byte-compile-warn "cl package required at runtime")
-	    (byte-compile-disable-warning 'cl-functions))
-	;; We may have required something that causes cl to be loaded, eg
-	;; the uncompiled version of a file that requires cl when compiling.
-	(setq hist-new load-history)
-	(while (and (not byte-compile-cl-functions)
-		    hist-new (not (eq hist-new hist-orig)))
-	  (and (byte-compile-cl-file-p (car (pop hist-new)))
-	       (byte-compile-find-cl-functions))))))
+          (push (cdr x) byte-compile-new-defuns)))))
   (byte-compile-keep-pending form 'byte-compile-normal-call))
 
 (put 'progn 'byte-hunk-handler 'byte-compile-file-form-progn)
@@ -3234,9 +3159,7 @@ byte-compile-form
                       ;; differently now).
                       (not (eq handler 'cl-byte-compile-compiler-macro))))
             (funcall handler form)
-          (byte-compile-normal-call form))
-        (if (byte-compile-warning-enabled-p 'cl-functions)
-            (byte-compile-cl-warn form))))
+          (byte-compile-normal-call form))))
      ((and (byte-code-function-p (car form))
            (memq byte-optimize '(t lap)))
       (byte-compile-unfold-bcf form))
diff --git a/lisp/obsolete/cl-compat.el b/lisp/obsolete/cl-compat.el
index b2471523d1..c37fc8eb5b 100644
--- a/lisp/obsolete/cl-compat.el
+++ b/lisp/obsolete/cl-compat.el
@@ -111,8 +111,9 @@ Multiple-value-prog1
 (defun build-klist (arglist keys &optional allow-others)
   (let ((res (Multiple-value-call 'mapcar* 'cons (unzip-lists arglist))))
     (or allow-others
-	(let ((bad (set-difference (mapcar 'car res) keys)))
-	  (if bad (error "Bad keywords: %s not in %s" bad keys))))
+        (with-suppressed-warnings ((obsolete set-difference))
+          (let ((bad (set-difference (mapcar 'car res) keys)))
+            (if bad (error "Bad keywords: %s not in %s" bad keys)))))
     res))
 
 (defun extract-from-klist (klist key &optional def)
@@ -130,16 +131,18 @@ elt-satisfies-test-p
       (funcall (or test 'eql) item elt))))
 
 (defun safe-idiv (a b)
-  (let* ((q (/ (abs a) (abs b)))
-         (s (* (signum a) (signum b))))
-    (Values q (- a (* s q b)) s)))
+  (with-suppressed-warnings ((obsolete signum))
+    (let* ((q (/ (abs a) (abs b)))
+           (s (* (signum a) (signum b))))
+      (Values q (- a (* s q b)) s))))
 
 
 ;; Internal routines.
 
 (defun pair-with-newsyms (oldforms)
-  (let ((newsyms (mapcar (lambda (x) (make-symbol "--cl-var--")) oldforms)))
-    (Values (mapcar* 'list newsyms oldforms) newsyms)))
+  (with-suppressed-warnings ((obsolete mapcar*))
+    (let ((newsyms (mapcar (lambda (x) (make-symbol "--cl-var--")) oldforms)))
+      (Values (mapcar* 'list newsyms oldforms) newsyms))))
 
 (defun zip-lists (evens odds)
   (cl-mapcan 'list evens odds))
diff --git a/lisp/obsolete/cl.el b/lisp/obsolete/cl.el
index 20bffffd78..6a628f305c 100644
--- a/lisp/obsolete/cl.el
+++ b/lisp/obsolete/cl.el
@@ -113,7 +113,7 @@ cl-unload-function
                most-positive-float
                ;; custom-print-functions
                ))
-  (defvaralias var (intern (format "cl-%s" var))))
+  (define-obsolete-variable-alias var (intern (format "cl-%s" var)) "27.1"))
 
 (dolist (fun '(
                (get* . cl-get)
@@ -291,7 +291,7 @@ cl-unload-function
                ))
   (let ((new (if (consp fun) (prog1 (cdr fun) (setq fun (car fun)))
                (intern (format "cl-%s" fun)))))
-    (defalias fun new)))
+    (define-obsolete-function-alias fun new "27.1")))
 
 (defun cl--wrap-in-nil-block (fun &rest args)
   `(cl-block nil ,(apply fun args)))
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#44792: [PATCH] Remove specific byte-compiler warnings for cl.el
  2020-11-22 11:09 bug#44792: [PATCH] Remove specific byte-compiler warnings for cl.el Stefan Kangas
@ 2020-11-22 15:15 ` Stefan Monnier
  2020-12-02  9:27   ` Stefan Kangas
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2020-11-22 15:15 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 44792

> Thoughts?

LGTM, thank you,


        Stefan






^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#44792: [PATCH] Remove specific byte-compiler warnings for cl.el
  2020-11-22 15:15 ` Stefan Monnier
@ 2020-12-02  9:27   ` Stefan Kangas
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Kangas @ 2020-12-02  9:27 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 44792

tags 44792 fixed
close 44792 28.1
thanks

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Thoughts?
>
> LGTM, thank you,

Thanks.  No further comments within 10 days; pushed to master as commit
ed1730718f and closing.





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-02  9:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-22 11:09 bug#44792: [PATCH] Remove specific byte-compiler warnings for cl.el Stefan Kangas
2020-11-22 15:15 ` Stefan Monnier
2020-12-02  9:27   ` Stefan Kangas

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).