X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Fclass.lisp;h=4e06f521cbf7002854dd3a0d2f56ca1802a1ce3f;hb=b1a20dc4dee1a14c9b11eabf4130187227b9b2a7;hp=eb35177cd76a2c9a5763dd6fb4f1d4712014c429;hpb=ef5bc526202b95f6a1bf92fe88d2fa778a827190;p=sbcl.git diff --git a/src/code/class.lisp b/src/code/class.lisp index eb35177..4e06f52 100644 --- a/src/code/class.lisp +++ b/src/code/class.lisp @@ -772,7 +772,18 @@ NIL is returned when no such class exists." (remhash name *forward-referenced-layouts*) (%note-type-defined name) - (setf (info :type :kind name) :instance) + ;; we need to handle things like + ;; (setf (find-class 'foo) (find-class 'integer)) + ;; and + ;; (setf (find-class 'integer) (find-class 'integer)) + (cond + ((built-in-classoid-p new-value) + (setf (info :type :kind name) (or (info :type :kind name) :defined)) + (let ((translation (built-in-classoid-translation new-value))) + (when translation + (setf (info :type :translator name) + (lambda (c) (declare (ignore c)) translation))))) + (t (setf (info :type :kind name) :instance))) (setf (classoid-cell-classoid (find-classoid-cell name)) new-value) (unless (eq (info :type :compiler-layout name) (classoid-layout new-value)) @@ -809,6 +820,38 @@ NIL is returned when no such class exists." (!define-type-class classoid) +;;; We might be passed classoids with invalid layouts; in any pairwise +;;; class comparison, we must ensure that both are valid before +;;; proceeding. +(defun ensure-classoid-valid (classoid layout) + (aver (eq classoid (layout-classoid layout))) + (when (layout-invalid layout) + (if (typep classoid 'standard-classoid) + (let ((class (classoid-pcl-class classoid))) + (cond + ((sb!pcl:class-finalized-p class) + (sb!pcl::force-cache-flushes class)) + ((sb!pcl::class-has-a-forward-referenced-superclass-p class) + (error "Invalid, unfinalizeable class ~S (classoid ~S)." + class classoid)) + (t (sb!pcl:finalize-inheritance class)))) + (error "Don't know how to ensure validity of ~S (not ~ + a STANDARD-CLASSOID)." classoid)))) + +(defun ensure-both-classoids-valid (class1 class2) + (do ((layout1 (classoid-layout class1) (classoid-layout class1)) + (layout2 (classoid-layout class2) (classoid-layout class2)) + (i 0 (+ i 1))) + ((and (not (layout-invalid layout1)) (not (layout-invalid layout2)))) + (aver (< i 2)) + (ensure-classoid-valid class1 layout1) + (ensure-classoid-valid class2 layout2))) + +(defun update-object-layout-or-invalid (object layout) + (if (typep (classoid-of object) 'standard-classoid) + (sb!pcl::check-wrapper-validity object) + (%layout-invalid-error object layout))) + ;;; Simple methods for TYPE= and SUBTYPEP should never be called when ;;; the two classes are equal, since there are EQ checks in those ;;; operations. @@ -818,6 +861,7 @@ NIL is returned when no such class exists." (!define-type-method (classoid :simple-subtypep) (class1 class2) (aver (not (eq class1 class2))) + (ensure-both-classoids-valid class1 class2) (let ((subclasses (classoid-subclasses class2))) (if (and subclasses (gethash class1 subclasses)) (values t t) @@ -841,6 +885,7 @@ NIL is returned when no such class exists." (!define-type-method (classoid :simple-intersection2) (class1 class2) (declare (type classoid class1 class2)) + (ensure-both-classoids-valid class1 class2) (cond ((eq class1 class2) class1) ;; If one is a subclass of the other, then that is the @@ -868,6 +913,22 @@ NIL is returned when no such class exists." ;; uncertain, since a subclass of both might be defined nil))) +;;; KLUDGE: we need this for the special-case SEQUENCE type, which +;;; (because of multiple inheritance with ARRAY for the VECTOR types) +;;; doesn't have the nice hierarchical properties we want. This is +;;; basically DELEGATE-COMPLEX-INTERSECTION2 with a special-case for +;;; SEQUENCE/ARRAY interactions. +(!define-type-method (classoid :complex-intersection2) (type1 class2) + (cond + ((and (eq class2 (find-classoid 'sequence)) + (array-type-p type1)) + (type-intersection2 (specifier-type 'vector) type1)) + (t + (let ((method (type-class-complex-intersection2 (type-class-info type1)))) + (if (and method (not (eq method #'delegate-complex-intersection2))) + :call-other-method + (hierarchical-intersection2 type1 class2)))))) + ;;; KLUDGE: we need this to deal with the special-case INSTANCE and ;;; FUNCALLABLE-INSTANCE types (which used to be CLASSOIDs until CSR ;;; discovered that this was incompatible with the MOP class @@ -899,12 +960,16 @@ NIL is returned when no such class exists." ;;;; PCL stuff -(def!struct (std-classoid (:include classoid) - (:constructor nil))) -(def!struct (standard-classoid (:include std-classoid) +;;; the CLASSOID that we use to represent type information for +;;; STANDARD-CLASS and FUNCALLABLE-STANDARD-CLASS. The type system +;;; side does not need to distinguish between STANDARD-CLASS and +;;; FUNCALLABLE-STANDARD-CLASS. +(def!struct (standard-classoid (:include classoid) (:constructor make-standard-classoid))) -(def!struct (random-pcl-classoid (:include std-classoid) - (:constructor make-random-pcl-classoid))) +;;; a metaclass for classes which aren't standardlike but will never +;;; change either. +(def!struct (static-classoid (:include classoid) + (:constructor make-static-classoid))) ;;;; built-in classes @@ -1047,7 +1112,8 @@ NIL is returned when no such class exists." :inherits (array) :prototype-form (make-array nil)) (sequence - :translation (or cons (member nil) vector)) + :state :read-only + :depth 2) (vector :translation vector :codes (#.sb!vm:complex-vector-widetag) :direct-superclasses (array sequence)