emacs-pretest-bug
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: `eval-when-compile' can cause incorrect byte-compiler warnings


From: Richard Stallman
Subject: Re: `eval-when-compile' can cause incorrect byte-compiler warnings
Date: Sun, 18 Jan 2004 14:16:07 -0500

The problem is more complex.  I don't think it is correct to
discard the byte-compile-noruntime properties after each compilation.
What makes it correct not to warn about them for file2 is the fact that
file2 contains (require 'nnkiboze) outside of eval-when-compile.
But if you recompile file1 after file2, ideally you would want to get
the warnings again.

That is not trivial to implement.  You would need to keep track of
which files required which other files, and ask "Will a chain of
requires force this function to be loaded whenever this code runs?"
It is nontrivial but it might be a real improvement.  Still I am not
sure it is worth the trouble.

It may not be worth the trouble to change this at all if it still
won't be "correct".

It occurs to me that a propert of the function name is not a very good
data structure for recording this information.  Using a list might be
better.  This change ought to do that, without changing any other behavior.


*** bytecomp.el.~2.141.~        Fri Jan 16 12:19:45 2004
--- bytecomp.el Sun Jan 18 13:07:08 2004
***************
*** 444,449 ****
--- 444,454 ----
  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
+   "Alist of functions called that may not be defined when the compiled code 
is run.
+ Used for warnings about calling a function that is defined during compilation
+ but won't necessarily be defined when the compiled file is loaded.")
+ 
  (defvar byte-compile-tag-number 0)
  (defvar byte-compile-output nil
    "Alist describing contents to put in byte code string.
***************
*** 776,782 ****
  
  (defun byte-compile-eval (form)
    "Eval FORM and mark the functions defined therein.
! Each function's symbol gets marked with the `byte-compile-noruntime' 
property."
    (let ((hist-orig load-history)
        (hist-nil-orig current-load-list))
      (prog1 (eval form)
--- 781,787 ----
  
  (defun byte-compile-eval (form)
    "Eval FORM and mark the functions defined therein.
! Each function's symbol gets added to `byte-compile-noruntime-functions'."
    (let ((hist-orig load-history)
        (hist-nil-orig current-load-list))
      (prog1 (eval form)
***************
*** 794,810 ****
                  (cond
                   ((symbolp s)
                    (unless (memq s old-autoloads)
!                     (put s 'byte-compile-noruntime t)))
                   ((and (consp s) (eq t (car s)))
                    (push (cdr s) old-autoloads))
                   ((and (consp s) (eq 'autoload (car s)))
!                   (put (cdr s) 'byte-compile-noruntime t)))))))
          ;; Go through current-load-list for the locally defined funs.
          (let (old-autoloads)
            (while (and hist-nil-new (not (eq hist-nil-new hist-nil-orig)))
              (let ((s (pop hist-nil-new)))
                (when (and (symbolp s) (not (memq s old-autoloads)))
!                 (put s 'byte-compile-noruntime t))
                (when (and (consp s) (eq t (car s)))
                  (push (cdr s) old-autoloads))))))))))
  
--- 799,815 ----
                  (cond
                   ((symbolp s)
                    (unless (memq s old-autoloads)
!                     (push s byte-compile-noruntime-functions)))
                   ((and (consp s) (eq t (car s)))
                    (push (cdr s) old-autoloads))
                   ((and (consp s) (eq 'autoload (car s)))
!                   (push (cdr s) byte-compile-noruntime-functions)))))))
          ;; Go through current-load-list for the locally defined funs.
          (let (old-autoloads)
            (while (and hist-nil-new (not (eq hist-nil-new hist-nil-orig)))
              (let ((s (pop hist-nil-new)))
                (when (and (symbolp s) (not (memq s old-autoloads)))
!                 (push s byte-compile-noruntime-functions))
                (when (and (consp s) (eq t (car s)))
                  (push (cdr s) old-autoloads))))))))))
  
***************
*** 1173,1179 ****
      ;; Check to see if the function will be available at runtime
      ;; and/or remember its arity if it's unknown.
      (or (and (or sig (fboundp (car form))) ; might be a subr or autoload.
!            (not (get (car form) 'byte-compile-noruntime)))
        (eq (car form) byte-compile-current-form) ; ## this doesn't work
                                        ; with recursion.
        ;; It's a currently-undefined function.
--- 1178,1184 ----
      ;; Check to see if the function will be available at runtime
      ;; and/or remember its arity if it's unknown.
      (or (and (or sig (fboundp (car form))) ; might be a subr or autoload.
!            (memq (car form) byte-compile-noruntime-functions))
        (eq (car form) byte-compile-current-form) ; ## this doesn't work
                                        ; with recursion.
        ;; It's a currently-undefined function.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]