aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2000-03-24 18:37:48 +0000
committerStefan Monnier2000-03-24 18:37:48 +0000
commita586093f7954aec3111ef2dd59dd1d9720948d70 (patch)
tree7c97178b2711629d6b3e962b359f9c78d169185a
parent39210e90adf7be66c7ca6c9fd702bbe11e4887e7 (diff)
downloademacs-a586093f7954aec3111ef2dd59dd1d9720948d70.tar.gz
emacs-a586093f7954aec3111ef2dd59dd1d9720948d70.zip
(byte-compile-warning-types, byte-compile-warnings): New warning `noruntime'.
(byte-compile-constants, byte-compile-variables): Fix docstring. (byte-compile-initial-macro-environment): Use `byte-compile-eval' to execute `eval-whenc-compile's body. (byte-compile-unresolved-functions): Fix docstring. (byte-compile-eval): New function. (byte-compile-callargs-warn): Check if the function will be available at runtime (via property `byte-compile-noruntime'). (byte-compile-print-syms): New function. (byte-compile-warn-about-unresolved-functions): Also warn about `noruntime' functions (and use `byte-compile-print-syms'). (byte-compile-file): Capitalize the message.
-rw-r--r--lisp/emacs-lisp/bytecomp.el107
1 files changed, 76 insertions, 31 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 285b2766b2b..394b16fc3b4 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -10,7 +10,7 @@
10 10
11;;; This version incorporates changes up to version 2.10 of the 11;;; This version incorporates changes up to version 2.10 of the
12;;; Zawinski-Furuseth compiler. 12;;; Zawinski-Furuseth compiler.
13(defconst byte-compile-version "$Revision: 2.62 $") 13(defconst byte-compile-version "$Revision: 2.63 $")
14 14
15;; This file is part of GNU Emacs. 15;; This file is part of GNU Emacs.
16 16
@@ -32,7 +32,8 @@
32;;; Commentary: 32;;; Commentary:
33 33
34;; The Emacs Lisp byte compiler. This crunches lisp source into a sort 34;; The Emacs Lisp byte compiler. This crunches lisp source into a sort
35;; of p-code which takes up less space and can be interpreted faster. 35;; of p-code (`lapcode') which takes up less space and can be interpreted
36;; faster. [`LAP' == `Lisp Assembly Program'.]
36;; The user entry points are byte-compile-file and byte-recompile-directory. 37;; The user entry points are byte-compile-file and byte-recompile-directory.
37 38
38;;; Code: 39;;; Code:
@@ -99,6 +100,8 @@
99;; a macro to a lambda or vice versa, 100;; a macro to a lambda or vice versa,
100;; or redefined to take other args) 101;; or redefined to take other args)
101;; 'obsolete (obsolete variables and functions) 102;; 'obsolete (obsolete variables and functions)
103;; 'noruntime (calls to functions only defined
104;; within `eval-when-compile')
102;; byte-compile-compatibility Whether the compiler should 105;; byte-compile-compatibility Whether the compiler should
103;; generate .elc files which can be loaded into 106;; generate .elc files which can be loaded into
104;; generic emacs 18. 107;; generic emacs 18.
@@ -324,7 +327,7 @@ If it is 'byte, then only byte-level optimizations will be logged."
324 :type 'boolean) 327 :type 'boolean)
325 328
326(defconst byte-compile-warning-types 329(defconst byte-compile-warning-types
327 '(redefine callargs free-vars unresolved obsolete)) 330 '(redefine callargs free-vars unresolved obsolete noruntime))
328(defcustom byte-compile-warnings t 331(defcustom byte-compile-warnings t
329 "*List of warnings that the byte-compiler should issue (t for all). 332 "*List of warnings that the byte-compiler should issue (t for all).
330Elements of the list may be be: 333Elements of the list may be be:
@@ -340,7 +343,7 @@ Elements of the list may be be:
340 (set :menu-tag "Some" 343 (set :menu-tag "Some"
341 (const free-vars) (const unresolved) 344 (const free-vars) (const unresolved)
342 (const callargs) (const redefined) 345 (const callargs) (const redefined)
343 (const obsolete)))) 346 (const obsolete) (const noruntime))))
344 347
345(defcustom byte-compile-generate-call-tree nil 348(defcustom byte-compile-generate-call-tree nil
346 "*Non-nil means collect call-graph information when compiling. 349 "*Non-nil means collect call-graph information when compiling.
@@ -386,9 +389,9 @@ specify different fields to sort on."
386;; which the link points to being overwritten.") 389;; which the link points to being overwritten.")
387 390
388(defvar byte-compile-constants nil 391(defvar byte-compile-constants nil
389 "list of all constants encountered during compilation of this form") 392 "List of all constants encountered during compilation of this form.")
390(defvar byte-compile-variables nil 393(defvar byte-compile-variables nil
391 "list of all variables encountered during compilation of this form") 394 "List of all variables encountered during compilation of this form.")
392(defvar byte-compile-bound-variables nil 395(defvar byte-compile-bound-variables nil
393 "List of variables bound in the context of the current form. 396 "List of variables bound in the context of the current form.
394This list lives partly on the stack.") 397This list lives partly on the stack.")
@@ -402,8 +405,9 @@ This list lives partly on the stack.")
402;; (byte-compiler-options . (lambda (&rest forms) 405;; (byte-compiler-options . (lambda (&rest forms)
403;; (apply 'byte-compiler-options-handler forms))) 406;; (apply 'byte-compiler-options-handler forms)))
404 (eval-when-compile . (lambda (&rest body) 407 (eval-when-compile . (lambda (&rest body)
405 (list 'quote (eval (byte-compile-top-level 408 (list 'quote
406 (cons 'progn body)))))) 409 (byte-compile-eval (byte-compile-top-level
410 (cons 'progn body))))))
407 (eval-and-compile . (lambda (&rest body) 411 (eval-and-compile . (lambda (&rest body)
408 (eval (cons 'progn body)) 412 (eval (cons 'progn body))
409 (cons 'progn body)))) 413 (cons 'progn body))))
@@ -423,8 +427,9 @@ Each element looks like (FUNCTIONNAME . DEFINITION). It is
423\(FUNCTIONNAME . nil) when a function is redefined as a macro.") 427\(FUNCTIONNAME . nil) when a function is redefined as a macro.")
424 428
425(defvar byte-compile-unresolved-functions nil 429(defvar byte-compile-unresolved-functions nil
426 "Alist of undefined functions to which calls have been compiled (used for 430 "Alist of undefined functions to which calls have been compiled.
427warnings when the function is later defined with incorrect args).") 431Used for warnings when the function is not known to be defined or is later
432defined with incorrect args.")
428 433
429(defvar byte-compile-tag-number 0) 434(defvar byte-compile-tag-number 0)
430(defvar byte-compile-output nil 435(defvar byte-compile-output nil
@@ -755,6 +760,28 @@ otherwise pop it")
755 (concat (nreverse bytes)))) 760 (concat (nreverse bytes))))
756 761
757 762
763;;; compile-time evaluation
764
765(defun byte-compile-eval (x)
766 (let ((hist-orig load-history)
767 (hist-nil-orig current-load-list))
768 (prog1 (eval x)
769 (when (memq 'noruntime byte-compile-warnings)
770 (let ((hist-new load-history)
771 (hist-nil-new current-load-list))
772 (while (not (eq hist-new hist-orig))
773 (dolist (s (pop hist-new))
774 (cond
775 ((symbolp s) (put s 'byte-compile-noruntime t))
776 ((and (consp s) (eq 'autoload (car s)))
777 (put (cdr s) 'byte-compile-noruntime t)))))
778 (while (not (eq hist-nil-new hist-nil-orig))
779 (let ((s (pop hist-nil-new)))
780 (when (symbolp s)
781 (put s 'byte-compile-noruntime t)))))))))
782
783
784
758;;; byte compiler messages 785;;; byte compiler messages
759 786
760(defvar byte-compile-current-form nil) 787(defvar byte-compile-current-form nil)
@@ -1012,7 +1039,8 @@ otherwise pop it")
1012 "requires" 1039 "requires"
1013 "accepts only") 1040 "accepts only")
1014 (byte-compile-arglist-signature-string sig))) 1041 (byte-compile-arglist-signature-string sig)))
1015 (or (fboundp (car form)) ; might be a subr or autoload. 1042 (or (and (fboundp (car form)) ; might be a subr or autoload.
1043 (not (get (car form) 'byte-compile-noruntime)))
1016 (eq (car form) byte-compile-current-form) ; ## this doesn't work 1044 (eq (car form) byte-compile-current-form) ; ## this doesn't work
1017 ; with recursion. 1045 ; with recursion.
1018 ;; It's a currently-undefined function. 1046 ;; It's a currently-undefined function.
@@ -1067,29 +1095,46 @@ otherwise pop it")
1067 (delq calls byte-compile-unresolved-functions))))) 1095 (delq calls byte-compile-unresolved-functions)))))
1068 ))) 1096 )))
1069 1097
1098(defun byte-compile-print-syms (str1 strn syms)
1099 (cond
1100 ((cdr syms)
1101 (let* ((str strn)
1102 (L (length str))
1103 s)
1104 (while syms
1105 (setq s (symbol-name (pop syms))
1106 L (+ L (length s) 2))
1107 (if (< L (1- fill-column))
1108 (setq str (concat str " " s (and syms ",")))
1109 (setq str (concat str "\n " s (and syms ","))
1110 L (+ (length s) 4))))
1111 (byte-compile-warn "%s" str)))
1112 (syms
1113 (byte-compile-warn str1 (car syms)))))
1114
1070;; If we have compiled any calls to functions which are not known to be 1115;; If we have compiled any calls to functions which are not known to be
1071;; defined, issue a warning enumerating them. 1116;; defined, issue a warning enumerating them.
1072;; `unresolved' in the list `byte-compile-warnings' disables this. 1117;; `unresolved' in the list `byte-compile-warnings' disables this.
1073(defun byte-compile-warn-about-unresolved-functions () 1118(defun byte-compile-warn-about-unresolved-functions ()
1074 (if (memq 'unresolved byte-compile-warnings) 1119 (when (memq 'unresolved byte-compile-warnings)
1075 (let ((byte-compile-current-form "the end of the data")) 1120 (let ((byte-compile-current-form "the end of the data")
1076 (if (cdr byte-compile-unresolved-functions) 1121 (noruntime nil)
1077 (let* ((str "The following functions are not known to be defined:") 1122 (unresolved nil))
1078 (L (length str)) 1123 ;; Separate the functions that will not be available at runtime
1079 (rest (reverse byte-compile-unresolved-functions)) 1124 ;; from the truly unresolved ones.
1080 s) 1125 (dolist (f byte-compile-unresolved-functions)
1081 (while rest 1126 (setq f (car f))
1082 (setq s (symbol-name (car (car rest))) 1127 (if (fboundp f) (push f noruntime) (push f unresolved)))
1083 L (+ L (length s) 2) 1128 ;; Complain about the no-run-time functions
1084 rest (cdr rest)) 1129 (byte-compile-print-syms
1085 (if (< L (1- fill-column)) 1130 "The function `%s' might not be defined at runtime."
1086 (setq str (concat str " " s (and rest ","))) 1131 "The following functions might not be defined at runtime:"
1087 (setq str (concat str "\n " s (and rest ",")) 1132 noruntime)
1088 L (+ (length s) 4)))) 1133 ;; Complain about the unresolved functions
1089 (byte-compile-warn "%s" str)) 1134 (byte-compile-print-syms
1090 (if byte-compile-unresolved-functions 1135 "The function `%s' is not known to be defined."
1091 (byte-compile-warn "the function %s is not known to be defined." 1136 "The following functions are not known to be defined:"
1092 (car (car byte-compile-unresolved-functions))))))) 1137 unresolved)))
1093 nil) 1138 nil)
1094 1139
1095 1140
@@ -1273,7 +1318,7 @@ The value is t if there were no errors, nil if errors."
1273 (or noninteractive 1318 (or noninteractive
1274 (let ((b (get-file-buffer (expand-file-name filename)))) 1319 (let ((b (get-file-buffer (expand-file-name filename))))
1275 (if (and b (buffer-modified-p b) 1320 (if (and b (buffer-modified-p b)
1276 (y-or-n-p (format "save buffer %s first? " (buffer-name b)))) 1321 (y-or-n-p (format "Save buffer %s first? " (buffer-name b))))
1277 (save-excursion (set-buffer b) (save-buffer))))) 1322 (save-excursion (set-buffer b) (save-buffer)))))
1278 1323
1279 (if byte-compile-verbose 1324 (if byte-compile-verbose