1 ;;;; This file contains structures and functions for the maintenance of
2 ;;;; basic information about defined types. Different object systems
3 ;;;; can be supported simultaneously.
5 ;;;; This software is part of the SBCL system. See the README file for
8 ;;;; This software is derived from the CMU CL system, which was
9 ;;;; written at Carnegie Mellon University and released into the
10 ;;;; public domain. The software is in the public domain and is
11 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
12 ;;;; files for more information.
14 (in-package "SB!KERNEL")
16 (!begin-collecting-cold-init-forms
)
18 ;;;; the CLASSOID structure
20 ;;; The CLASSOID structure is a supertype of all classoid types.
21 ;;; Its definition occurs in 'early-classoid.lisp'
23 (defmethod make-load-form ((self classoid
) &optional env
)
24 (declare (ignore env
))
25 (let ((name (classoid-name self
)))
26 (if (and name
(eq (find-classoid name nil
) self
))
27 `(find-classoid ',name
)
28 (error "can't use anonymous or undefined class as constant:~% ~S"
32 ;;;; basic LAYOUT stuff
34 ;;; a list of conses, initialized by genesis
36 ;;; In each cons, the car is the symbol naming the layout, and the
37 ;;; cdr is the layout itself.
38 (defvar *!initial-layouts
*)
40 ;;; a table mapping class names to layouts for classes we have
41 ;;; referenced but not yet loaded. This is initialized from an alist
42 ;;; created by genesis describing the layouts that genesis created at
44 (defvar *forward-referenced-layouts
*)
46 ;; Protected by *WORLD-LOCK*
47 (setq *forward-referenced-layouts
* (make-hash-table :test
'equal
))
49 (/show0
"processing *!INITIAL-LAYOUTS*")
50 (dolist (x *!initial-layouts
*)
51 (setf (layout-clos-hash (cdr x
)) (random-layout-clos-hash))
52 (setf (gethash (car x
) *forward-referenced-layouts
*)
54 (/show0
"done processing *!INITIAL-LAYOUTS*")))
56 ;;; The LAYOUT structure itself is defined in 'early-classoid.lisp'
58 (declaim (inline layout-for-std-class-p
))
59 (defun layout-for-std-class-p (x) (not (zerop (layout-%for-std-class-b x
))))
61 (defmethod print-object ((layout layout
) stream
)
62 (print-unreadable-object (layout stream
:type t
:identity t
)
64 "for ~S~@[, INVALID=~S~]"
65 (layout-proper-name layout
)
66 (layout-invalid layout
))))
68 (eval-when (#-sb-xc
:compile-toplevel
:load-toplevel
:execute
)
69 (defun layout-proper-name (layout)
70 (classoid-proper-name (layout-classoid layout
))))
72 ;;;; support for the hash values used by CLOS when working with LAYOUTs
74 ;;; a generator for random values suitable for the CLOS-HASH slots of
75 ;;; LAYOUTs. We use our own RANDOM-STATE here because we'd like
76 ;;; pseudo-random values to come the same way in the target even when
77 ;;; we make minor changes to the system, in order to reduce the
78 ;;; mysteriousness of possible CLOS bugs.
79 (defvar *layout-clos-hash-random-state
*)
80 (defun random-layout-clos-hash ()
81 ;; FIXME: I'm not sure why this expression is (1+ (RANDOM FOO)),
82 ;; returning a strictly positive value. I copied it verbatim from
83 ;; CMU CL INITIALIZE-LAYOUT-HASH, so presumably it works, but I
84 ;; dunno whether the hash values are really supposed to be 1-based.
85 ;; They're declared as INDEX.. Or is this a hack to try to avoid
86 ;; having to use bignum arithmetic? Or what? An explanation would be
89 ;; an explanation is provided in Kiczales and Rodriguez, "Efficient
90 ;; Method Dispatch in PCL", 1990. -- CSR, 2005-11-30
91 (1+ (random (1- layout-clos-hash-limit
)
92 (if (boundp '*layout-clos-hash-random-state
*)
93 *layout-clos-hash-random-state
*
94 (setf *layout-clos-hash-random-state
*
95 (make-random-state))))))
97 ;;; If we can't find any existing layout, then we create a new one
98 ;;; storing it in *FORWARD-REFERENCED-LAYOUTS*. In classic CMU CL, we
99 ;;; used to immediately check for compatibility, but for
100 ;;; cross-compilability reasons (i.e. convenience of using this
101 ;;; function in a MAKE-LOAD-FORM expression) that functionality has
102 ;;; been split off into INIT-OR-CHECK-LAYOUT.
103 (declaim (ftype (sfunction (symbol) layout
) find-layout
))
104 ;; The comment "This seems ..." is misleading but I don't have a better one.
105 ;; FIND-LAYOUT is used by FIND-AND-INIT-OR-CHECK-LAYOUT which is used
106 ;; by FOP-LAYOUT, so clearly it's used when reading fasl files.
107 (defun find-layout (name)
108 ;; This seems to be currently used only from the compiler, but make
109 ;; it thread-safe all the same. We need to lock *F-R-L* before doing
110 ;; FIND-CLASSOID in case (SETF FIND-CLASSOID) happens in parallel.
111 (let ((table *forward-referenced-layouts
*))
113 (let ((classoid (find-classoid name nil
)))
114 (or (and classoid
(classoid-layout classoid
))
116 (setf (gethash name table
)
117 (make-layout :classoid
(or classoid
(make-undefined-classoid name
)))))))))
119 ;;; If LAYOUT is uninitialized, initialize it with CLASSOID, LENGTH,
120 ;;; INHERITS, DEPTHOID, and BITMAP.
121 ;;; Otherwise require that it be consistent with the existing values.
123 ;;; UNDEFINED-CLASS values are interpreted specially as "we don't know
124 ;;; anything about the class", so if LAYOUT is initialized, any
125 ;;; preexisting class slot value is OK, and if it's not initialized,
126 ;;; its class slot value is set to an UNDEFINED-CLASS. -- FIXME: This
127 ;;; is no longer true, :UNINITIALIZED used instead.
128 (declaim (ftype (function (layout classoid index simple-vector layout-depthoid layout-bitmap
)
130 %init-or-check-layout
))
131 (defun %init-or-check-layout
(layout classoid length inherits depthoid bitmap
)
132 (cond ((eq (layout-invalid layout
) :uninitialized
)
133 ;; There was no layout before, we just created one which
134 ;; we'll now initialize with our information.
135 (setf (layout-length layout
) length
136 (layout-inherits layout
) inherits
137 (layout-depthoid layout
) depthoid
138 (layout-bitmap layout
) bitmap
139 (layout-classoid layout
) classoid
140 (layout-invalid layout
) nil
))
141 ;; FIXME: Now that LAYOUTs are born :UNINITIALIZED, maybe this
142 ;; clause is not needed?
143 ((not *type-system-initialized
*)
144 (setf (layout-classoid layout
) classoid
))
146 ;; There was an old layout already initialized with old
147 ;; information, and we'll now check that old information
148 ;; which was known with certainty is consistent with current
149 ;; information which is known with certainty.
150 (check-layout layout classoid length inherits depthoid bitmap
)))
153 ;;; In code for the target Lisp, we don't dump LAYOUTs using the
154 ;;; standard load form mechanism, we use special fops instead, in
155 ;;; order to make cold load come out right. But when we're building
156 ;;; the cross-compiler, we can't do that because we don't have access
157 ;;; to special non-ANSI low-level things like special fops, and we
158 ;;; don't need to do that anyway because our code isn't going to be
159 ;;; cold loaded, so we use the ordinary load form system.
161 (defmethod make-load-form ((layout layout
) &optional env
)
162 (declare (ignore env
))
163 (when (layout-invalid layout
)
164 (sb!c
::compiler-error
"can't dump reference to obsolete class: ~S"
165 (layout-classoid layout
)))
166 (let ((name (classoid-name (layout-classoid layout
))))
168 (sb!c
::compiler-error
"can't dump anonymous LAYOUT: ~S" layout
))
169 ;; Since LAYOUT refers to a class which refers back to the LAYOUT,
170 ;; we have to do this in two stages, like the TREE-WITH-PARENT
171 ;; example in the MAKE-LOAD-FORM entry in the ANSI spec.
173 ;; "creation" form (which actually doesn't create a new LAYOUT if
174 ;; there's a preexisting one with this name)
175 `(find-layout ',name
)
176 ;; "initialization" form (which actually doesn't initialize
177 ;; preexisting LAYOUTs, just checks that they're consistent).
178 `(%init-or-check-layout
',layout
179 ',(layout-classoid layout
)
180 ',(layout-length layout
)
181 ',(layout-inherits layout
)
182 ',(layout-depthoid layout
)
183 ',(layout-bitmap layout
)))))
184 (!set-load-form-method layout
(:xc
:target
) :ignore-it
)
186 ;;; If LAYOUT's slot values differ from the specified slot values in
187 ;;; any interesting way, then give a warning and return T.
188 (declaim (ftype (function (simple-string
195 redefine-layout-warning
))
196 (defun redefine-layout-warning (old-context old-layout
197 context length inherits depthoid bitmap
)
198 (declare (type layout old-layout
) (type simple-string old-context context
))
199 (let ((name (layout-proper-name old-layout
))
200 (old-inherits (layout-inherits old-layout
)))
201 (or (when (mismatch old-inherits inherits
:key
#'layout-proper-name
)
202 (warn "change in superclasses of class ~S:~% ~
203 ~A superclasses: ~S~% ~
207 (map 'list
#'layout-proper-name old-inherits
)
209 (map 'list
#'layout-proper-name inherits
))
211 (let ((diff (mismatch old-inherits inherits
)))
213 (warn "in class ~S:~% ~
214 ~@(~A~) definition of superclass ~S is incompatible with~% ~
218 (layout-proper-name (svref old-inherits diff
))
221 (let ((old-length (layout-length old-layout
)))
222 (unless (= old-length length
)
223 (warn "change in instance length of class ~S:~% ~
227 old-context old-length
230 (let ((old-bitmap (layout-bitmap old-layout
)))
231 (unless (= old-bitmap bitmap
)
232 (warn "change in placement of raw slots of class ~S ~
233 between the ~A definition and the ~A definition"
234 name old-context context
)
236 (unless (= (layout-depthoid old-layout
) depthoid
)
237 (warn "change in the inheritance structure of class ~S~% ~
238 between the ~A definition and the ~A definition"
239 name old-context context
)
242 ;;; Require that LAYOUT data be consistent with CLASSOID, LENGTH,
243 ;;; INHERITS, DEPTHOID, and BITMAP.
244 (declaim (ftype (function (layout classoid index simple-vector layout-depthoid layout-bitmap
))
246 (defun check-layout (layout classoid length inherits depthoid bitmap
)
247 (aver (eq (layout-classoid layout
) classoid
))
248 (when (redefine-layout-warning "current" layout
249 "compile time" length inherits depthoid bitmap
)
250 ;; Classic CMU CL had more options here. There are several reasons
251 ;; why they might want more options which are less appropriate for
252 ;; us: (1) It's hard to fit the classic CMU CL flexible approach
253 ;; into the ANSI-style MAKE-LOAD-FORM system, and having a
254 ;; non-MAKE-LOAD-FORM-style system is painful when we're trying to
255 ;; make the cross-compiler run under vanilla ANSI Common Lisp. (2)
256 ;; We have CLOS now, and if you want to be able to flexibly
257 ;; redefine classes without restarting the system, it'd make sense
258 ;; to use that, so supporting complexity in order to allow
259 ;; modifying DEFSTRUCTs without restarting the system is a low
260 ;; priority. (3) We now have the ability to rebuild the SBCL
261 ;; system from scratch, so we no longer need this functionality in
262 ;; order to maintain the SBCL system by modifying running images.
263 (error "The loaded code expects an incompatible layout for class ~S."
264 (layout-proper-name layout
)))
267 ;;; a common idiom (the same as CMU CL FIND-LAYOUT) rolled up into a
268 ;;; single function call
270 ;;; Used by the loader to forward-reference layouts for classes whose
271 ;;; definitions may not have been loaded yet. This allows type tests
272 ;;; to be loaded when the type definition hasn't been loaded yet.
273 (declaim (ftype (function (symbol index simple-vector layout-depthoid layout-bitmap
)
275 find-and-init-or-check-layout
))
276 (defun find-and-init-or-check-layout (name length inherits depthoid bitmap
)
277 (truly-the ; avoid an "assertion too complex to check" optimizer note
278 (values layout
&optional
)
280 (let ((layout (find-layout name
)))
281 (%init-or-check-layout layout
282 (or (find-classoid name nil
)
283 (layout-classoid layout
))
289 ;;; Record LAYOUT as the layout for its class, adding it as a subtype
290 ;;; of all superclasses. This is the operation that "installs" a
291 ;;; layout for a class in the type system, clobbering any old layout.
292 ;;; However, this does not modify the class namespace; that is a
293 ;;; separate operation (think anonymous classes.)
294 ;;; -- If INVALIDATE, then all the layouts for any old definition
295 ;;; and subclasses are invalidated, and the SUBCLASSES slot is cleared.
296 ;;; -- If DESTRUCT-LAYOUT, then this is some old layout, and is to be
297 ;;; destructively modified to hold the same type information.
298 (eval-when (#-sb-xc
:compile-toplevel
:load-toplevel
:execute
)
299 (defun register-layout (layout &key
(invalidate t
) destruct-layout
)
300 (declare (type layout layout
) (type (or layout null
) destruct-layout
))
302 (let* ((classoid (layout-classoid layout
))
303 (classoid-layout (classoid-layout classoid
))
304 (subclasses (classoid-subclasses classoid
)))
306 ;; Attempting to register ourselves with a temporary undefined
307 ;; class placeholder is almost certainly a programmer error. (I
308 ;; should know, I did it.) -- WHN 19990927
309 (aver (not (undefined-classoid-p classoid
)))
311 ;; This assertion dates from classic CMU CL. The rationale is
312 ;; probably that calling REGISTER-LAYOUT more than once for the
313 ;; same LAYOUT is almost certainly a programmer error.
314 (aver (not (eq classoid-layout layout
)))
316 ;; Figure out what classes are affected by the change, and issue
317 ;; appropriate warnings and invalidations.
318 (when classoid-layout
319 (%modify-classoid classoid
)
321 (dohash ((subclass subclass-layout
) subclasses
:locked t
)
322 (%modify-classoid subclass
)
324 (%invalidate-layout subclass-layout
))))
326 (%invalidate-layout classoid-layout
)
327 (setf (classoid-subclasses classoid
) nil
)))
330 (setf (layout-invalid destruct-layout
) nil
331 (layout-inherits destruct-layout
) (layout-inherits layout
)
332 (layout-depthoid destruct-layout
) (layout-depthoid layout
)
333 (layout-length destruct-layout
) (layout-length layout
)
334 (layout-bitmap destruct-layout
) (layout-bitmap layout
)
335 (layout-info destruct-layout
) (layout-info layout
)
336 (classoid-layout classoid
) destruct-layout
)
337 (setf (layout-invalid layout
) nil
338 (classoid-layout classoid
) layout
))
340 (dovector (super-layout (layout-inherits layout
))
341 (let* ((super (layout-classoid super-layout
))
342 (subclasses (or (classoid-subclasses super
)
343 (setf (classoid-subclasses super
)
344 (make-hash-table :test
'eq
345 #-sb-xc-host
#-sb-xc-host
347 (when (and (eq (classoid-state super
) :sealed
)
348 (not (gethash classoid subclasses
)))
349 (warn "unsealing sealed class ~S in order to subclass it"
350 (classoid-name super
))
351 (setf (classoid-state super
) :read-only
))
352 (setf (gethash classoid subclasses
)
353 (or destruct-layout layout
))))))
358 ;;; Arrange the inherited layouts to appear at their expected depth,
359 ;;; ensuring that hierarchical type tests succeed. Layouts with
360 ;;; DEPTHOID >= 0 (i.e. hierarchical classes) are placed first,
361 ;;; at exactly that index in the INHERITS vector. Then, non-hierarchical
362 ;;; layouts are placed in remaining elements. Then, any still-empty
363 ;;; elements are filled with their successors, ensuring that each
364 ;;; element contains a valid layout.
366 ;;; This reordering may destroy CPL ordering, so the inherits should
367 ;;; not be read as being in CPL order.
368 (defun order-layout-inherits (layouts)
369 (declare (simple-vector layouts
))
370 (let ((length (length layouts
))
373 (let ((depth (layout-depthoid (svref layouts i
))))
374 (when (> depth max-depth
)
375 (setf max-depth depth
))))
376 (let* ((new-length (max (1+ max-depth
) length
))
377 ;; KLUDGE: 0 here is the "uninitialized" element. We need
378 ;; to specify it explicitly for portability purposes, as
379 ;; elements can be read before being set [ see below, "(EQL
380 ;; OLD-LAYOUT 0)" ]. -- CSR, 2002-04-20
381 (inherits (make-array new-length
:initial-element
0)))
383 (let* ((layout (svref layouts i
))
384 (depth (layout-depthoid layout
)))
385 (unless (eql depth -
1)
386 (let ((old-layout (svref inherits depth
)))
387 (unless (or (eql old-layout
0) (eq old-layout layout
))
388 (error "layout depth conflict: ~S~%" layouts
)))
389 (setf (svref inherits depth
) layout
))))
393 (declare (type index i j
))
394 (let* ((layout (svref layouts i
))
395 (depth (layout-depthoid layout
)))
397 (loop (when (eql (svref inherits j
) 0)
400 (setf (svref inherits j
) layout
))))
401 (do ((i (1- new-length
) (1- i
)))
403 (declare (type fixnum i
))
404 (when (eql (svref inherits i
) 0)
405 (setf (svref inherits i
) (svref inherits
(1+ i
)))))
408 ;;;; class precedence lists
410 ;;; Topologically sort the list of objects to meet a set of ordering
411 ;;; constraints given by pairs (A . B) constraining A to precede B.
412 ;;; When there are multiple objects to choose, the tie-breaker
413 ;;; function is called with both the list of object to choose from and
414 ;;; the reverse ordering built so far.
415 (defun topological-sort (objects constraints tie-breaker
)
416 (declare (list objects constraints
)
417 (function tie-breaker
))
418 (let ((obj-info (make-hash-table :size
(length objects
)))
421 (dolist (constraint constraints
)
422 (let ((obj1 (car constraint
))
423 (obj2 (cdr constraint
)))
424 (let ((info2 (gethash obj2 obj-info
)))
427 (setf (gethash obj2 obj-info
) (list 1))))
428 (let ((info1 (gethash obj1 obj-info
)))
430 (push obj2
(rest info1
))
431 (setf (gethash obj1 obj-info
) (list 0 obj2
))))))
432 (dolist (obj objects
)
433 (let ((info (gethash obj obj-info
)))
434 (when (or (not info
) (zerop (first info
)))
435 (push obj free-objs
))))
437 (flet ((next-result (obj)
439 (dolist (successor (rest (gethash obj obj-info
)))
440 (let* ((successor-info (gethash successor obj-info
))
441 (count (1- (first successor-info
))))
442 (setf (first successor-info
) count
)
444 (push successor free-objs
))))))
445 (cond ((endp free-objs
)
446 (dohash ((obj info
) obj-info
)
447 (unless (zerop (first info
))
448 (error "Topological sort failed due to constraint on ~S."
450 (return (nreverse result
)))
451 ((endp (rest free-objs
))
452 (next-result (pop free-objs
)))
454 (let ((obj (funcall tie-breaker free-objs result
)))
455 (setf free-objs
(remove obj free-objs
))
456 (next-result obj
))))))))
459 ;;; standard class precedence list computation
460 (defun std-compute-class-precedence-list (class)
463 (labels ((note-class (class)
464 (unless (member class classes
)
466 (let ((superclasses (classoid-direct-superclasses class
)))
468 (rest superclasses
(rest rest
)))
470 (let ((next (first rest
)))
471 (push (cons prev next
) constraints
)
473 (dolist (class superclasses
)
474 (note-class class
)))))
475 (std-cpl-tie-breaker (free-classes rev-cpl
)
476 (dolist (class rev-cpl
(first free-classes
))
477 (let* ((superclasses (classoid-direct-superclasses class
))
478 (intersection (intersection free-classes
481 (return (first intersection
)))))))
483 (topological-sort classes constraints
#'std-cpl-tie-breaker
))))
485 ;;;; object types to represent classes
487 ;;; BUILT-IN-CLASS is used to represent the standard classes that
488 ;;; aren't defined with DEFSTRUCT and other specially implemented
489 ;;; primitive types whose only attribute is their name.
490 ;;; It is defined in 'early-classoid.lisp'
492 ;;; STRUCTURE-CLASS represents what we need to know about structure
493 ;;; classes. Non-structure "typed" defstructs are a special case, and
494 ;;; don't have a corresponding class.
495 (def!struct
(structure-classoid (:include classoid
)
496 (:constructor %make-structure-classoid
)))
497 (defun make-structure-classoid (&key name
)
498 (mark-ctype-interned (%make-structure-classoid
:name name
)))
500 ;;;; classoid namespace
502 (eval-when (#-sb-xc
:compile-toplevel
:load-toplevel
:execute
)
503 (defun (setf find-classoid
) (new-value name
)
504 #-sb-xc
(declare (type (or null classoid
) new-value
))
506 (let ((table *forward-referenced-layouts
*))
508 (let ((cell (find-classoid-cell name
:create t
)))
509 (ecase (info :type
:kind name
)
511 (:forthcoming-defclass-type
512 ;; FIXME: Currently, nothing needs to be done in this case.
513 ;; Later, when PCL is integrated tighter into SBCL, this
514 ;; might need more work.
518 (let ((old-value (classoid-cell-classoid cell
)))
520 ;; KLUDGE: The reason these clauses aren't directly
521 ;; parallel is that we need to use the internal
522 ;; CLASSOID structure ourselves, because we don't
523 ;; have CLASSes to work with until PCL is built. In
524 ;; the host, CLASSes have an approximately
525 ;; one-to-one correspondence with the target
526 ;; CLASSOIDs (as well as with the target CLASSes,
527 ;; modulo potential differences with respect to
530 (let ((old (class-of old-value
))
531 (new (class-of new-value
)))
533 (bug "Trying to change the metaclass of ~S from ~S to ~S in the ~
535 name
(class-name old
) (class-name new
))))
537 (let ((old (classoid-of old-value
))
538 (new (classoid-of new-value
)))
540 (warn "Changing meta-class of ~S from ~S to ~S."
541 name
(classoid-name old
) (classoid-name new
))))))
543 (error "Cannot redefine standard type ~
544 ~/sb!impl:print-type-specifier/." name
))
546 (warn "redefining DEFTYPE type to be a class: ~
547 ~/sb!impl::print-symbol-with-prefix/" name
)
548 (clear-info :type
:expander name
)
549 (clear-info :type
:source-location name
)))
552 (%note-type-defined name
)
553 ;; FIXME: I'm unconvinced of the need to handle either of these.
554 ;; Package locks preclude the latter, and in the former case,
555 ;; once you've made some random thing into a :PRIMITIVE kind of type,
556 ;; you've painted yourself into a corner - those types
557 ;; elicit vociferous complaints if you try to redefine them.
559 ;; we need to handle things like
560 ;; (setf (find-class 'foo) (find-class 'integer))
562 ;; (setf (find-class 'integer) (find-class 'integer))
563 (cond ((built-in-classoid-p new-value
)
564 ;; But I can't figure out how to get assertions to pass
565 ;; without violation what would otherwise be invariants
566 ;; of the internal representation of types. This sucks.
567 (setf (info :type
:kind name
)
568 (or (info :type
:kind name
) :defined
)))
570 (setf (info :type
:kind name
) :instance
)))
571 (setf (classoid-cell-classoid cell
) new-value
)
572 (unless (eq (info :type
:compiler-layout name
)
573 (classoid-layout new-value
))
574 (setf (info :type
:compiler-layout name
)
575 (classoid-layout new-value
))))))
578 (defun %clear-classoid
(name cell
)
579 (ecase (info :type
:kind name
)
583 (error "Attempt to remove :PRIMITIVE type: ~
584 ~/sb!impl:print-type-specifier/" name
))
585 ((:forthcoming-defclass-type
:instance
)
587 ;; Note: We cannot remove the classoid cell from the table,
588 ;; since compiled code may refer directly to the cell, and
589 ;; getting a different cell for a classoid with the same name
590 ;; just would not do.
592 ;; Remove the proper name of the classoid, if this was it.
593 (let* ((classoid (classoid-cell-classoid cell
))
594 (proper-name (classoid-name classoid
)))
595 (when (eq proper-name name
)
596 (setf (classoid-name classoid
) nil
)))
599 (setf (classoid-cell-classoid cell
) nil
600 (classoid-cell-pcl-class cell
) nil
))
601 (clear-info :type
:kind name
)
602 (clear-info :type
:documentation name
)
603 (clear-info :type
:compiler-layout name
)))))
605 ;;; Called when we are about to define NAME as a class meeting some
606 ;;; predicate (such as a meta-class type test.) The first result is
607 ;;; always of the desired class. The second result is any existing
608 ;;; LAYOUT for this name.
610 ;;; Again, this should be compiler-only, but easier to make this
612 (defun insured-find-classoid (name predicate constructor
)
613 (declare (type function predicate constructor
))
614 (let ((table *forward-referenced-layouts
*))
615 (with-locked-system-table (table)
616 (let* ((old (find-classoid name nil
))
617 (res (if (and old
(funcall predicate old
))
619 (funcall constructor
:name name
)))
620 (found (or (gethash name table
)
621 (when old
(classoid-layout old
)))))
623 (setf (layout-classoid found
) res
))
624 (values res found
)))))
626 ;;; If the classoid has a proper name, return the name, otherwise return
628 (defun classoid-proper-name (classoid)
629 #-sb-xc
(declare (type classoid classoid
))
630 (let ((name (classoid-name classoid
)))
631 (if (and name
(eq (find-classoid name nil
) classoid
))
635 ;;;; CLASS type operations
637 ;; CLASSOID-ENUMERABLE-P is referenced during compile by !DEFINE-TYPE-CLASS.
638 ;; But don't redefine it when building the target since we've already
639 ;; got a perfectly good definition loaded for the host.
640 (eval-when (#-sb-xc
:compile-toplevel
:load-toplevel
:execute
)
641 ;; Actually this definition makes very little sense because
642 ;; (TYPE-ENUMERABLE (FIND-CLASSOID 'CHARACTER)) => T
643 ;; but (TYPE-ENUMERABLE (SPECIFIER-TYPE 'CHARACTER)) => NIL.
644 ;; You should never see the CLASSOID used as a type though,
645 ;; at least not from parsing and set operations.
646 ;; On a related note, (TYPE-ENUMERABLE (FIND-CLASSOID 'NULL))
647 ;; should probably be T, but you'll never see that type either.
648 ;; Perhaps a better definition of this function would be
649 ;; (if (classoid-translation x) (bug "enumerable-p classoid?") nil)
650 (defun classoid-enumerable-p (x) (eq (classoid-name x
) 'character
)))
651 (!define-type-class classoid
:enumerable
#'classoid-enumerable-p
652 :might-contain-other-types nil
)
654 (defun classoid-inherits-from (sub super-or-name
)
655 (declare (type classoid sub
)
656 (type (or symbol classoid
) super-or-name
))
657 (let ((super (if (symbolp super-or-name
)
658 (find-classoid super-or-name
)
660 (find (classoid-layout super
)
661 (layout-inherits (classoid-layout sub
)))))
663 ;;; We might be passed classoids with invalid layouts; in any pairwise
664 ;;; class comparison, we must ensure that both are valid before
666 (defun %ensure-classoid-valid
(classoid layout error-context
)
667 (declare (ignorable error-context
)) ; not used on host
668 (aver (eq classoid
(layout-classoid layout
)))
669 (or (not (layout-invalid layout
))
670 ;; Avoid accidentally reaching code that can't work.
671 #+sb-xc-host
(bug "(TYPEP x 'STANDARD-CLASSOID) can't be tested")
673 (if (typep classoid
'standard-classoid
)
674 (let ((class (classoid-pcl-class classoid
)))
676 ((sb!pcl
:class-finalized-p class
)
677 (sb!pcl
::%force-cache-flushes class
)
679 ((sb!pcl
::class-has-a-forward-referenced-superclass-p class
)
681 (bug "~@<Invalid class ~S with forward-referenced superclass ~
684 (sb!pcl
::class-has-a-forward-referenced-superclass-p class
)
688 (sb!pcl
:finalize-inheritance class
)
690 (bug "~@<Don't know how to ensure validity of ~S (not a STANDARD-CLASSOID) ~
692 classoid
(or error-context
'subtypep
)))))
694 (defun %ensure-both-classoids-valid
(class1 class2
&optional errorp
)
695 (do ((layout1 (classoid-layout class1
) (classoid-layout class1
))
696 (layout2 (classoid-layout class2
) (classoid-layout class2
))
698 ((and (not (layout-invalid layout1
)) (not (layout-invalid layout2
)))
701 (unless (and (%ensure-classoid-valid class1 layout1 errorp
)
702 (%ensure-classoid-valid class2 layout2 errorp
))
703 (return-from %ensure-both-classoids-valid nil
))))
705 #-sb-xc-host
; No such thing as LAYOUT-OF, never mind the rest
706 (defun update-object-layout-or-invalid (object layout
)
707 ;; FIXME: explain why this isn't (LAYOUT-FOR-STD-CLASS-P LAYOUT).
708 (if (layout-for-std-class-p (layout-of object
))
709 (sb!pcl
::check-wrapper-validity object
)
710 (sb!c
::%layout-invalid-error object layout
)))
712 ;;; Simple methods for TYPE= and SUBTYPEP should never be called when
713 ;;; the two classes are equal, since there are EQ checks in those
715 (!define-type-method
(classoid :simple-
=) (type1 type2
)
716 (aver (not (eq type1 type2
)))
719 (!define-type-method
(classoid :simple-subtypep
) (class1 class2
)
720 (aver (not (eq class1 class2
)))
722 (if (%ensure-both-classoids-valid class1 class2
)
723 (let ((subclasses2 (classoid-subclasses class2
)))
724 (if (and subclasses2
(gethash class1 subclasses2
))
726 (if (and (typep class1
'standard-classoid
)
727 (typep class2
'standard-classoid
)
728 (or (sb!pcl
::class-has-a-forward-referenced-superclass-p
729 (classoid-pcl-class class1
))
730 (sb!pcl
::class-has-a-forward-referenced-superclass-p
731 (classoid-pcl-class class2
))))
732 ;; If there's a forward-referenced class involved we don't know for sure.
733 ;; (There are cases which we /could/ figure out, but that doesn't seem
734 ;; to be required or important, really.)
739 ;;; When finding the intersection of a sealed class and some other
740 ;;; class (not hierarchically related) the intersection is the union
741 ;;; of the currently shared subclasses.
742 (defun sealed-class-intersection2 (sealed other
)
743 (declare (type classoid sealed other
))
744 (let ((s-sub (classoid-subclasses sealed
))
745 (o-sub (classoid-subclasses other
)))
746 (if (and s-sub o-sub
)
747 (collect ((res *empty-type
* type-union
))
748 (dohash ((subclass layout
) s-sub
:locked t
)
749 (declare (ignore layout
))
750 (when (gethash subclass o-sub
)
751 (res (specifier-type subclass
))))
755 (!define-type-method
(classoid :simple-intersection2
) (class1 class2
)
756 (declare (type classoid class1 class2
))
758 (%ensure-both-classoids-valid class1 class2
"type intersection")
759 (cond ((eq class1 class2
)
761 ;; If one is a subclass of the other, then that is the
763 ((let ((subclasses (classoid-subclasses class2
)))
764 (and subclasses
(gethash class1 subclasses
)))
766 ((let ((subclasses (classoid-subclasses class1
)))
767 (and subclasses
(gethash class2 subclasses
)))
769 ;; Otherwise, we can't in general be sure that the
770 ;; intersection is empty, since a subclass of both might be
771 ;; defined. But we can eliminate it for some special cases.
772 ((or (structure-classoid-p class1
)
773 (structure-classoid-p class2
))
774 ;; No subclass of both can be defined.
776 ((eq (classoid-state class1
) :sealed
)
777 ;; checking whether a subclass of both can be defined:
778 (sealed-class-intersection2 class1 class2
))
779 ((eq (classoid-state class2
) :sealed
)
780 ;; checking whether a subclass of both can be defined:
781 (sealed-class-intersection2 class2 class1
))
782 ;; If exactly one of CLASS{1,2} is a CONDITION-CLASSOID,
783 ;; there can be no intersection: sub-/superclass relations
784 ;; between CONDITION-CLASSOIDs and other CLASSOIDs are not
785 ;; possible and a CONDITION-CLASSOIDs cannot be changed into
786 ;; different CLASSOIDs.
787 ((let ((c1 (condition-classoid-p class1
))
788 (c2 (condition-classoid-p class2
)))
789 (or (and c1
(not c2
)) (and (not c1
) c2
)))
792 ;; uncertain, since a subclass of both might be defined
795 ;;; KLUDGE: we need this to deal with the special-case INSTANCE and
796 ;;; FUNCALLABLE-INSTANCE types (which used to be CLASSOIDs until CSR
797 ;;; discovered that this was incompatible with the MOP class
798 ;;; hierarchy). See NAMED :COMPLEX-SUBTYPEP-ARG2
799 (declaim (type cons
**non-instance-classoid-types
**))
800 (defglobal **non-instance-classoid-types
**
801 '(symbol system-area-pointer weak-pointer code-component
802 lra fdefn random-class
))
804 (defun classoid-non-instance-p (classoid)
805 (declare (type classoid classoid
))
806 (member classoid
**non-instance-classoid-types
**
807 :key
#'find-classoid
))
809 ;;; KLUDGE: we need this because of the need to represent
810 ;;; intersections of two classes, even when empty at a given time, as
811 ;;; uncanonicalized intersections because of the possibility of later
812 ;;; defining a subclass of both classes. The necessity for changing
813 ;;; the default return value from SUBTYPEP to NIL, T if no alternate
814 ;;; method is present comes about because, unlike the other places we
815 ;;; use INVOKE-COMPLEX-SUBTYPEP-ARG1-METHOD, in HAIRY methods and the
816 ;;; like, classes are in their own hierarchy with no possibility of
817 ;;; mixtures with other type classes.
818 (!define-type-method
(classoid :complex-subtypep-arg2
) (type1 class2
)
819 (if (and (intersection-type-p type1
)
820 (> (count-if #'classoid-p
(intersection-type-types type1
)) 1))
822 (invoke-complex-subtypep-arg1-method type1 class2 nil t
)))
824 (!define-type-method
(classoid :negate
) (type) (make-negation-type type
))
826 (!define-type-method
(classoid :unparse
) (type)
827 (classoid-proper-name type
))
829 ;;;; built-in classes
831 ;;; The BUILT-IN-CLASSES list is a data structure which configures the
832 ;;; creation of all the built-in classes. It contains all the info
833 ;;; that we need to maintain the mapping between classes, compile-time
834 ;;; types and run-time type codes. These options are defined:
836 ;;; :TRANSLATION (default none)
837 ;;; When this class is "parsed" as a type specifier, it is
838 ;;; translated into the specified internal type representation,
839 ;;; rather than being left as a class. This is used for types
840 ;;; which we want to canonicalize to some other kind of type
841 ;;; object because in general we want to be able to include more
842 ;;; information than just the class (e.g. for numeric types.)
844 ;;; :STATE (default :SEALED)
845 ;;; The value of CLASS-STATE which we want on completion,
846 ;;; indicating whether subclasses can be created at run-time.
848 ;;; :HIERARCHICAL-P (default T unless any of the inherits are non-hierarchical)
849 ;;; True if we can assign this class a unique inheritance depth.
851 ;;; :CODES (default none)
852 ;;; Run-time type codes which should be translated back to this
853 ;;; class by CLASS-OF. Unspecified for abstract classes.
855 ;;; :INHERITS (default this class and T)
856 ;;; The class-precedence list for this class, with this class and
859 ;;; :DIRECT-SUPERCLASSES (default to head of CPL)
860 ;;; List of the direct superclasses of this class.
862 ;;; NB: not to be confused with SB-PCL::*BUILT-IN-CLASSES*
863 (!defvar
*!built-in-classes
*
864 ;; To me these data would look nicer with commas instead of "#."
865 '((t :state
:read-only
:translation t
)
866 (character :codes
(#.sb
!vm
:character-widetag
)
867 :translation
(character-set)
868 :prototype-form
(code-char 42))
869 (symbol :codes
(#.sb
!vm
:symbol-header-widetag
)
870 :prototype-form
'#:mu
)
872 (system-area-pointer :codes
(#.sb
!vm
:sap-widetag
)
873 :prototype-form
(int-sap 42))
874 (weak-pointer :codes
(#.sb
!vm
:weak-pointer-widetag
)
875 :prototype-form
(make-weak-pointer (find-package "CL")))
876 (code-component :codes
(#.sb
!vm
:code-header-widetag
))
877 ;; should this be #!-(or x86 x86-64) ?
878 (lra :codes
(#.sb
!vm
:return-pc-header-widetag
))
879 (fdefn :codes
(#.sb
!vm
:fdefn-widetag
)
880 :prototype-form
(make-fdefn "42"))
881 (random-class) ; used for unknown type codes
884 :codes
(#.sb
!vm
:closure-header-widetag
885 #.sb
!vm
:simple-fun-header-widetag
)
887 :prototype-form
(function (lambda () 42)))
889 (number :translation number
)
893 :codes
(#.sb
!vm
:complex-widetag
)
894 :prototype-form
(complex 42 42))
895 (complex-single-float
896 :translation
(complex single-float
)
897 :inherits
(complex number
)
898 :codes
(#.sb
!vm
:complex-single-float-widetag
)
899 :prototype-form
(complex 42f0
42f0
))
900 (complex-double-float
901 :translation
(complex double-float
)
902 :inherits
(complex number
)
903 :codes
(#.sb
!vm
:complex-double-float-widetag
)
904 :prototype-form
(complex 42d0
42d0
))
907 :translation
(complex long-float
)
908 :inherits
(complex number
)
909 :codes
(#.sb
!vm
:complex-long-float-widetag
)
910 :prototype-form
(complex 42l0 42l0))
913 :translation simd-pack
914 :codes
(#.sb
!vm
:simd-pack-widetag
)
915 :prototype-form
(%make-simd-pack-ub64
42 42))
916 (real :translation real
:inherits
(number))
919 :inherits
(real number
))
921 :translation single-float
922 :inherits
(float real number
)
923 :codes
(#.sb
!vm
:single-float-widetag
)
924 :prototype-form
42f0
)
926 :translation double-float
927 :inherits
(float real number
)
928 :codes
(#.sb
!vm
:double-float-widetag
)
929 :prototype-form
42d0
)
932 :translation long-float
933 :inherits
(float real number
)
934 :codes
(#.sb
!vm
:long-float-widetag
)
935 :prototype-form
42l0)
937 :translation rational
938 :inherits
(real number
))
940 :translation
(and rational
(not integer
))
941 :inherits
(rational real number
)
942 :codes
(#.sb
!vm
:ratio-widetag
)
943 :prototype-form
1/42)
946 :inherits
(rational real number
))
948 :translation
(integer #.sb
!xc
:most-negative-fixnum
949 #.sb
!xc
:most-positive-fixnum
)
950 :inherits
(integer rational real number
)
951 :codes
#.
(mapcar #'symbol-value sb
!vm
::fixnum-lowtags
)
954 :translation
(and integer
(not fixnum
))
955 :inherits
(integer rational real number
)
956 :codes
(#.sb
!vm
:bignum-widetag
)
957 :prototype-form
(expt 2 #.
(* sb
!vm
:n-word-bits
(/ 3 2))))
959 (array :translation array
:codes
(#.sb
!vm
:complex-array-widetag
)
961 :prototype-form
(make-array nil
:adjustable t
))
963 :translation simple-array
:codes
(#.sb
!vm
:simple-array-widetag
)
965 :prototype-form
(make-array nil
))
967 :translation
(or cons
(member nil
) vector extended-sequence
)
971 :translation vector
:codes
(#.sb
!vm
:complex-vector-widetag
)
972 :direct-superclasses
(array sequence
)
973 :inherits
(array sequence
))
975 :translation simple-vector
:codes
(#.sb
!vm
:simple-vector-widetag
)
976 :direct-superclasses
(vector simple-array
)
977 :inherits
(vector simple-array array sequence
)
978 :prototype-form
(make-array 0))
980 :translation bit-vector
:codes
(#.sb
!vm
:complex-bit-vector-widetag
)
981 :inherits
(vector array sequence
)
982 :prototype-form
(make-array 0 :element-type
'bit
:fill-pointer t
))
984 :translation simple-bit-vector
:codes
(#.sb
!vm
:simple-bit-vector-widetag
)
985 :direct-superclasses
(bit-vector simple-array
)
986 :inherits
(bit-vector vector simple-array
988 :prototype-form
(make-array 0 :element-type
'bit
))
989 (simple-array-unsigned-byte-2
990 :translation
(simple-array (unsigned-byte 2) (*))
991 :codes
(#.sb
!vm
:simple-array-unsigned-byte-2-widetag
)
992 :direct-superclasses
(vector simple-array
)
993 :inherits
(vector simple-array array sequence
)
994 :prototype-form
(make-array 0 :element-type
'(unsigned-byte 2)))
995 (simple-array-unsigned-byte-4
996 :translation
(simple-array (unsigned-byte 4) (*))
997 :codes
(#.sb
!vm
:simple-array-unsigned-byte-4-widetag
)
998 :direct-superclasses
(vector simple-array
)
999 :inherits
(vector simple-array array sequence
)
1000 :prototype-form
(make-array 0 :element-type
'(unsigned-byte 4)))
1001 (simple-array-unsigned-byte-7
1002 :translation
(simple-array (unsigned-byte 7) (*))
1003 :codes
(#.sb
!vm
:simple-array-unsigned-byte-7-widetag
)
1004 :direct-superclasses
(vector simple-array
)
1005 :inherits
(vector simple-array array sequence
)
1006 :prototype-form
(make-array 0 :element-type
'(unsigned-byte 7)))
1007 (simple-array-unsigned-byte-8
1008 :translation
(simple-array (unsigned-byte 8) (*))
1009 :codes
(#.sb
!vm
:simple-array-unsigned-byte-8-widetag
)
1010 :direct-superclasses
(vector simple-array
)
1011 :inherits
(vector simple-array array sequence
)
1012 :prototype-form
(make-array 0 :element-type
'(unsigned-byte 8)))
1013 (simple-array-unsigned-byte-15
1014 :translation
(simple-array (unsigned-byte 15) (*))
1015 :codes
(#.sb
!vm
:simple-array-unsigned-byte-15-widetag
)
1016 :direct-superclasses
(vector simple-array
)
1017 :inherits
(vector simple-array array sequence
)
1018 :prototype-form
(make-array 0 :element-type
'(unsigned-byte 15)))
1019 (simple-array-unsigned-byte-16
1020 :translation
(simple-array (unsigned-byte 16) (*))
1021 :codes
(#.sb
!vm
:simple-array-unsigned-byte-16-widetag
)
1022 :direct-superclasses
(vector simple-array
)
1023 :inherits
(vector simple-array array sequence
)
1024 :prototype-form
(make-array 0 :element-type
'(unsigned-byte 16)))
1026 (simple-array-unsigned-fixnum
1027 :translation
(simple-array (unsigned-byte #.sb
!vm
:n-positive-fixnum-bits
) (*))
1028 :codes
(#.sb
!vm
:simple-array-unsigned-fixnum-widetag
)
1029 :direct-superclasses
(vector simple-array
)
1030 :inherits
(vector simple-array array sequence
)
1031 :prototype-form
(make-array 0
1032 :element-type
'(unsigned-byte #.sb
!vm
:n-positive-fixnum-bits
)))
1034 (simple-array-unsigned-byte-31
1035 :translation
(simple-array (unsigned-byte 31) (*))
1036 :codes
(#.sb
!vm
:simple-array-unsigned-byte-31-widetag
)
1037 :direct-superclasses
(vector simple-array
)
1038 :inherits
(vector simple-array array sequence
)
1039 :prototype-form
(make-array 0 :element-type
'(unsigned-byte 31)))
1040 (simple-array-unsigned-byte-32
1041 :translation
(simple-array (unsigned-byte 32) (*))
1042 :codes
(#.sb
!vm
:simple-array-unsigned-byte-32-widetag
)
1043 :direct-superclasses
(vector simple-array
)
1044 :inherits
(vector simple-array array sequence
)
1045 :prototype-form
(make-array 0 :element-type
'(unsigned-byte 32)))
1047 (simple-array-unsigned-byte-63
1048 :translation
(simple-array (unsigned-byte 63) (*))
1049 :codes
(#.sb
!vm
:simple-array-unsigned-byte-63-widetag
)
1050 :direct-superclasses
(vector simple-array
)
1051 :inherits
(vector simple-array array sequence
)
1052 :prototype-form
(make-array 0 :element-type
'(unsigned-byte 63)))
1054 (simple-array-unsigned-byte-64
1055 :translation
(simple-array (unsigned-byte 64) (*))
1056 :codes
(#.sb
!vm
:simple-array-unsigned-byte-64-widetag
)
1057 :direct-superclasses
(vector simple-array
)
1058 :inherits
(vector simple-array array sequence
)
1059 :prototype-form
(make-array 0 :element-type
'(unsigned-byte 64)))
1060 (simple-array-signed-byte-8
1061 :translation
(simple-array (signed-byte 8) (*))
1062 :codes
(#.sb
!vm
:simple-array-signed-byte-8-widetag
)
1063 :direct-superclasses
(vector simple-array
)
1064 :inherits
(vector simple-array array sequence
)
1065 :prototype-form
(make-array 0 :element-type
'(signed-byte 8)))
1066 (simple-array-signed-byte-16
1067 :translation
(simple-array (signed-byte 16) (*))
1068 :codes
(#.sb
!vm
:simple-array-signed-byte-16-widetag
)
1069 :direct-superclasses
(vector simple-array
)
1070 :inherits
(vector simple-array array sequence
)
1071 :prototype-form
(make-array 0 :element-type
'(signed-byte 16)))
1073 (simple-array-fixnum
1074 :translation
(simple-array (signed-byte #.sb
!vm
:n-fixnum-bits
)
1076 :codes
(#.sb
!vm
:simple-array-fixnum-widetag
)
1077 :direct-superclasses
(vector simple-array
)
1078 :inherits
(vector simple-array array sequence
)
1079 :prototype-form
(make-array 0
1081 '(signed-byte #.sb
!vm
:n-fixnum-bits
)))
1083 (simple-array-signed-byte-32
1084 :translation
(simple-array (signed-byte 32) (*))
1085 :codes
(#.sb
!vm
:simple-array-signed-byte-32-widetag
)
1086 :direct-superclasses
(vector simple-array
)
1087 :inherits
(vector simple-array array sequence
)
1088 :prototype-form
(make-array 0 :element-type
'(signed-byte 32)))
1090 (simple-array-signed-byte-64
1091 :translation
(simple-array (signed-byte 64) (*))
1092 :codes
(#.sb
!vm
:simple-array-signed-byte-64-widetag
)
1093 :direct-superclasses
(vector simple-array
)
1094 :inherits
(vector simple-array array sequence
)
1095 :prototype-form
(make-array 0 :element-type
'(signed-byte 64)))
1096 (simple-array-single-float
1097 :translation
(simple-array single-float
(*))
1098 :codes
(#.sb
!vm
:simple-array-single-float-widetag
)
1099 :direct-superclasses
(vector simple-array
)
1100 :inherits
(vector simple-array array sequence
)
1101 :prototype-form
(make-array 0 :element-type
'single-float
))
1102 (simple-array-double-float
1103 :translation
(simple-array double-float
(*))
1104 :codes
(#.sb
!vm
:simple-array-double-float-widetag
)
1105 :direct-superclasses
(vector simple-array
)
1106 :inherits
(vector simple-array array sequence
)
1107 :prototype-form
(make-array 0 :element-type
'double-float
))
1109 (simple-array-long-float
1110 :translation
(simple-array long-float
(*))
1111 :codes
(#.sb
!vm
:simple-array-long-float-widetag
)
1112 :direct-superclasses
(vector simple-array
)
1113 :inherits
(vector simple-array array sequence
)
1114 :prototype-form
(make-array 0 :element-type
'long-float
))
1115 (simple-array-complex-single-float
1116 :translation
(simple-array (complex single-float
) (*))
1117 :codes
(#.sb
!vm
:simple-array-complex-single-float-widetag
)
1118 :direct-superclasses
(vector simple-array
)
1119 :inherits
(vector simple-array array sequence
)
1120 :prototype-form
(make-array 0 :element-type
'(complex single-float
)))
1121 (simple-array-complex-double-float
1122 :translation
(simple-array (complex double-float
) (*))
1123 :codes
(#.sb
!vm
:simple-array-complex-double-float-widetag
)
1124 :direct-superclasses
(vector simple-array
)
1125 :inherits
(vector simple-array array sequence
)
1126 :prototype-form
(make-array 0 :element-type
'(complex double-float
)))
1128 (simple-array-complex-long-float
1129 :translation
(simple-array (complex long-float
) (*))
1130 :codes
(#.sb
!vm
:simple-array-complex-long-float-widetag
)
1131 :direct-superclasses
(vector simple-array
)
1132 :inherits
(vector simple-array array sequence
)
1133 :prototype-form
(make-array 0 :element-type
'(complex long-float
)))
1136 :direct-superclasses
(vector)
1137 :inherits
(vector array sequence
))
1139 :translation simple-string
1140 :direct-superclasses
(string simple-array
)
1141 :inherits
(string vector simple-array array sequence
))
1143 :translation
(vector nil
)
1144 :codes
(#.sb
!vm
:complex-vector-nil-widetag
)
1145 :direct-superclasses
(string)
1146 :inherits
(string vector array sequence
)
1147 :prototype-form
(make-array 0 :element-type
'nil
:fill-pointer t
))
1149 :translation
(simple-array nil
(*))
1150 :codes
(#.sb
!vm
:simple-array-nil-widetag
)
1151 :direct-superclasses
(vector-nil simple-string
)
1152 :inherits
(vector-nil simple-string string vector simple-array
1154 :prototype-form
(make-array 0 :element-type
'nil
))
1156 :translation base-string
1157 :codes
(#.sb
!vm
:complex-base-string-widetag
)
1158 :direct-superclasses
(string)
1159 :inherits
(string vector array sequence
)
1160 :prototype-form
(make-array 0 :element-type
'base-char
:fill-pointer t
))
1162 :translation simple-base-string
1163 :codes
(#.sb
!vm
:simple-base-string-widetag
)
1164 :direct-superclasses
(base-string simple-string
)
1165 :inherits
(base-string simple-string string vector simple-array
1167 :prototype-form
(make-array 0 :element-type
'base-char
))
1170 :translation
(vector character
)
1171 :codes
(#.sb
!vm
:complex-character-string-widetag
)
1172 :direct-superclasses
(string)
1173 :inherits
(string vector array sequence
)
1174 :prototype-form
(make-array 0 :element-type
'character
:fill-pointer t
))
1176 (simple-character-string
1177 :translation
(simple-array character
(*))
1178 :codes
(#.sb
!vm
:simple-character-string-widetag
)
1179 :direct-superclasses
(character-string simple-string
)
1180 :inherits
(character-string simple-string string vector simple-array
1182 :prototype-form
(make-array 0 :element-type
'character
))
1184 :translation
(or cons
(member nil
))
1185 :inherits
(sequence))
1187 :codes
(#.sb
!vm
:list-pointer-lowtag
)
1189 :inherits
(list sequence
)
1190 :prototype-form
(cons nil nil
))
1192 :translation
(member nil
)
1193 :inherits
(symbol list sequence
)
1194 :direct-superclasses
(symbol list
)
1195 :prototype-form
'nil
)
1206 :inherits
(stream))))
1208 ;;; See also src/code/class-init.lisp where we finish setting up the
1209 ;;; translations for built-in types.
1211 (dolist (x *!built-in-classes
*)
1212 #-sb-xc-host
(/show0
"at head of loop over *!BUILT-IN-CLASSES*")
1215 (translation nil trans-p
)
1221 (hierarchical-p t
) ; might be modified below
1222 (direct-superclasses (if inherits
1223 (list (car inherits
))
1226 (declare (ignore codes state translation prototype-form
))
1227 (let ((inherits-list (if (eq name t
)
1229 (cons t
(reverse inherits
))))
1231 (acond #+sb-xc
; genesis dumps some classoid literals
1232 ((find-classoid name nil
)
1233 ;; Unseal it so that REGISTER-LAYOUT doesn't warn
1234 (setf (classoid-state it
) nil
)
1237 (setf (classoid-cell-classoid
1238 (find-classoid-cell name
:create t
))
1239 (mark-ctype-interned
1240 (make-built-in-classoid
1242 :translation
(if trans-p
:initializing nil
)
1243 :direct-superclasses
1246 (mapcar #'find-classoid
1247 direct-superclasses
)))))))))
1248 (setf (info :type
:kind name
) :primitive
)
1250 (setf (info :type
:builtin name
) classoid
))
1251 (let* ((inherits-vector
1255 (classoid-layout (find-classoid x
))))
1256 (when (minusp (layout-depthoid super-layout
))
1257 (setf hierarchical-p nil
))
1260 (depthoid (if hierarchical-p
1261 (or depth
(length inherits-vector
))
1264 (find-and-init-or-check-layout name
1268 +layout-all-tagged
+)
1269 :invalidate nil
)))))
1270 (/show0
"done with loop over *!BUILT-IN-CLASSES*"))
1272 ;;; Define temporary PCL STANDARD-CLASSes. These will be set up
1273 ;;; correctly and the Lisp layout replaced by a PCL wrapper after PCL
1274 ;;; is loaded and the class defined.
1276 (/show0
"about to define temporary STANDARD-CLASSes")
1277 ;; You'd think with all the pedantic explanation in here it would at least
1278 ;; be right, but it isn't: layout-inherits for FUNDAMENTAL-STREAM
1279 ;; ends up as (T SLOT-OBJECT STREAM STANDARD-OBJECT)
1280 (dolist (x '(;; Why is STREAM duplicated in this list? Because, when
1281 ;; the inherits-vector of FUNDAMENTAL-STREAM is set up,
1282 ;; a vector containing the elements of the list below,
1283 ;; i.e. '(T STREAM STREAM), is created, and
1284 ;; this is what the function ORDER-LAYOUT-INHERITS
1287 ;; So, the purpose is to guarantee a valid layout for
1288 ;; the FUNDAMENTAL-STREAM class, matching what
1289 ;; ORDER-LAYOUT-INHERITS would do.
1290 ;; ORDER-LAYOUT-INHERITS would place STREAM at index 2
1291 ;; in the INHERITS(-VECTOR). Index 1 would not be
1292 ;; filled, so STREAM is duplicated there (as
1293 ;; ORDER-LAYOUTS-INHERITS would do). Maybe the
1294 ;; duplicate definition could be removed (removing a
1295 ;; STREAM element), because FUNDAMENTAL-STREAM is
1296 ;; redefined after PCL is set up, anyway. But to play
1297 ;; it safely, we define the class with a valid INHERITS
1299 (fundamental-stream (t stream stream
))))
1300 (/show0
"defining temporary STANDARD-CLASS")
1301 (let* ((name (first x
))
1302 (inherits-list (second x
))
1303 (classoid (make-standard-classoid :name name
))
1304 (classoid-cell (find-classoid-cell name
:create t
)))
1305 ;; Needed to open-code the MAP, below
1306 (declare (type list inherits-list
))
1307 (setf (classoid-cell-classoid classoid-cell
) classoid
1308 (info :type
:kind name
) :instance
)
1309 (let ((inherits (map 'simple-vector
1311 (classoid-layout (find-classoid x
)))
1313 #-sb-xc-host
(/show0
"INHERITS=..") #-sb-xc-host
(/hexstr inherits
)
1314 (register-layout (find-and-init-or-check-layout name
0 inherits
1315 -
1 +layout-all-tagged
+)
1317 (/show0
"done defining temporary STANDARD-CLASSes"))
1319 ;;; Now that we have set up the class heterarchy, seal the sealed
1320 ;;; classes. This must be done after the subclasses have been set up.
1322 (dolist (x *!built-in-classes
*)
1323 (destructuring-bind (name &key
(state :sealed
) &allow-other-keys
) x
1324 (setf (classoid-state (find-classoid name
)) state
))))
1326 ;;;; class definition/redefinition
1328 ;;; This is to be called whenever we are altering a class.
1330 (defun %modify-classoid
(classoid) (bug "MODIFY-CLASSOID ~S" classoid
))
1332 (defun %modify-classoid
(classoid)
1334 (awhen (classoid-state classoid
)
1335 ;; FIXME: This should probably be CERROR.
1336 (warn "making ~(~A~) class ~S writable" it
(classoid-name classoid
))
1337 (setf (classoid-state classoid
) nil
)))
1339 ;;; Mark LAYOUT as invalid. Setting DEPTHOID -1 helps cause unsafe
1340 ;;; structure type tests to fail. Remove class from all superclasses
1341 ;;; too (might not be registered, so might not be in subclasses of the
1342 ;;; nominal superclasses.) We set the layout-clos-hash slots to 0 to
1343 ;;; invalidate the wrappers for specialized dispatch functions, which
1344 ;;; use those slots as indexes into tables.
1345 (defun %invalidate-layout
(layout)
1346 (declare (type layout layout
))
1347 (setf (layout-invalid layout
) t
1348 (layout-depthoid layout
) -
1)
1349 (setf (layout-clos-hash layout
) 0)
1350 (let ((inherits (layout-inherits layout
))
1351 (classoid (layout-classoid layout
)))
1352 (%modify-classoid classoid
)
1353 (dovector (super inherits
)
1354 (let ((subs (classoid-subclasses (layout-classoid super
))))
1356 (remhash classoid subs
)))))
1359 ;;;; cold loading initializations
1361 ;;; FIXME: It would be good to arrange for this to be called when the
1362 ;;; cross-compiler is being built, not just when the target Lisp is
1363 ;;; being cold loaded. Perhaps this could be moved to its own file
1364 ;;; late in the build-order.lisp-expr sequence, and be put in
1365 ;;; !COLD-INIT-FORMS there?
1366 (defun !class-finalize
()
1367 (dohash ((name layout
) *forward-referenced-layouts
*)
1368 (let ((class (find-classoid name nil
)))
1370 (setf (layout-classoid layout
) (make-undefined-classoid name
)))
1371 ((eq (classoid-layout class
) layout
)
1372 (remhash name
*forward-referenced-layouts
*))
1374 (error "Something strange with forward layout for ~S:~% ~S"
1378 #-sb-xc-host
(/show0
"about to set *BUILT-IN-CLASS-CODES*")
1379 (setq **built-in-class-codes
**
1380 (let* ((initial-element (classoid-layout (find-classoid 'random-class
)))
1381 (res (make-array 256 :initial-element initial-element
)))
1382 (dolist (x *!built-in-classes
* res
)
1383 (destructuring-bind (name &key codes
&allow-other-keys
)
1385 (let ((layout (classoid-layout (find-classoid name
))))
1386 (dolist (code codes
)
1387 (setf (svref res code
) layout
)))))))
1388 #-sb-xc-host
(/show0
"done setting *BUILT-IN-CLASS-CODES*"))
1390 (!defun-from-collected-cold-init-forms
!classes-cold-init
)