Compiled COMPILE forms at load time Bug

Helmut Eller heller at common-lisp.net
Wed Mar 10 19:27:07 CET 2010


* Raymond Toy [2010-03-10 17:26+0100] writes:

> On 3/10/10 9:24 AM, Raymond Toy wrote:
>> On 2/14/10 4:15 PM, Helmut Eller wrote:
>>>
>>> We could probably fix the problem by binding form in compile in
>>> main.lisp with something like this:
>>>
>>> (form (etypecase definition
>>>        ((or cons eval:interpreted-function)
>>>         `#',(get-lambda-to-compile definition))
>>>        (function `',definition)))
>>>
>>>   
>> Oops.  I checked in this change and it's in the March snapshot.  But it
>> also breaks something that used to work:
>> 
>> (defun foo (x y) (+ x y))
>> (compile 'foo)
>> (compile 'foo)
>> 
>> This used to work.  Now the second compile generates an error about FOO
>> being undefined.

Who would have thought that writing an identity function could be so
hard :-)

>
> Perhaps the following change would work.  It makes the old behavior work
> again, and still fixes the compile form issue:
>
> 	     (form (etypecase definition
> 		     ((or cons eval:interpreted-function)
> 		      `#',(get-lambda-to-compile definition))
> 		     (function
> 		      (multiple-value-bind (exp lexenv)
> 			  (function-lambda-expression definition)
> 			(if (and exp (not lexenv))
> 			    `#',exp
> 			    `',definition)))))
>
> (Perhaps this can be written in a better way.  The second etypecase
> clause is like get-lambda-to-compile, except we don't signal an error.)

We could add this

  (when (typep definition '(and function (not eval:interpreted-function)))
    (when name (setf (fdefinition name) definition))
    (return-from compile (values definition nil nil)))

right before the with-compilation-unit form.  We can't return-from
inside the with-compilation-unit without producing some error message so
we have to put it before it.  We'd lose some restarts, but that should
only be noticeable if (setf (fdefinition ..)) hits a definition lock and
it's not required by the spec anyway.

Then form would be bound as it used to be
(form `#',(get-lambda-to-compile definition).

> I think we still need the additional fix in function-lambda-expression
> in case the compiled-debug-info-source is NIL.

I think we always have the lambda expression for interpreted functions.

Helmut




More information about the cmucl-imp mailing list