GNU bug report logs - #21466
[PATCH] Avoid defining (temporarily) vars and functions

Previous Next

Packages: cc-mode, emacs;

Reported by: Stefan Monnier <monnier <at> iro.umontreal.ca>

Date: Sat, 12 Sep 2015 03:41:01 UTC

Severity: normal

Tags: patch, wontfix

Found in version 25.0.50

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 21466 in the body.
You can then email your comments to 21466 AT debbugs.gnu.org in the normal way.

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-cc-mode <at> gnu.org, bug-gnu-emacs <at> gnu.org:
bug#21466; Package emacs. (Sat, 12 Sep 2015 03:41:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
New bug report received and forwarded. Copy sent to bug-cc-mode <at> gnu.org, bug-gnu-emacs <at> gnu.org. (Sat, 12 Sep 2015 03:41:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Avoid defining (temporarily) vars and functions
Date: Fri, 11 Sep 2015 23:36:45 -0400
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)?


        Stefan


2015-09-12  Stefan Monnier  <monnier <at> iro.umontreal.ca>

	* lisp/progmodes/cc-bytecomp.el: Use newer compiler-silencers.
	(cc-bytecomp-defvar): Use just (defvar <foo>) when that is known to
	silence the byte-compiler warnings.
	(cc-bytecomp-defun): Use just (declare-function <foo>) 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 @@
 
 (defvar cc-bytecomp-unbound-variables nil)
 (defvar cc-bytecomp-original-functions nil)
-(defvar cc-bytecomp-original-properties nil)
 (defvar cc-bytecomp-loaded-files nil)
 
 (setq cc-bytecomp-unbound-variables nil)
 (setq cc-bytecomp-original-functions nil)
-(setq cc-bytecomp-original-properties nil)
 (setq cc-bytecomp-loaded-files nil)
 
 (defvar cc-bytecomp-environment-set nil)
@@ -173,16 +171,6 @@ perhaps a `cc-bytecomp-restore-environment' is forgotten 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 forgotten 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))))
 
 (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 ‘defvar’ works in the same way.
+    `(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)))))))
 
 (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 shut 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-properties))
-	 (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)))))))
 
 (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))




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#21466; Package emacs,cc-mode. (Thu, 29 Oct 2015 13:10:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: 21466 <at> debbugs.gnu.org
Cc: bug-cc-mode <at> gnu.org
Subject: Re: bug#21466: [PATCH] Avoid defining (temporarily) vars and functions
Date: Thu, 29 Oct 2015 09:09:29 -0400
Ping?


        Stefan


>>>>> "Stefan" == Stefan Monnier <monnier <at> iro.umontreal.ca> 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)?


>         Stefan


> 2015-09-12  Stefan Monnier  <monnier <at> iro.umontreal.ca>

> 	* lisp/progmodes/cc-bytecomp.el: Use newer compiler-silencers.
> 	(cc-bytecomp-defvar): Use just (defvar <foo>) when that is known to
> 	silence the byte-compiler warnings.
> 	(cc-bytecomp-defun): Use just (declare-function <foo>) 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 @@
 
>  (defvar cc-bytecomp-unbound-variables nil)
>  (defvar cc-bytecomp-original-functions nil)
> -(defvar cc-bytecomp-original-properties nil)
>  (defvar cc-bytecomp-loaded-files nil)
 
>  (setq cc-bytecomp-unbound-variables nil)
>  (setq cc-bytecomp-original-functions nil)
> -(setq cc-bytecomp-original-properties nil)
>  (setq cc-bytecomp-loaded-files nil)
 
>  (defvar cc-bytecomp-environment-set nil)
> @@ -173,16 +171,6 @@ perhaps a `cc-bytecomp-restore-environment' is forgotten 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 forgotten 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))))
 
>  (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 ‘defvar’ works in the same way.
> +    `(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)))))))
 
>  (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 shut 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-properties))
> -	 (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)))))))
 
>  (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))








Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#21466; Package emacs,cc-mode. (Wed, 06 Nov 2019 01:30:02 GMT) Full text and rfc822 format available.

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

