From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#21466: [PATCH] Avoid defining (temporarily) vars and functions Date: Wed, 06 Nov 2019 02:29:09 +0100 Message-ID: <87wocd4wt6.fsf@marxist.se> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="114363"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Alan Mackenzie , 21466@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Nov 06 02:30:16 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iSA9H-000Tda-GF for geb-bug-gnu-emacs@m.gmane.org; Wed, 06 Nov 2019 02:30:15 +0100 Original-Received: from localhost ([::1]:52216 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iSA9G-0003dT-D1 for geb-bug-gnu-emacs@m.gmane.org; Tue, 05 Nov 2019 20:30:14 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47888) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iSA98-0003dJ-VZ for bug-gnu-emacs@gnu.org; Tue, 05 Nov 2019 20:30:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iSA97-0002Eq-C2 for bug-gnu-emacs@gnu.org; Tue, 05 Nov 2019 20:30:06 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:58749) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iSA95-0002BN-4S; Tue, 05 Nov 2019 20:30:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iSA94-0002TO-SW; Tue, 05 Nov 2019 20:30:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Wed, 06 Nov 2019 01:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21466 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: patch Original-Received: via spool by 21466-submit@debbugs.gnu.org id=B21466.15730037619421 (code B ref 21466); Wed, 06 Nov 2019 01:30:02 +0000 Original-Received: (at 21466) by debbugs.gnu.org; 6 Nov 2019 01:29:21 +0000 Original-Received: from localhost ([127.0.0.1]:39337 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iSA8O-0002Rr-G9 for submit@debbugs.gnu.org; Tue, 05 Nov 2019 20:29:20 -0500 Original-Received: from host.gofardesign.uk ([208.79.239.190]:38761) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iSA8M-0002Rd-6A for 21466@debbugs.gnu.org; Tue, 05 Nov 2019 20:29:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=marxist.se; s=default; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID: Date:References:In-Reply-To:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Ks8ygVjs2Vdnvv41xWejtFa/RMjo8r88/KIB67yYpwA=; b=dImy7fC5oOsc7IMgrxXGEkXdvN l5zbwkiHO2sda7dTBVrTyvGcNVkx9AXiPfLYeO0+TtoKh50CqOuOcPfoF0ShWysRjWzQHM06KQOYC pC73Tb+J1DR0DTz1IYmsVuqcrYiqR5jIV2282GT/Z8GmyTyMpOIJskH67MjbZ0CTOg4w=; Original-Received: from h-70-69.a785.priv.bahnhof.se ([155.4.70.69]:49380 helo=localhost) by host.gofardesign.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1iSA8E-0007vp-TB; Tue, 05 Nov 2019 19:29:12 -0600 In-Reply-To: (Stefan Monnier's message of "Fri, 11 Sep 2015 23:36:45 -0400") X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - host.gofardesign.uk X-AntiAbuse: Original Domain - debbugs.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - marxist.se X-Get-Message-Sender-Via: host.gofardesign.uk: authenticated_id: stefan@marxist.se X-Authenticated-Sender: host.gofardesign.uk: stefan@marxist.se X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:171007 Archived-At: Stefan Monnier writes: > Package: Emacs > Version: 25.0.50 > > > CC-mode currently defines various non-CC-mode variables and functions > with dummy values, as a way to avoid byte-compiler warnings when using > those external vars/functions. > > Since this is dangerous business, CC-mode has to be extra careful to > undo such settings when they're not needed any more. > > It might have made sense back in the days when the byte-compiler did not > offer built-in ways to silence those warnings, but nowadays we can > do better. > > Any objections to the patch below (which also removes the unused > cc-bytecomp-put, while we're at it)? Hi Alan, This patch was sent to the bug list in 2015, but it seems like it never got a reply at the time. Assuming this patch is still relevant, could you please take a look? Best regards, Stefan Kangas > 2015-09-12 Stefan Monnier > > * lisp/progmodes/cc-bytecomp.el: Use newer compiler-silencers. > (cc-bytecomp-defvar): Use just (defvar ) when that is known to > silence the byte-compiler warnings. > (cc-bytecomp-defun): Use just (declare-function ) when that is > known to silence the byte-compiler warnings. > (cc-bytecomp-boundp, cc-bytecomp-fboundp): Change accordingly. > (cc-bytecomp-put): Remove, unused. > (cc-bytecomp-original-properties): Remove var. > (cc-bytecomp-setup-environment, cc-bytecomp-restore-environment): > Don't use cc-bytecomp-original-properties any more. > > > diff --git a/lisp/progmodes/cc-bytecomp.el b/lisp/progmodes/cc-bytecomp.el > index 81b7a82..fff2a9e 100644 > --- a/lisp/progmodes/cc-bytecomp.el > +++ b/lisp/progmodes/cc-bytecomp.el > @@ -75,12 +75,10 @@ >=20=20 > (defvar cc-bytecomp-unbound-variables nil) > (defvar cc-bytecomp-original-functions nil) > -(defvar cc-bytecomp-original-properties nil) > (defvar cc-bytecomp-loaded-files nil) >=20=20 > (setq cc-bytecomp-unbound-variables nil) > (setq cc-bytecomp-original-functions nil) > -(setq cc-bytecomp-original-properties nil) > (setq cc-bytecomp-loaded-files nil) >=20=20 > (defvar cc-bytecomp-environment-set nil) > @@ -173,16 +171,6 @@ perhaps a `cc-bytecomp-restore-environment' is forgo= tten somewhere")) > (cc-bytecomp-debug-msg > "cc-bytecomp-setup-environment: Covered function %s" fun)))) > (setq p (cdr p))) > - (setq p cc-bytecomp-original-properties) > - (while p > - (let ((sym (car (car (car p)))) > - (prop (cdr (car (car p)))) > - (tempdef (car (cdr (car p))))) > - (put sym prop tempdef) > - (cc-bytecomp-debug-msg > - "cc-bytecomp-setup-environment: Bound property %s for %s to %s" > - prop sym tempdef)) > - (setq p (cdr p))) > (setq cc-bytecomp-environment-set t) > (cc-bytecomp-debug-msg > "cc-bytecomp-setup-environment: Done")))) > @@ -232,22 +220,6 @@ perhaps a `cc-bytecomp-restore-environment' is forgo= tten somewhere")) > "cc-bytecomp-restore-environment: Not restoring function %s" > fun)))) > (setq p (cdr p))) > - (setq p cc-bytecomp-original-properties) > - (while p > - (let ((sym (car (car (car p)))) > - (prop (cdr (car (car p)))) > - (tempdef (car (cdr (car p)))) > - (origdef (cdr (cdr (car p))))) > - (if (eq (get sym prop) tempdef) > - (progn > - (put sym prop origdef) > - (cc-bytecomp-debug-msg > - "cc-bytecomp-restore-environment: Restored property %s for %s to %s" > - prop sym origdef)) > - (cc-bytecomp-debug-msg > - "cc-bytecomp-restore-environment: Not restoring property %s for = %s" > - prop sym))) > - (setq p (cdr p))) > (setq cc-bytecomp-environment-set nil) > (cc-bytecomp-debug-msg > "cc-bytecomp-restore-environment: Done")))) > @@ -348,25 +320,28 @@ afterwards. Don't use within `eval-when-compile'." > (eval-when-compile (cc-bytecomp-setup-environment)))) >=20=20 > (defmacro cc-bytecomp-defvar (var) > - "Binds the symbol as a variable during compilation of the file, > + "Bind the symbol as a variable during compilation of the file, > to silence the byte compiler. Don't use within `eval-when-compile'." > - `(eval-when-compile > - (if (boundp ',var) > - (cc-bytecomp-debug-msg > - "cc-bytecomp-defvar: %s bound already as variable" ',var) > - (if (not (memq ',var cc-bytecomp-unbound-variables)) > - (progn > - (cc-bytecomp-debug-msg > - "cc-bytecomp-defvar: Saving %s (as unbound)" ',var) > - (setq cc-bytecomp-unbound-variables > - (cons ',var cc-bytecomp-unbound-variables)))) > - (if (cc-bytecomp-is-compiling) > - (progn > - (defvar ,var) > - (set ',var (intern (concat "cc-bytecomp-ignore-var:" > - (symbol-name ',var)))) > - (cc-bytecomp-debug-msg > - "cc-bytecomp-defvar: Covered variable %s" ',var)))))) > + (if (not (featurep 'xemacs)) > + `(defvar ,var) > + ;; Not sure if XEmacs's =E2=80=98defvar=E2=80=99 works in the same w= ay. > + `(eval-when-compile > + (if (boundp ',var) > + (cc-bytecomp-debug-msg > + "cc-bytecomp-defvar: %s bound already as variable" ',var) > + (if (not (memq ',var cc-bytecomp-unbound-variables)) > + (progn > + (cc-bytecomp-debug-msg > + "cc-bytecomp-defvar: Saving %s (as unbound)" ',var) > + (setq cc-bytecomp-unbound-variables > + (cons ',var cc-bytecomp-unbound-variables)))) > + (if (cc-bytecomp-is-compiling) > + (progn > + (defvar ,var) > + (set ',var (intern (concat "cc-bytecomp-ignore-var:" > + (symbol-name ',var)))) > + (cc-bytecomp-debug-msg > + "cc-bytecomp-defvar: Covered variable %s" ',var))))))) >=20=20 > (defmacro cc-bytecomp-defun (fun) > "Bind the symbol as a function during compilation of the file, > @@ -377,48 +352,33 @@ definition. That means that this macro will not sh= ut up warnings > about incorrect number of arguments. It's dangerous to try to replace > existing functions since the byte compiler might need the definition > at compile time, e.g. for macros and inline functions." > - `(eval-when-compile > - (if (fboundp ',fun) > - (cc-bytecomp-debug-msg > - "cc-bytecomp-defun: %s bound already as function" ',fun) > - (if (not (assq ',fun cc-bytecomp-original-functions)) > - (progn > - (cc-bytecomp-debug-msg > - "cc-bytecomp-defun: Saving %s (as unbound)" ',fun) > - (setq cc-bytecomp-original-functions > - (cons (list ',fun nil 'unbound) > - cc-bytecomp-original-functions)))) > - (if (cc-bytecomp-is-compiling) > - (progn > - (fset ',fun (intern (concat "cc-bytecomp-ignore-fun:" > - (symbol-name ',fun)))) > - (cc-bytecomp-debug-msg > - "cc-bytecomp-defun: Covered function %s" ',fun)))))) > - > -(defmacro cc-bytecomp-put (symbol propname value) > - "Set a property on a symbol during compilation (and evaluation) of > -the file. Don't use outside `eval-when-compile'." > - `(eval-when-compile > - (if (not (assoc (cons ,symbol ,propname) cc-bytecomp-original-prope= rties)) > - (progn > + (if (fboundp 'declare-function) > + `(declare-function ,fun nil) > + `(eval-when-compile > + (if (fboundp ',fun) > (cc-bytecomp-debug-msg > - "cc-bytecomp-put: Saving property %s for %s with value %s" > - ,propname ,symbol (get ,symbol ,propname)) > - (setq cc-bytecomp-original-properties > - (cons (cons (cons ,symbol ,propname) > - (cons ,value (get ,symbol ,propname))) > - cc-bytecomp-original-properties)))) > - (put ,symbol ,propname ,value) > - (cc-bytecomp-debug-msg > - "cc-bytecomp-put: Bound property %s for %s to %s" > - ,propname ,symbol ,value))) > + "cc-bytecomp-defun: %s bound already as function" ',fun) > + (if (not (assq ',fun cc-bytecomp-original-functions)) > + (progn > + (cc-bytecomp-debug-msg > + "cc-bytecomp-defun: Saving %s (as unbound)" ',fun) > + (setq cc-bytecomp-original-functions > + (cons (list ',fun nil 'unbound) > + cc-bytecomp-original-functions)))) > + (if (cc-bytecomp-is-compiling) > + (progn > + (fset ',fun (intern (concat "cc-bytecomp-ignore-fun:" > + (symbol-name ',fun)))) > + (cc-bytecomp-debug-msg > + "cc-bytecomp-defun: Covered function %s" ',fun))))))) >=20=20 > (defmacro cc-bytecomp-boundp (symbol) > "Return non-nil if the given symbol is bound as a variable outside > the compilation. This is the same as using `boundp' but additionally > exclude any variables that have been bound during compilation with > `cc-bytecomp-defvar'." > - (if (and (cc-bytecomp-is-compiling) > + (if (and (featurep 'xemacs) > + (cc-bytecomp-is-compiling) > (memq (car (cdr symbol)) cc-bytecomp-unbound-variables)) > nil > `(boundp ,symbol))) > @@ -429,7 +389,8 @@ the compilation. This is the same as using `fboundp'= but additionally > exclude any functions that have been bound during compilation with > `cc-bytecomp-defun'." > (let (fun-elem) > - (if (and (cc-bytecomp-is-compiling) > + (if (and (not (fboundp 'declare-function)) > + (cc-bytecomp-is-compiling) > (setq fun-elem (assq (car (cdr symbol)) > cc-bytecomp-original-functions)) > (eq (elt fun-elem 2) 'unbound))