fasl-file-valid-p

From: Sam Steingold (sds_at_gnu.org)
Date: 11/29/04


Date: Mon, 29 Nov 2004 12:51:05 -0500

Build tools, like defsystem or asdf, have to determine whether a file
needs to be recompiled. Obviously, when the .fasl is older than the
.lisp, recompilation is in order.

Alas, there are other situations when this might be necessary, e.g.,
when the implementation changes the FASL format or when two
implementations use the same name for their FASL files
(are there such cases?)

Proposal:

function (FASL-FILE-VALID-P file-name) => valid-p
return T if the file is a valid FASL file for this implementation and
NIL otherwise.
E.g.,
(fasl-file-valid-p "foo.lisp") ==> NIL
(fasl-file-valid-p (compile-file "foo.lisp")) ==> T

the trivial implementation:

(defun fasl-file-valid-p (file-name)
  (not (nth-value 1 (ignore-errors (load file-name)))))

is wrong because,

1. LOAD may fail even though the file is valid:
   even when "foo.lisp" contains "(error)",
      (fasl-file-valid-p (compile-file "foo.lisp"))
   should still return T

2. this is not side-effect-free, i.e., this may define new functions and
   macros (or, worse yet, redefine some existing functions and macros or
   execute some malicious code).

Cost to implementors: something like this:
#+clisp
(defun fasl-file-valid-p (file-name)
  (with-open-file (in file-name :direction :input :if-does-not-exist nil)
    (and in
         (let ((line (read-line in nil nil)))
           (and line
                (string= line "(SYSTEM::VERSION " :start1 0
                         :end1 #.(length "(SYSTEM::VERSION "))
                (null (nth-value 1 (ignore-errors
                                     (eval (read-from-string line))))))))))))

Comments?

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
Binaries die but source code lives forever.


Relevant Pages

  • Re: fasl-file-valid-p
    ... when the .fasl is older than the ... > .lisp, recompilation is in order. ... Asdf should IMHO support a binary tree different from the source path. ... My current practice with defsystem ...
    (comp.lang.lisp)
  • Re: fasl-file-valid-p
    ... >> Build tools, like defsystem or asdf, have to determine whether a file ... when the .fasl is older than the ... >> .lisp, recompilation is in order. ... Sam Steingold running w2k ...
    (comp.lang.lisp)
  • Re: fasl-file-valid-p
    ... when the .fasl is older than the ... > .lisp, recompilation is in order. ... > when the implementation changes the FASL format or when two ... it tends to leave behind invalid .fasl files. ...
    (comp.lang.lisp)