aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2015-11-21 18:43:57 +0000
committerAlan Mackenzie2015-11-21 18:43:57 +0000
commitab4df9ce7d57bb391e56ddd5feee3d227bfce76d (patch)
tree178b46b507e0abfda1913f88c749fea48d725398
parentd696d62fea48096680d6d511a71c4df56d00a51f (diff)
downloademacs-fix/not-defined-at-runtime.tar.gz
emacs-fix/not-defined-at-runtime.zip
Byte compiler: fix spurious warnings "might not be defined at runtime".fix/not-defined-at-runtime
Also initialize byte-compile-noruntime-functions between runs. bytecomp.el (byte-compile-new-defuns): New variable. (byte-compile-initial-macro-environment): For eval-when-compile: bind byte-compile-unresolved-functions and byte-compile-new-defuns around byte-compile-top-level, to prevent spurious entries being made. (byte-compile-warn-about-unresolved-functions): Check whether function is in byte-compile-new-defuns before emitting a warning about it. (byte-compile-from-buffer): Initialize new variable and byte-compile-noruntime-functions to nil. (byte-compile-file-form-require): record all new functions defined by a `require' in byte-compile-new-defuns. (byte-compile-file-form-defmumble): record the new alias in byte-compile-new-defuns.
-rw-r--r--lisp/emacs-lisp/bytecomp.el40
1 files changed, 33 insertions, 7 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 024719168af..35743644f06 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -456,10 +456,14 @@ Return the compile-time value of FORM."
456 (byte-compile-recurse-toplevel 456 (byte-compile-recurse-toplevel
457 (macroexp-progn body) 457 (macroexp-progn body)
458 (lambda (form) 458 (lambda (form)
459 (setf result 459 (let ((byte-compile-unresolved-functions
460 (byte-compile-eval 460 byte-compile-unresolved-functions)
461 (byte-compile-top-level 461 (byte-compile-new-defuns
462 (byte-compile-preprocess form)))))) 462 byte-compile-new-defuns))
463 (setf result
464 (byte-compile-eval
465 (byte-compile-top-level
466 (byte-compile-preprocess form)))))))
463 (list 'quote result)))) 467 (list 'quote result))))
464 (eval-and-compile . ,(lambda (&rest body) 468 (eval-and-compile . ,(lambda (&rest body)
465 (byte-compile-recurse-toplevel 469 (byte-compile-recurse-toplevel
@@ -503,6 +507,11 @@ defined with incorrect args.")
503Used for warnings about calling a function that is defined during compilation 507Used for warnings about calling a function that is defined during compilation
504but won't necessarily be defined when the compiled file is loaded.") 508but won't necessarily be defined when the compiled file is loaded.")
505 509
510(defvar byte-compile-new-defuns nil
511 "List of functions defined for use at runtime.
512This variable is used to qualify `byte-compile-noruntime-functions' when
513outputting warnings about functions not being defined at runtime.")
514
506;; Variables for lexical binding 515;; Variables for lexical binding
507(defvar byte-compile--lexical-environment nil 516(defvar byte-compile--lexical-environment nil
508 "The current lexical environment.") 517 "The current lexical environment.")
@@ -1503,8 +1512,9 @@ extra args."
1503 ;; Separate the functions that will not be available at runtime 1512 ;; Separate the functions that will not be available at runtime
1504 ;; from the truly unresolved ones. 1513 ;; from the truly unresolved ones.
1505 (dolist (f byte-compile-unresolved-functions) 1514 (dolist (f byte-compile-unresolved-functions)
1506 (setq f (car f)) 1515 (setq f (car f))
1507 (if (fboundp f) (push f noruntime) (push f unresolved))) 1516 (when (not (memq f byte-compile-new-defuns))
1517 (if (fboundp f) (push f noruntime) (push f unresolved))))
1508 ;; Complain about the no-run-time functions 1518 ;; Complain about the no-run-time functions
1509 (byte-compile-print-syms 1519 (byte-compile-print-syms
1510 "the function `%s' might not be defined at runtime." 1520 "the function `%s' might not be defined at runtime."
@@ -1961,6 +1971,8 @@ With argument ARG, insert value in current buffer after the form."
1961 ;; compiled. A: Yes! b-c-u-f might contain dross from a 1971 ;; compiled. A: Yes! b-c-u-f might contain dross from a
1962 ;; previous byte-compile. 1972 ;; previous byte-compile.
1963 (setq byte-compile-unresolved-functions nil) 1973 (setq byte-compile-unresolved-functions nil)
1974 (setq byte-compile-noruntime-functions nil)
1975 (setq byte-compile-new-defuns nil)
1964 1976
1965 ;; Compile the forms from the input buffer. 1977 ;; Compile the forms from the input buffer.
1966 (while (progn 1978 (while (progn
@@ -2346,8 +2358,21 @@ list that represents a doc string reference.
2346(defun byte-compile-file-form-require (form) 2358(defun byte-compile-file-form-require (form)
2347 (let ((args (mapcar 'eval (cdr form))) 2359 (let ((args (mapcar 'eval (cdr form)))
2348 (hist-orig load-history) 2360 (hist-orig load-history)
2349 hist-new) 2361 hist-new prov-cons)
2350 (apply 'require args) 2362 (apply 'require args)
2363
2364 ;; Record the functions defined by the require in `byte-compille-new-defuns'.
2365 (setq hist-new load-history)
2366 (setq prov-cons (cons 'provide (car args)))
2367 (while (and hist-new
2368 (not (member prov-cons (car hist-new))))
2369 (setq hist-new (cdr hist-new)))
2370 (when hist-new
2371 (dolist (x (car hist-new))
2372 (when (and (consp x)
2373 (memq (car x) '(defun t)))
2374 (push (cdr x) byte-compile-new-defuns))))
2375
2351 (when (byte-compile-warning-enabled-p 'cl-functions) 2376 (when (byte-compile-warning-enabled-p 'cl-functions)
2352 ;; Detect (require 'cl) in a way that works even if cl is already loaded. 2377 ;; Detect (require 'cl) in a way that works even if cl is already loaded.
2353 (if (member (car args) '("cl" cl)) 2378 (if (member (car args) '("cl" cl))
@@ -2403,6 +2428,7 @@ not to take responsibility for the actual compilation of the code."
2403 (byte-compile-current-form name)) ; For warnings. 2428 (byte-compile-current-form name)) ; For warnings.
2404 2429
2405 (byte-compile-set-symbol-position name) 2430 (byte-compile-set-symbol-position name)
2431 (push name byte-compile-new-defuns)
2406 ;; When a function or macro is defined, add it to the call tree so that 2432 ;; When a function or macro is defined, add it to the call tree so that
2407 ;; we can tell when functions are not used. 2433 ;; we can tell when functions are not used.
2408 (if byte-compile-generate-call-tree 2434 (if byte-compile-generate-call-tree