unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* BUG + FIX. Spurious "might not be defined at runtime" from byte-compile-file
@ 2006-05-23 10:15 Alan Mackenzie
  2006-05-24  2:18 ` Richard Stallman
  0 siblings, 1 reply; 2+ messages in thread
From: Alan Mackenzie @ 2006-05-23 10:15 UTC (permalink / raw)


Hi, Emacs!

Evaluate the following:

(defun foo ()
  (bar))
(byte-compile 'foo)
(defun bar ())
(byte-compile 'bar)

Get a cup of coffee, go for a twenty mile run, come back and do some
furious hacking.

Then do M-x byte-compile-file jrandom.el.  You get the spurious warning:

  ** The function `bar' might not be defined at runtime.

This happens because the (byte-compile 'foo) form (correctly) flags 'bar
as an unknown function, recording it in
byte-compile-unresolved-functions.  The subsequent byte-compile-file
initialises this variable AFTER doing the compilation rather than before
- hence the silly warning.

It seems to me this state of affairs was probably caused by the sloppy
doc-string for the variable - it doesn't give any context for when its
contents are gathered and used, hence hackers were (subconsciously)
scared to initialise it properly, fearing they might discard important
info.  So I've amended the doc-string too.

Should I commit this fix?



2006-05-23  Alan Mackenzie  <acm@muc.de>

	* emacs-lisp/bytecomp.el (byte-compile-from-buffer): initialize
	byte-compile-unresolved-functions before doing a compilation
	rather than afterwards.  Amend the variable's doc-string.


Index: bytecomp.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/emacs-lisp/bytecomp.el,v
retrieving revision 2.183
diff -c -r2.183 bytecomp.el
*** bytecomp.el	11 Apr 2006 17:58:49 -0000	2.183
--- bytecomp.el	23 May 2006 09:56:18 -0000
***************
*** 453,459 ****
  
  (defvar byte-compile-unresolved-functions nil
    "Alist of undefined functions to which calls have been compiled.
! Used for warnings when the function is not known to be defined or is later
  defined with incorrect args.")
  
  (defvar byte-compile-noruntime-functions nil
--- 453,460 ----
  
  (defvar byte-compile-unresolved-functions nil
    "Alist of undefined functions to which calls have been compiled.
! This variable is only significant whilst compiling an entire buffer.
! Used for warnings when a function is not known to be defined or is later
  defined with incorrect args.")
  
  (defvar byte-compile-noruntime-functions nil
***************
*** 1821,1826 ****
--- 1822,1832 ----
        (save-excursion
  	(set-buffer inbuffer)
  	(goto-char 1)
+ 	;; Should we always do this?  When calling multiple files, it
+ 	;; would be useful to delay this warning until all have been
+ 	;; compiled.  A: Yes!  b-c-u-f might contain dross from a
+ 	;; previous byte-compile.
+ 	(setq byte-compile-unresolved-functions nil)
  
  	;; Compile the forms from the input buffer.
  	(while (progn
***************
*** 1837,1847 ****
  	;; Make warnings about unresolved functions
  	;; give the end of the file as their position.
  	(setq byte-compile-last-position (point-max))
! 	(byte-compile-warn-about-unresolved-functions)
! 	;; Should we always do this?  When calling multiple files, it
! 	;; would be useful to delay this warning until all have
! 	;; been compiled.
! 	(setq byte-compile-unresolved-functions nil))
        ;; Fix up the header at the front of the output
        ;; if the buffer contains multibyte characters.
        (and filename (byte-compile-fix-header filename inbuffer outbuffer))))
--- 1843,1849 ----
  	;; Make warnings about unresolved functions
  	;; give the end of the file as their position.
  	(setq byte-compile-last-position (point-max))
! 	(byte-compile-warn-about-unresolved-functions))
        ;; Fix up the header at the front of the output
        ;; if the buffer contains multibyte characters.
        (and filename (byte-compile-fix-header filename inbuffer outbuffer))))



-- 
Alan.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-05-24  2:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-23 10:15 BUG + FIX. Spurious "might not be defined at runtime" from byte-compile-file Alan Mackenzie
2006-05-24  2:18 ` Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).