From: Stefan Kangas <stefan <at> marxist.se>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Alan Mackenzie <acm <at> muc.de>, 21466 <at> debbugs.gnu.org
Subject: Re: bug#21466: [PATCH] Avoid defining (temporarily) vars and functions
Date: Wed, 06 Nov 2019 02:29:09 +0100
Stefan Monnier <monnier <at> iro.umontreal.ca> 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  <monnier <at> iro.umontreal.ca>
>
> 	* lisp/progmodes/cc-bytecomp.el: Use newer compiler-silencers.
> 	(cc-bytecomp-defvar): Use just (defvar <foo>) when that is known to
> 	silence the byte-compiler warnings.
> 	(cc-bytecomp-defun): Use just (declare-function <foo>) 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 @@
>  
>  (defvar cc-bytecomp-unbound-variables nil)
>  (defvar cc-bytecomp-original-functions nil)
> -(defvar cc-bytecomp-original-properties nil)
>  (defvar cc-bytecomp-loaded-files nil)
>  
>  (setq cc-bytecomp-unbound-variables nil)
>  (setq cc-bytecomp-original-functions nil)
> -(setq cc-bytecomp-original-properties nil)
>  (setq cc-bytecomp-loaded-files nil)
>  
>  (defvar cc-bytecomp-environment-set nil)
> @@ -173,16 +171,6 @@ perhaps a `cc-bytecomp-restore-environment' is forgotten 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 forgotten 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))))
>  
>  (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 ‘defvar’ works in the same way.
> +    `(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)))))))
>  
>  (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 shut 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-properties))
> -	 (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)))))))
>  
>  (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))




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#21466; Package emacs,cc-mode. (Mon, 10 May 2021 11:46:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Alan Mackenzie <acm <at> muc.de>, 21466 <at> debbugs.gnu.org
Subject: Re: bug#21466: [PATCH] Avoid defining (temporarily) vars and functions
Date: Mon, 10 May 2021 13:45:21 +0200
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

> 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.

This was five years ago, but skimming the code, it seems like it's
generally applicable still?

Alan, do you have any comments on this patch?

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




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#21466; Package emacs,cc-mode. (Tue, 11 May 2021 20:35:01 GMT) Full text and rfc822 format available.

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

From: Alan Mackenzie <acm <at> muc.de>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>, 21466 <at> debbugs.gnu.org
Subject: Re: bug#21466: [PATCH] Avoid defining (temporarily) vars and functions
Date: Tue, 11 May 2021 20:34:30 +0000
Hello, Lars.

On Mon, May 10, 2021 at 13:45:21 +0200, Lars Ingebrigtsen wrote:
> Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

> > 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.

> This was five years ago, but skimming the code, it seems like it's
> generally applicable still?

> Alan, do you have any comments on this patch?

I meant to comment on it back then, but the patch is unusually difficult
to follow: most of the context lines are unhelpful in giving the
context, and the git macros identifying the current function in the diff
aren't working here, to a large degree.

