changeset 86003:e33327200372

* emacs-lisp/byte-opt.el (byte-optimize-featurep): Optimize (featurep 'emacs) to t. * emacs-lisp/bytecomp.el (byte-compile-find-bound-condition): New function. (byte-compile-maybe-guarded): Use it to also look for bound symbols inside `and' forms. Comment out non-working code that was trying to avoid warnings for XEmacs code.
author Dan Nicolaescu <dann@ics.uci.edu>
date Sat, 10 Nov 2007 08:05:15 +0000
parents 613df1ba1584
children 7c2160a058cb
files lisp/ChangeLog lisp/emacs-lisp/byte-opt.el lisp/emacs-lisp/bytecomp.el
diffstat 3 files changed, 57 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Sat Nov 10 05:22:16 2007 +0000
+++ b/lisp/ChangeLog	Sat Nov 10 08:05:15 2007 +0000
@@ -1,5 +1,14 @@
 2007-11-10  Dan Nicolaescu  <dann@ics.uci.edu>
 
+	* emacs-lisp/byte-opt.el (byte-optimize-featurep): Optimize
+	(featurep 'emacs) to t.
+
+	* emacs-lisp/bytecomp.el (byte-compile-find-bound-condition): New
+	function.
+	(byte-compile-maybe-guarded): Use it to also look for bound
+	symbols inside `and' forms.  Comment out non-working code that was
+	trying to avoid warnings for XEmacs code.
+
 	* vc.el (vc-diff-internal): Make the *vc-diff* buffer read only.
 
 	* vc-svn.el (vc-svn-print-log, vc-svn-diff):
--- a/lisp/emacs-lisp/byte-opt.el	Sat Nov 10 05:22:16 2007 +0000
+++ b/lisp/emacs-lisp/byte-opt.el	Sat Nov 10 08:05:15 2007 +0000
@@ -1150,7 +1150,9 @@
   ;; can safely optimize away this test.
   (if (member (cdr-safe form) '(((quote xemacs)) ((quote sxemacs))))
       nil
-    form))
+    (if (member (cdr-safe form) '(((quote emacs))))
+	t
+      form)))
 
 (put 'set 'byte-optimizer 'byte-optimize-set)
 (defun byte-optimize-set (form)
--- a/lisp/emacs-lisp/bytecomp.el	Sat Nov 10 05:22:16 2007 +0000
+++ b/lisp/emacs-lisp/bytecomp.el	Sat Nov 10 08:05:15 2007 +0000
@@ -3492,6 +3492,32 @@
       (if ,discard 'byte-goto-if-nil 'byte-goto-if-nil-else-pop))
     ,tag))
 
+;; Return the list of items in CONDITION-PARAM that match PRED-LIST.
+;; Only return items that are not in ONLY-IF-NOT-PRESENT.
+(defun byte-compile-find-bound-condition (condition-param 
+					  pred-list 
+					  &optional only-if-not-present)
+  (let ((result nil)
+	(nth-one nil)
+	(cond-list 
+	 (if (memq (car-safe condition-param) pred-list)
+	     ;; The condition appears by itself.
+	     (list condition-param)
+	   ;; If the condition is an `and', look for matches among the
+	   ;; `and' arguments.
+	   (when (eq 'and (car-safe condition-param))
+	     (cdr condition-param)))))
+    
+    (dolist (crt cond-list)
+      (when (and (memq (car-safe crt) pred-list)
+		 (eq 'quote (car-safe (setq nth-one (nth 1 crt))))
+		 ;; Ignore if the symbol is already on the unresolved
+		 ;; list.
+		 (not (assq (nth 1 nth-one) ; the relevant symbol
+			    only-if-not-present)))
+	(push (nth 1 (nth 1 crt)) result)))
+    result))
+
 (defmacro byte-compile-maybe-guarded (condition &rest body)
   "Execute forms in BODY, potentially guarded by CONDITION.
 CONDITION is a variable whose value is a test in an `if' or `cond'.
@@ -3503,35 +3529,34 @@
 If CONDITION's value is (not (featurep 'emacs)) or (featurep 'xemacs),
 that suppresses all warnings during execution of BODY."
   (declare (indent 1) (debug t))
-  `(let* ((fbound
-	   (if (eq 'fboundp (car-safe ,condition))
-	       (and (eq 'quote (car-safe (nth 1 ,condition)))
-		    ;; Ignore if the symbol is already on the
-		    ;; unresolved list.
-		    (not (assq (nth 1 (nth 1 ,condition)) ; the relevant symbol
-			       byte-compile-unresolved-functions))
-		    (nth 1 (nth 1 ,condition)))))
-	  (bound (if (or (eq 'boundp (car-safe ,condition))
-			 (eq 'default-boundp (car-safe ,condition)))
-		     (and (eq 'quote (car-safe (nth 1 ,condition)))
-			  (nth 1 (nth 1 ,condition)))))
+  `(let* ((fbound-list (byte-compile-find-bound-condition 
+			,condition (list 'fboundp) 
+			byte-compile-unresolved-functions))
+	  (bound-list (byte-compile-find-bound-condition 
+		       ,condition (list 'boundp 'default-boundp)))
 	  ;; Maybe add to the bound list.
 	  (byte-compile-bound-variables
-	   (if bound
-	       (cons bound byte-compile-bound-variables)
+	   (if bound-list
+	       (append bound-list byte-compile-bound-variables)
 	     byte-compile-bound-variables))
 	  ;; Suppress all warnings, for code not used in Emacs.
-	  (byte-compile-warnings
-	   (if (member ,condition '((featurep 'xemacs)
-				    (not (featurep 'emacs))))
-	       nil byte-compile-warnings)))
+	  ;; FIXME: by the time this is executed the `featurep'
+	  ;; emacs/xemacs tests have been optimized away, so this is
+	  ;; not doing anything useful here, is should probably be
+	  ;; moved to a different place.
+	  ;; (byte-compile-warnings
+	  ;;  (if (member ,condition '((featurep 'xemacs)
+	  ;; 			    (not (featurep 'emacs))))
+	  ;;      nil byte-compile-warnings))
+	  )
      (unwind-protect
 	 (progn ,@body)
        ;; Maybe remove the function symbol from the unresolved list.
-       (if fbound
+       (dolist (fbound fbound-list)
+	 (when fbound
 	   (setq byte-compile-unresolved-functions
 		 (delq (assq fbound byte-compile-unresolved-functions)
-		       byte-compile-unresolved-functions))))))
+		       byte-compile-unresolved-functions)))))))
 
 (defun byte-compile-if (form)
   (byte-compile-form (car (cdr form)))