From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.devel Subject: Re: Towards a cleaner build Date: Sat, 18 May 2019 08:45:08 +0200 Message-ID: References: <831s0xd3z1.fsf@gnu.org> <83pnohbhny.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="29498"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Eli Zaretskii , Noam Postavsky , Emacs developers To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat May 18 08:45:56 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hRt6R-0007XQ-RH for ged-emacs-devel@m.gmane.org; Sat, 18 May 2019 08:45:56 +0200 Original-Received: from localhost ([127.0.0.1]:58515 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRt6Q-00035q-RK for ged-emacs-devel@m.gmane.org; Sat, 18 May 2019 02:45:54 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:51769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRt5p-00035Y-2n for emacs-devel@gnu.org; Sat, 18 May 2019 02:45:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hRt5n-0007xl-G1 for emacs-devel@gnu.org; Sat, 18 May 2019 02:45:17 -0400 Original-Received: from quimby.gnus.org ([80.91.231.51]:47900) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hRt5n-0007vy-4S; Sat, 18 May 2019 02:45:15 -0400 Original-Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=stories) by quimby.gnus.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hRt5g-0005ND-6l; Sat, 18 May 2019 08:45:10 +0200 Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAKlBMVEVuAD7PY1FqAD3DS0hn AD3n2+WqOUOkGz2aDTyaKj6KAz7////XhXhkADxqGL9hAAACXUlEQVQ4jZWUv2vbQBTHj4wCD4cg qYsKhRYKhQziwHLAQwevGTUEeYgRyBTqIQhydmihtGBdDB6CS1wVDCZDKwQZPWlyTQqBC4QkGFS4 /6XvnZqWtkqgX0kn6X3ej9PTSSTLPG/uZl72l0iWua7neuXALQfZfJ65paBUAObeHI7SCCxSCiDk P2qoO3QPiO8CU4V7eapuOVi1vyrVLPRnRPzhBTFicqu1tacFuLkiFeOz+SnVMmYItwE8hytjmHaN 9JeO1sk2uUTDl4/vp2NHoIZwJ+UuOKfKSA/H8DRtDU6UJaV8OCPGTH0X05VSeREBagNISZqo3HgH 0+hEnIueGNbFQMoHKUnEqcp7I5X7nJ+qiXi7IaLQbFSJALDiYYdDwKZ6xvsBZosCACM14SzoOJy/ UUJHQk5BBJyc8PXFE9bjPE8QREgIjKETvbq4XjInNIU63q+jbw9AyBzhV23WZ4xFmxtcq0fADvKV Or5izOH7cGMCOEHg2NSOVTtndr0DZkBYg/sYweAlXtu0vkfPFkuG8yBc282pyo8oaienGMMKQM1H Kh43JEqtWnIBAKuBY9XcakNbGy2rG0gaUEZgUjamqFWx3fLM3bFoHNQQaLu1WGgg5bm9HK/7jPiY yJIwaPM3M2ZWTdIC/PSVWHSyF9DYBlAEFKI2tc4H4csVtEADusBB6gfojPox9gZSaQTGGu/wIbyJ AcMu/vMZCBFu3S7RZvMxMQy9Cg9nSeTv3iC4JASWCijRi3AIW2qQSoUkM7g8iEQkeNITIjkQAn1m xP0tiUMLJVvyvj9DuX4AOIl7wr/k51MAAAAASUVORK5CYII= In-Reply-To: (Stefan Monnier's message of "Fri, 17 May 2019 08:28:16 -0400") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 80.91.231.51 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:236704 Archived-At: Stefan Monnier writes: >> So if we want to go this direction it looks like it can be done in a >> pretty clean fashion. > > Pretty please? I made a proof of concept thing by just cargo-culting the code for with-no-warnings, and it works! I used the ehelp.el warning to test with (with-suppressed-warnings ((interactive-only execute-extended-command)) (setq electric-help-form-to-execute (lambda () (execute-extended-command nil)))) and now it compiles cleanly and even seems to work!? Both interactively and byte-compiled, although more testing is required. There's some details in the interface that could be bike-shedded... for instance, how often do we need several things suppressed at once? If we limit it to one thing at a time, then we lose one set of parentheses: (with-suppressed-warnings (interactive-only execute-extended-command) ...) In the rare cases you need more, you can say (with-suppressed-warnings (obsolete something-else) (with-suppressed-warnings (interactive-only execute-extended-command) ...)) You can also either just allow one symbol to be suppressed per warning type, or more, and the implementation supports the latter, so you can say: (with-suppressed-warnings ((obsolete something something-else)) ...) I think that makes sense, and it doesn't add more (or less) visual clutter.. Eli, what do you think? Is `with-suppressed-warnings' something you can see Emacs having? If so, I can finish it up and write some documentation... 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