There are little things I'm unhappy about with the patch: it explicitly
tests (featurep 'xemacs), which is not done in CC Mode, being regarded
as somewhat vulgar.  Instead specific functionalities are always tested
for.

Also, in place of cc-bytecomp-defun is proposed declare-function.
However this is in an inconsistent state, with the documentation
requiring a FILE argument, but Stefan's patch supplying nil.

It seems that cc-bytecomp-defvar has long (?always) been unnecessary,
given that (defvar foo) has ?always had the desired effect, even in
XEmacs.  So I don't have anything against clearing out the
cc-bytecomp-defvar's.

So, I don't object on principle to the principle of the patch, just
there are these little irritations about it, and it will need me to
study it more closely to check nothing subtle would get lost (I doubt it
would).

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

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#21466; Package emacs,cc-mode. (Tue, 11 May 2021 22:04:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Alan Mackenzie <acm <at> muc.de>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 21466 <at> debbugs.gnu.org
Subject: Re: bug#21466: [PATCH] Avoid defining (temporarily) vars and functions
Date: Tue, 11 May 2021 18:03:38 -0400
> There are little things I'm unhappy about with the patch: it
> explicitly tests (featurep 'xemacs), which is not done in CC Mode,
> being regarded as somewhat vulgar.  Instead specific functionalities
> are always tested for.

I use (featurep 'xemacs) because it results in cleaner byte-code because
the compiler replaces it with nil.  It also usually results in fewer
spurious warnings (because of the removal of XEmacs-only code).
[ I believe the same holds on XEmacs where (featurep 'xemacs) is
  optimized to t, which removes Emacs-only code.  ]
But that's just my favorite bikeshed color, it's not crucial for the patch.

> Also, in place of cc-bytecomp-defun is proposed declare-function.
> However this is in an inconsistent state, with the documentation
> requiring a FILE argument, but Stefan's patch supplying nil.

`declare-function` says:

    The FILE argument is not used by the byte-compiler, but by the
    `check-declare' package, which checks that FILE contains a
    definition for FN.

So indeed, a real FILE argument would be preferable, but passing nil
works fine (it will simply prevent `check-declare` from making sure
that file indeed defines that function, which is no different than what
we have now with `cc-bytecomp-defun` which `check-declare` also
ignores).
If you want the "better" option, then it will require changing
`cc-bytecomp-defun` so it takes a FILE arg.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#21466; Package emacs,cc-mode. (Fri, 23 Jul 2021 13:15:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Alan Mackenzie <acm <at> muc.de>, 21466 <at> debbugs.gnu.org
Subject: Re: bug#21466: [PATCH] Avoid defining (temporarily) vars and functions
Date: Fri, 23 Jul 2021 15:14:41 +0200
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

>> Also, in place of cc-bytecomp-defun is proposed declare-function.
>> However this is in an inconsistent state, with the documentation
>> requiring a FILE argument, but Stefan's patch supplying nil.
>
> `declare-function` says:
>
>     The FILE argument is not used by the byte-compiler, but by the
>     `check-declare' package, which checks that FILE contains a
>     definition for FN.
>
> So indeed, a real FILE argument would be preferable, but passing nil
> works fine (it will simply prevent `check-declare` from making sure
> that file indeed defines that function,

I've now amended the doc string to `declare-function on the trunk to
mention this.

Alan, it sounded like you were generally positive to the patch (except
for the `declare-function' bit, which should now be clarified and the
(featurep 'xemacs))?  

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




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#21466; Package emacs,cc-mode. (Fri, 23 Jul 2021 15:02:02 GMT) Full text and rfc822 format available.

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

From: Glenn Morris <rgm <at> gnu.org>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Alan Mackenzie <acm <at> muc.de>, Stefan Monnier <monnier <at> iro.umontreal.ca>,
 21466 <at> debbugs.gnu.org
Subject: Re: bug#21466: [PATCH] Avoid defining (temporarily) vars and functions
Date: Fri, 23 Jul 2021 11:01:03 -0400
Lars Ingebrigtsen wrote:

>> So indeed, a real FILE argument would be preferable, but passing nil
>> works fine (it will simply prevent `check-declare` from making sure
>> that file indeed defines that function,
>
> I've now amended the doc string to `declare-function on the trunk to
> mention this.

Whilst that may happen to work as a kludge, it's against the intent of
declare-function, so personally I would prefer that it either remained
undocumented, or you do it properly and make FILE an optional argument
(I haven't checked if check-declare would need changes for that).

Ref: https://lists.gnu.org/r/emacs-devel/2007-11/msg01409.html




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#21466; Package emacs,cc-mode. (Sat, 24 Jul 2021 10:27:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Glenn Morris <rgm <at> gnu.org>
Cc: Alan Mackenzie <acm <at> muc.de>, Stefan Monnier <monnier <at> iro.umontreal.ca>,
 21466 <at> debbugs.gnu.org
Subject: Re: bug#21466: [PATCH] Avoid defining (temporarily) vars and functions
Date: Sat, 24 Jul 2021 12:26:30 +0200
Glenn Morris <rgm <at> gnu.org> writes:

> Whilst that may happen to work as a kludge, it's against the intent of
> declare-function, so personally I would prefer that it either remained
> undocumented, or you do it properly and make FILE an optional argument
> (I haven't checked if check-declare would need changes for that).

I almost made it optional at the same time, but then changed my mind --
the nil case is abnormal and it probably almost always an error, so
having an explicit nil parameter seemed a more productive alternative.

But if others feel differently, go ahead and change it.

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




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#21466; Package emacs,cc-mode. (Wed, 23 Mar 2022 20:14:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Alan Mackenzie <acm <at> muc.de>
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>, 21466 <at> debbugs.gnu.org
Subject: Re: bug#21466: [PATCH] Avoid defining (temporarily) vars and functions
Date: Wed, 23 Mar 2022 21:13:35 +0100
Alan Mackenzie <acm <at> muc.de> writes:

> So, I don't object on principle to the principle of the patch, just
> there are these little irritations about it, and it will need me to
> study it more closely to check nothing subtle would get lost (I doubt it
> would).

The patch no longer applied to Emacs 29, so I've respun it.



diff --git a/lisp/progmodes/cc-bytecomp.el b/lisp/progmodes/cc-bytecomp.el
index 4b8154dafe..277ba29a89 100644
--- a/lisp/progmodes/cc-bytecomp.el
+++ b/lisp/progmodes/cc-bytecomp.el
@@ -75,12 +75,10 @@
 
 (defvar cc-bytecomp-unbound-variables nil)
 (defvar cc-bytecomp-original-functions nil)
-(defvar cc-bytecomp-original-properties nil)
 (defvar cc-bytecomp-loaded-files nil)
 
 (setq cc-bytecomp-unbound-variables nil)
 (setq cc-bytecomp-original-functions nil)
-(setq cc-bytecomp-original-properties nil)
 (setq cc-bytecomp-loaded-files nil)
 
 (defvar cc-bytecomp-environment-set nil)
@@ -177,16 +175,6 @@ cc-bytecomp-setup-environment
 		  (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"))))
@@ -236,22 +224,6 @@ cc-bytecomp-restore-environment
 		   "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"))))
@@ -385,23 +357,26 @@ cc-bytecomp-defvar
 This can be used to silence the byte compiler.  Don't use within
 `eval-when-compile'."
   (declare (debug nil))
-  `(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 `defvar' works in the same way.
+    `(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)))))))
 
 (defmacro cc-bytecomp-defun (fun)
   "Bind the symbol FUN as a function during compilation of the file.
@@ -414,42 +389,25 @@ cc-bytecomp-defun
 existing functions since the byte compiler might need the definition
 at compile time, e.g. for macros and inline functions."
   (declare (debug nil))
-  `(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 SYMBOL during compilation (and evaluation) of the file.
-Don't use outside `eval-when-compile'."
-  (declare (debug t))
-  `(eval-when-compile
-     (if (not (assoc (cons ,symbol ,propname) cc-bytecomp-original-properties))
-	 (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)))))))
 
 (defmacro cc-bytecomp-boundp (symbol)
   "Return non-nil if SYMBOL is bound as a variable outside the compilation.
@@ -457,7 +415,8 @@ cc-bytecomp-boundp
 variables that have been bound during compilation with
 `cc-bytecomp-defvar'."
   (declare (debug t))
-  (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)))
@@ -469,7 +428,8 @@ cc-bytecomp-fboundp
 `cc-bytecomp-defun'."
   (declare (debug t))
   (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))


However, it leads to a number of warnings when compiling, so either my
respin is faulty, or something's changed to make it not work any more?


In c-fontify-recorded-types-and-refs:
progmodes/cc-fonts.el:491:8: Warning: function `c-fontify-recorded-types-and-refs' defined multiple times in this file
  ELC      progmodes/cc-styles.elc
