emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Towards a cleaner build


From: Lars Ingebrigtsen
Subject: Re: Towards a cleaner build
Date: Tue, 28 May 2019 17:11:28 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Eli Zaretskii <address@hidden> writes:

>> From: Lars Ingebrigtsen <address@hidden>
>> Cc: Eli Zaretskii <address@hidden>, Stefan Monnier
>> <address@hidden>, Emacs developers <address@hidden>
>> Date: Tue, 28 May 2019 13:39:46 +0200
>> 
>> And Eli hasn't OK'd the with-suppressed-warnings yet.  :-)  Did that
>> patch look OK?
>
> Not sure what this alludes to.  I may have missed some question?

It's this patch.  It adds the syntax

  (with-suppressed-warnings (obsolete some-function)
    (some-function la la la))

which is very similar to with-no-warnings, only it specifies precisely
which warning on what function we're suppressing.

diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el
index 842d1d48b4..9a9d93367b 100644
--- a/lisp/emacs-lisp/byte-run.el
+++ b/lisp/emacs-lisp/byte-run.el
@@ -494,6 +494,18 @@ with-no-warnings
   ;; The implementation for the interpreter is basically trivial.
   (car (last body)))
 
+(defmacro with-suppressed-warnings (warnings &rest body)
+  "Like `progn', but prevents compiler warnings in the body."
+  (declare (indent 1))
+  ;; The implementation for the interpreter is basically trivial.
+  `(with-suppressed-warnings-1 ',warnings (progn ,@body)))
+
+(defun with-suppressed-warnings-1 (_ &rest body)
+  "Like `progn', but prevents compiler warnings in the body."
+  (declare (indent 1))
+  ;; The implementation for the interpreter is basically trivial.
+  (car (last body)))
+
 
 (defun byte-run--unescaped-character-literals-warning ()
   "Return a warning about unescaped character literals.
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index e76baf5ed0..1285ef9037 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -331,18 +331,26 @@ byte-compile-warnings
                       ,@(mapcar (lambda (x) `(const ,x))
                                 byte-compile-warning-types))))
 
+(defvar byte-compile-suppressed-warnings nil)
+
 ;;;###autoload
 (put 'byte-compile-warnings 'safe-local-variable
      (lambda (v)
        (or (symbolp v)
            (null (delq nil (mapcar (lambda (x) (not (symbolp x))) v))))))
 
-(defun byte-compile-warning-enabled-p (warning)
+(defun byte-compile-warning-enabled-p (warning &optional symbol)
   "Return non-nil if WARNING is enabled, according to `byte-compile-warnings'."
-  (or (eq byte-compile-warnings t)
-      (if (eq (car byte-compile-warnings) 'not)
-          (not (memq warning byte-compile-warnings))
-        (memq warning byte-compile-warnings))))
+  (let ((suppress nil))
+    (dolist (elem byte-compile-suppressed-warnings)
+      (when (and (eq (car elem) warning)
+                 (memq symbol (cdr elem)))
+        (setq suppress t)))
+    (and (not suppress)
+         (or (eq byte-compile-warnings t)
+             (if (eq (car byte-compile-warnings) 'not)
+                 (not (memq warning byte-compile-warnings))
+               (memq warning byte-compile-warnings))))))
 
 ;;;###autoload
 (defun byte-compile-disable-warning (warning)
@@ -2518,6 +2526,15 @@ byte-compile-file-form-with-no-warnings
     (mapc 'byte-compile-file-form (cdr form))
     nil))
 
+(put 'with-suppressed-warnings-1 'byte-hunk-handler
+     'byte-compile-file-form-with-suppressed-warnings)
+(defun byte-compile-file-form-with-suppressed-warnings (form)
+  ;; cf byte-compile-file-form-progn.
+  (let ((byte-compile-suppressed-warnings
+         (append (cadadr form) byte-compile-suppressed-warnings)))
+    (mapc 'byte-compile-file-form (cddr form))
+    nil))
+
 ;; Automatically evaluate define-obsolete-function-alias etc at top-level.
 (put 'make-obsolete 'byte-hunk-handler 'byte-compile-file-form-make-obsolete)
 (defun byte-compile-file-form-make-obsolete (form)
@@ -3150,7 +3167,7 @@ byte-compile-form
         (when (and (byte-compile-warning-enabled-p 'suspicious)
                    (macroexp--const-symbol-p fn))
           (byte-compile-warn "`%s' called as a function" fn))
-       (when (and (byte-compile-warning-enabled-p 'interactive-only)
+       (when (and (byte-compile-warning-enabled-p 'interactive-only fn)
                   interactive-only)
          (byte-compile-warn "`%s' is for interactive use only%s"
                             fn
@@ -4765,6 +4782,14 @@ byte-compile-no-warnings
   (let (byte-compile-warnings)
     (byte-compile-form (cons 'progn (cdr form)))))
 
+(byte-defop-compiler-1 with-suppressed-warnings-1
+                       byte-compile-suppressed-warnings)
+(defun byte-compile-suppressed-warnings (form)
+  (let ((byte-compile-suppressed-warnings
+         (append (cadadr form) byte-compile-suppressed-warnings)))
+    (mapc 'byte-compile-file-form (cddr form))
+    nil))
+
 ;; Warn about misuses of make-variable-buffer-local.
 (byte-defop-compiler-1 make-variable-buffer-local
                        byte-compile-make-variable-buffer-local)


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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]