[cmucl-help] Inlined TYPEP over-optimization bug with CHANGE-CLASS

Dan Corkill corkill at gbbopen.org
Sun Feb 5 14:57:44 UTC 2012


>> Recent CMUCL releases (including the current one), incorrectly over-optimize TYPEP and
>> miss the class change resulting from CHANGE-CLASS. 
> 
>> (defmethod show-bug ((instance foo))
>> (change-class instance 'bar)
>> (format t "~&;; Inlined TYPEP: ~s (incorrect)~%;; Not-inlined TYPEP: ~s (correct)~%"
>>         (typep instance 'foo)
>>         (locally (declare (notinline typep))
>>           (typep instance 'foo))))
> 
> Changing the class of an instance within a method specializing on that
> instance to a class where the method would no longer have been called is
> one of the things that the CLHS description of change-class calls
> "semantic difficulties".
> 
> Not speaking for CMUCL developers, I would call it a downright bad idea
> to mess with the classes of specialized instances in methods -- allowing
> the programmer to do invalidates whole classes of CLOS optimizations.
> The CLHS specifically calls out slot access, but that's just one case of
> a general problem: after you issue the change-class, the method
> currently running is no longer an applicable method to the instance, so
> all the compiler assumptions have just been invalidated, and all the
> run-time calculations of next methods also (though they're not present
> in your example).
> 
> Best,
> 
> Christophe

I fully agree (and apologies for the confusion caused by my quick-and-dirty 
example).

The issue doesn't require being within an instance method--as the following
vanilla-function example shows.

(in-package :cl-user)

(defclass foo () ())
(defclass bar () ())

(defun show-bug (instance)
  (change-class instance 'bar)
  (format t "~&;; Inlined TYPEP: ~s (incorrect)~%;; Not-inlined TYPEP: ~s (correct)~%"
          (typep instance 'foo)
          (locally (declare (notinline typep))
            (typep instance 'foo))))

(show-bug (make-instance 'foo))

-- Dan





More information about the cmucl-help mailing list