In c-font-lock-declarators:
progmodes/cc-fonts.el:1063:8: Warning: function `c-font-lock-declarators' defined multiple times in this file
progmodes/cc-fonts.el:2300:35: Warning: reference to free variable `c-preprocessor-face-name'
progmodes/cc-fonts.el:2300:35: Warning: reference to free variable `c-preprocessor-face-name'
progmodes/cc-fonts.el:2496:37: Warning: reference to free variable `c-preprocessor-face-name'
progmodes/cc-fonts.el:2496:37: Warning: reference to free variable `c-preprocessor-face-name'
progmodes/cc-fonts.el:2501:37: Warning: reference to free variable `c-reference-face-name'
In c-font-lock-objc-method:
progmodes/cc-fonts.el:2527:8: Warning: function `c-font-lock-objc-method' defined multiple times in this file
progmodes/cc-fonts.el:2602:38: Warning: reference to free variable `c-preprocessor-face-name'
progmodes/cc-fonts.el:2602:38: Warning: reference to free variable `c-preprocessor-face-name'
progmodes/cc-fonts.el:2650:38: Warning: reference to free variable `c-reference-face-name'
progmodes/cc-fonts.el:2678:37: Warning: reference to free variable `c-preprocessor-face-name'
progmodes/cc-fonts.el:2678:37: Warning: reference to free variable `c-preprocessor-face-name'
progmodes/cc-fonts.el:2683:37: Warning: reference to free variable `c-reference-face-name'
progmodes/cc-fonts.el:2711:38: Warning: reference to free variable `c-preprocessor-face-name'
progmodes/cc-fonts.el:2711:38: Warning: reference to free variable `c-preprocessor-face-name'
progmodes/cc-fonts.el:2716:38: Warning: reference to free variable `c-reference-face-name'




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#21466; Package emacs,cc-mode. (Fri, 25 Mar 2022 21:10:02 GMT) Full text and rfc822 format available.

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

From: Alan Mackenzie <acm <at> muc.de>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>, 21466 <at> debbugs.gnu.org
Subject: Re: bug#21466: [PATCH] Avoid defining (temporarily) vars and functions
Date: Fri, 25 Mar 2022 21:09:11 +0000
Hello, Lars.

On Wed, Mar 23, 2022 at 21:13:35 +0100, Lars Ingebrigtsen wrote:
> Alan Mackenzie <acm <at> muc.de> writes:

> > So, I don't object on principle to the principle of the patch, just
> > there are these little irritations about it, and it will need me to
> > study it more closely to check nothing subtle would get lost (I doubt it
> > would).

> The patch no longer applied to Emacs 29, so I've respun it.

[ .... ]

I'll take a look at it, hopefully over the weekend.

> However, it leads to a number of warnings when compiling, so either my
> respin is faulty, or something's changed to make it not work any more?


> In c-fontify-recorded-types-and-refs:
> progmodes/cc-fonts.el:491:8: Warning: function `c-fontify-recorded-types-and-refs' defined multiple times in this file
>   ELC      progmodes/cc-styles.elc
> In c-font-lock-declarators:
> progmodes/cc-fonts.el:1063:8: Warning: function `c-font-lock-declarators' defined multiple times in this file
> progmodes/cc-fonts.el:2300:35: Warning: reference to free variable `c-preprocessor-face-name'
> progmodes/cc-fonts.el:2300:35: Warning: reference to free variable `c-preprocessor-face-name'
> progmodes/cc-fonts.el:2496:37: Warning: reference to free variable `c-preprocessor-face-name'
> progmodes/cc-fonts.el:2496:37: Warning: reference to free variable `c-preprocessor-face-name'
> progmodes/cc-fonts.el:2501:37: Warning: reference to free variable `c-reference-face-name'
> In c-font-lock-objc-method:
> progmodes/cc-fonts.el:2527:8: Warning: function `c-font-lock-objc-method' defined multiple times in this file
> progmodes/cc-fonts.el:2602:38: Warning: reference to free variable `c-preprocessor-face-name'
> progmodes/cc-fonts.el:2602:38: Warning: reference to free variable `c-preprocessor-face-name'
> progmodes/cc-fonts.el:2650:38: Warning: reference to free variable `c-reference-face-name'
> progmodes/cc-fonts.el:2678:37: Warning: reference to free variable `c-preprocessor-face-name'
> progmodes/cc-fonts.el:2678:37: Warning: reference to free variable `c-preprocessor-face-name'
> progmodes/cc-fonts.el:2683:37: Warning: reference to free variable `c-reference-face-name'
> progmodes/cc-fonts.el:2711:38: Warning: reference to free variable `c-preprocessor-face-name'
> progmodes/cc-fonts.el:2711:38: Warning: reference to free variable `c-preprocessor-face-name'
> progmodes/cc-fonts.el:2716:38: Warning: reference to free variable `c-reference-face-name'

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#21466; Package emacs,cc-mode. (Sat, 26 Mar 2022 14:46:01 GMT) Full text and rfc822 format available.

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

From: Alan Mackenzie <acm <at> muc.de>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: acm <at> muc.de, Stefan Monnier <monnier <at> iro.umontreal.ca>,
 21466 <at> debbugs.gnu.org
Subject: Re: bug#21466: [PATCH] Avoid defining (temporarily) vars and functions
Date: Sat, 26 Mar 2022 14:45:40 +0000
Hello again, Lars.

On Wed, Mar 23, 2022 at 21:13:35 +0100, Lars Ingebrigtsen wrote:
> Alan Mackenzie <acm <at> muc.de> writes:

> > So, I don't object on principle to the principle of the patch, just
> > there are these little irritations about it, and it will need me to
> > study it more closely to check nothing subtle would get lost (I doubt it
> > would).

> The patch no longer applied to Emacs 29, so I've respun it.

[ .... ]


> However, it leads to a number of warnings when compiling, so either my
> respin is faulty, or something's changed to make it not work any more?

Maybe it didn't work properly back in 2015, I didn't actually get around
to trying it out, then.

> In c-fontify-recorded-types-and-refs:
> progmodes/cc-fonts.el:491:8: Warning: function `c-fontify-recorded-types-and-refs' defined multiple times in this file
>   ELC      progmodes/cc-styles.elc
> In c-font-lock-declarators:
> progmodes/cc-fonts.el:1063:8: Warning: function `c-font-lock-declarators' defined multiple times in this file
> progmodes/cc-fonts.el:2300:35: Warning: reference to free variable `c-preprocessor-face-name'
> progmodes/cc-fonts.el:2300:35: Warning: reference to free variable `c-preprocessor-face-name'
> progmodes/cc-fonts.el:2496:37: Warning: reference to free variable `c-preprocessor-face-name'
> progmodes/cc-fonts.el:2496:37: Warning: reference to free variable `c-preprocessor-face-name'
> progmodes/cc-fonts.el:2501:37: Warning: reference to free variable `c-reference-face-name'
> In c-font-lock-objc-method:
> progmodes/cc-fonts.el:2527:8: Warning: function `c-font-lock-objc-method' defined multiple times in this file
> progmodes/cc-fonts.el:2602:38: Warning: reference to free variable `c-preprocessor-face-name'
> progmodes/cc-fonts.el:2602:38: Warning: reference to free variable `c-preprocessor-face-name'
> progmodes/cc-fonts.el:2650:38: Warning: reference to free variable `c-reference-face-name'
> progmodes/cc-fonts.el:2678:37: Warning: reference to free variable `c-preprocessor-face-name'
> progmodes/cc-fonts.el:2678:37: Warning: reference to free variable `c-preprocessor-face-name'
> progmodes/cc-fonts.el:2683:37: Warning: reference to free variable `c-reference-face-name'
> progmodes/cc-fonts.el:2711:38: Warning: reference to free variable `c-preprocessor-face-name'
> progmodes/cc-fonts.el:2711:38: Warning: reference to free variable `c-preprocessor-face-name'
> progmodes/cc-fonts.el:2716:38: Warning: reference to free variable `c-reference-face-name'

The patch is essentially replacing cc-bytecomp-defvar by (defvar foo),
and cc-bytecomp-defun by (declare-function 'foo nil).  These are only
approximately similar.

cc-bytecomp-def{var,fun} are like C's extern.  They say "this
variable/function will be defined somewhere else".

By contrast, (defvar foo) doesn't really do anything (?except marking
any possible foo as a special variable).  (declare-function 'foo nil)
says "This function HAS ALREADY been defined somewhere else (and don't
you dare redefine it!)."

These explain the "free variable" warnings for the variables and the
"defined multiple times" warnings for the functions.

To sort out this bug properly, we really need Lisp functions equivalent
to C's extern.  (defvar foo) and (declare-function 'foo nil) currently
don't fill this need.

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#21466; Package emacs,cc-mode. (Sat, 26 Mar 2022 16:48:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Alan Mackenzie <acm <at> muc.de>
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>, 21466 <at> debbugs.gnu.org
Subject: Re: bug#21466: [PATCH] Avoid defining (temporarily) vars and functions
Date: Sat, 26 Mar 2022 17:47:24 +0100
Alan Mackenzie <acm <at> muc.de> writes:

> These explain the "free variable" warnings for the variables and the
> "defined multiple times" warnings for the functions.
>
> To sort out this bug properly, we really need Lisp functions equivalent
> to C's extern.  (defvar foo) and (declare-function 'foo nil) currently
> don't fill this need.

I had a brief look at a couple of the warnings (after the patch), and it
looks like the warnings could be resolved by just removing the
cc-bytecomp-deffun (and rearranging the code order).

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




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#21466; Package emacs,cc-mode. (Sat, 26 Mar 2022 19:52:01 GMT) Full text and rfc822 format available.

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

From: Alan Mackenzie <acm <at> muc.de>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>, 21466 <at> debbugs.gnu.org
Subject: Re: bug#21466: [PATCH] Avoid defining (temporarily) vars and functions
Date: Sat, 26 Mar 2022 19:51:35 +0000
Hello, Lars.

On Sat, Mar 26, 2022 at 17:47:24 +0100, Lars Ingebrigtsen wrote:
> Alan Mackenzie <acm <at> muc.de> writes:

> > These explain the "free variable" warnings for the variables and the
> > "defined multiple times" warnings for the functions.

> > To sort out this bug properly, we really need Lisp functions equivalent
> > to C's extern.  (defvar foo) and (declare-function 'foo nil) currently
> > don't fill this need.

> I had a brief look at a couple of the warnings (after the patch), and it
> looks like the warnings could be resolved by just removing the
> cc-bytecomp-deffun (and rearranging the code order).

The whole patch was predicated on:

    >>>> 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.

I'm not convinced that what the byte compiler currently offers is
"better", if that involves having to rearrange things in a source file.
And even then, that would only resolve two of the ~15 warning messages.

By contrast, leaving things alone is not causing any trouble, and seems
unlikely to cause trouble in the near future.

There is currently no clean way of declaring a symbol's variable or
function cell as bound for the byte compiler.  Perhaps there should be.

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

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#21466; Package emacs,cc-mode. (Tue, 29 Mar 2022 12:27:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Alan Mackenzie <acm <at> muc.de>
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>, 21466 <at> debbugs.gnu.org
Subject: Re: bug#21466: [PATCH] Avoid defining (temporarily) vars and functions
Date: Tue, 29 Mar 2022 14:26:28 +0200
Alan Mackenzie <acm <at> muc.de> writes:

> By contrast, leaving things alone is not causing any trouble, and seems
> unlikely to cause trouble in the near future.

OK, I guess the conclusion here is that we're not going to apply this
patch, so I'm closing this bug report.

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




Added tag(s) wontfix. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 29 Mar 2022 12:27:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 21466 <at> debbugs.gnu.org and Stefan Monnier <monnier <at> iro.umontreal.ca> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 29 Mar 2022 12:27:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#21466; Package emacs,cc-mode. (Tue, 29 Mar 2022 21:03:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Alan Mackenzie <acm <at> muc.de>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 21466 <at> debbugs.gnu.org
Subject: Re: bug#21466: [PATCH] Avoid defining (temporarily) vars and functions
Date: Tue, 29 Mar 2022 17:02:04 -0400
> There is currently no clean way of declaring a symbol's variable or
> function cell as bound for the byte compiler.

I think there is: (defvar <foo>) and (declare-function <bar>) is used
for that by all other ELisp packages.


        Stefan





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 27 Apr 2022 11:24:11 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 14 days ago.

Previous Next


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