0.9.18.38:
[sbcl.git] / src / pcl / vector.lisp
1 ;;;; permutation vectors
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5
6 ;;;; This software is derived from software originally released by Xerox
7 ;;;; Corporation. Copyright and release statements follow. Later modifications
8 ;;;; to the software are in the public domain and are provided with
9 ;;;; absolutely no warranty. See the COPYING and CREDITS files for more
10 ;;;; information.
11
12 ;;;; copyright information from original PCL sources:
13 ;;;;
14 ;;;; Copyright (c) 1985, 1986, 1987, 1988, 1989, 1990 Xerox Corporation.
15 ;;;; All rights reserved.
16 ;;;;
17 ;;;; Use and copying of this software and preparation of derivative works based
18 ;;;; upon this software are permitted. Any distribution of this software or
19 ;;;; derivative works must comply with all applicable United States export
20 ;;;; control laws.
21 ;;;;
22 ;;;; This software is made available AS IS, and Xerox Corporation makes no
23 ;;;; warranty about the software, its performance or its conformity to any
24 ;;;; specification.
25
26 (in-package "SB-PCL")
27 \f
28 (defmacro instance-slot-index (wrapper slot-name)
29   `(let ((pos 0))
30      (declare (fixnum pos))
31      (block loop
32        (dolist (sn (wrapper-instance-slots-layout ,wrapper))
33          (when (eq ,slot-name sn) (return-from loop pos))
34          (incf pos)))))
35 \f
36 (defun pv-cache-limit-fn (nlines)
37   (default-limit-fn nlines))
38
39 (defstruct (pv-table (:predicate pv-tablep)
40                      (:constructor make-pv-table-internal
41                                    (slot-name-lists call-list))
42                      (:copier nil))
43   (cache nil :type (or cache null))
44   (pv-size 0 :type fixnum)
45   (slot-name-lists nil :type list)
46   (call-list nil :type list))
47
48 #-sb-fluid (declaim (sb-ext:freeze-type pv-table))
49
50 ;;; FIXME: The comment below seem to indicate that this was intended
51 ;;; to be actually used, however, it isn't anymore, and was commented
52 ;;; out at 0.9.13.47. Also removed was code in MAKE-PV-TABLE that
53 ;;; pushed each new PV-TABLE onto this list. --NS 2006-06-18
54 ;;;
55 ;;;   help new slot-value-using-class methods affect fast iv access
56 ;;;
57 ;;;  (defvar *all-pv-table-list* nil)
58
59 (declaim (inline make-pv-table))
60 (defun make-pv-table (&key slot-name-lists call-list)
61   (make-pv-table-internal slot-name-lists call-list))
62
63 (defun make-pv-table-type-declaration (var)
64   `(type pv-table ,var))
65
66 (defvar *slot-name-lists-inner* (make-hash-table :test 'equal))
67 (defvar *slot-name-lists-outer* (make-hash-table :test 'equal))
68
69 ;;; Entries in this are lists of (table . pv-offset-list).
70 (defvar *pv-key-to-pv-table-table* (make-hash-table :test 'equal))
71
72 (defun intern-pv-table (&key slot-name-lists call-list)
73   (let ((new-p nil))
74     (flet ((inner (x)
75              (or (gethash x *slot-name-lists-inner*)
76                  (setf (gethash x *slot-name-lists-inner*) (copy-list x))))
77            (outer (x)
78              (or (gethash x *slot-name-lists-outer*)
79                  (setf (gethash x *slot-name-lists-outer*)
80                        (let ((snl (copy-list (cdr x)))
81                              (cl (car x)))
82                          (setq new-p t)
83                          (make-pv-table :slot-name-lists snl
84                                         :call-list cl))))))
85       (let ((pv-table
86              (outer (mapcar #'inner (cons call-list slot-name-lists)))))
87         (when new-p
88           (let ((pv-index 0))
89             (dolist (slot-name-list slot-name-lists)
90               (dolist (slot-name (cdr slot-name-list))
91                 (note-pv-table-reference slot-name pv-index pv-table)
92                 (incf pv-index)))
93             (dolist (gf-call call-list)
94               (note-pv-table-reference gf-call pv-index pv-table)
95               (incf pv-index))
96             (setf (pv-table-pv-size pv-table) pv-index)))
97         pv-table))))
98
99 (defun note-pv-table-reference (ref pv-offset pv-table)
100   (let ((entry (gethash ref *pv-key-to-pv-table-table*)))
101     (when (listp entry)
102       (let ((table-entry (assq pv-table entry)))
103         (when (and (null table-entry)
104                    (> (length entry) 8))
105           (let ((new-table-table (make-hash-table :size 16 :test 'eq)))
106             (dolist (table-entry entry)
107               (setf (gethash (car table-entry) new-table-table)
108                     (cdr table-entry)))
109             (setf (gethash ref *pv-key-to-pv-table-table*) new-table-table)))
110         (when (listp entry)
111           (if (null table-entry)
112               (let ((new (cons pv-table pv-offset)))
113                 (if (consp entry)
114                     (push new (cdr entry))
115                     (setf (gethash ref *pv-key-to-pv-table-table*)
116                           (list new))))
117               (push pv-offset (cdr table-entry)))
118           (return-from note-pv-table-reference nil))))
119     (let ((list (gethash pv-table entry)))
120       (if (consp list)
121           (push pv-offset (cdr list))
122           (setf (gethash pv-table entry) (list pv-offset)))))
123   nil)
124
125 (defun map-pv-table-references-of (ref function)
126   (let ((entry (gethash ref *pv-key-to-pv-table-table*)))
127     (if (listp entry)
128         (dolist (table+pv-offset-list entry)
129           (funcall function
130                    (car table+pv-offset-list)
131                    (cdr table+pv-offset-list)))
132         (maphash function entry)))
133   ref)
134 \f
135 (defun optimize-slot-value-by-class-p (class slot-name type)
136   (or (not (eq *boot-state* 'complete))
137       (let ((slotd (find-slot-definition class slot-name)))
138         (and slotd
139              (slot-accessor-std-p slotd type)))))
140
141 (defun compute-pv-slot (slot-name wrapper class class-slots)
142   (if (symbolp slot-name)
143       (when (optimize-slot-value-by-class-p class slot-name 'all)
144         (or (instance-slot-index wrapper slot-name)
145             (assq slot-name class-slots)))
146       (when (consp slot-name)
147         (case (first slot-name)
148           ((reader writer)
149            (when (eq *boot-state* 'complete)
150              (let ((gf (gdefinition (second slot-name))))
151                (when (generic-function-p gf)
152                  (accessor-values1 gf (first slot-name) class)))))
153           (t (bug "Don't know how to deal with ~S in ~S"
154                   slot-name 'compute-pv-slots))))))
155
156 (defun compute-pv (slot-name-lists wrappers)
157   (unless (listp wrappers)
158     (setq wrappers (list wrappers)))
159   (let (elements)
160     (dolist (slot-names slot-name-lists
161              (make-permutation-vector (nreverse elements)))
162       (when slot-names
163         (let* ((wrapper (pop wrappers))
164                (std-p (typep wrapper 'wrapper))
165                (class (wrapper-class* wrapper))
166                (class-slots (and std-p (wrapper-class-slots wrapper))))
167           (dolist (slot-name (cdr slot-names))
168             (push (if std-p
169                       (compute-pv-slot slot-name wrapper class class-slots)
170                       nil)
171                   elements)))))))
172
173 (defun compute-calls (call-list wrappers)
174   (declare (ignore call-list wrappers))
175   #||
176   (map 'vector
177        (lambda (call)
178          (compute-emf-from-wrappers call wrappers))
179        call-list)
180   ||#
181   '#())
182
183 #|| ; Need to finish this, then write the maintenance functions.
184 (defun compute-emf-from-wrappers (call wrappers)
185   (when call
186     (destructuring-bind (gf-name nreq restp arg-info) call
187       (if (eq gf-name 'make-instance)
188           (error "should not get here") ; there is another mechanism for this.
189           (lambda (&rest args)
190             (if (not (eq *boot-state* 'complete))
191                 (apply (gdefinition gf-name) args)
192                 (let* ((gf (gdefinition gf-name))
193                        (arg-info (arg-info-reader gf))
194                        (classes '?)
195                        (types '?)
196                        (emf (cache-miss-values-internal gf arg-info
197                                                         wrappers classes types
198                                                         'caching)))
199                   (update-all-pv-tables call wrappers emf)
200                   (invoke-emf emf args))))))))
201 ||#
202
203 (defun make-permutation-vector (indexes)
204   (make-array (length indexes) :initial-contents indexes))
205
206 (defun pv-table-lookup (pv-table pv-wrappers)
207   (let* ((slot-name-lists (pv-table-slot-name-lists pv-table))
208          (call-list (pv-table-call-list pv-table))
209          (cache (or (pv-table-cache pv-table)
210                     (setf (pv-table-cache pv-table)
211                           (get-cache (- (length slot-name-lists)
212                                         (count nil slot-name-lists))
213                                      t
214                                      #'pv-cache-limit-fn
215                                      2)))))
216     (or (probe-cache cache pv-wrappers)
217         (let* ((pv (compute-pv slot-name-lists pv-wrappers))
218                (calls (compute-calls call-list pv-wrappers))
219                (pv-cell (cons pv calls))
220                (new-cache (fill-cache cache pv-wrappers pv-cell)))
221           (unless (eq new-cache cache)
222             (setf (pv-table-cache pv-table) new-cache))
223           pv-cell))))
224
225 (defun make-pv-type-declaration (var)
226   `(type simple-vector ,var))
227
228 (defmacro pvref (pv index)
229   `(svref ,pv ,index))
230
231 (defmacro copy-pv (pv)
232   `(copy-seq ,pv))
233
234 (defun make-calls-type-declaration (var)
235   `(type simple-vector ,var))
236
237 (defmacro callsref (calls index)
238   `(svref ,calls ,index))
239
240 (defvar *pv-table-cache-update-info* nil)
241
242 (defun update-pv-table-cache-info (class)
243   (let ((slot-names-for-pv-table-update nil)
244         (new-icui nil))
245     (dolist (icu *pv-table-cache-update-info*)
246       (if (eq (car icu) class)
247           (pushnew (cdr icu) slot-names-for-pv-table-update)
248           (push icu new-icui)))
249     (setq *pv-table-cache-update-info* new-icui)
250     (when slot-names-for-pv-table-update
251       (update-all-pv-table-caches class slot-names-for-pv-table-update))))
252
253 (defun update-all-pv-table-caches (class slot-names)
254   (let* ((cwrapper (class-wrapper class))
255          (std-p (typep cwrapper 'wrapper))
256          (class-slots (and std-p (wrapper-class-slots cwrapper)))
257          (new-values
258           (mapcar
259            (lambda (slot-name)
260              (cons slot-name
261                    (if std-p
262                        (compute-pv-slot slot-name cwrapper class class-slots)
263                        nil)))
264            slot-names))
265          (pv-tables nil))
266     (dolist (slot-name slot-names)
267       (map-pv-table-references-of
268        slot-name
269        (lambda (pv-table pv-offset-list)
270          (declare (ignore pv-offset-list))
271          (pushnew pv-table pv-tables))))
272     (dolist (pv-table pv-tables)
273       (let* ((cache (pv-table-cache pv-table))
274              (slot-name-lists (pv-table-slot-name-lists pv-table))
275              (pv-size (pv-table-pv-size pv-table))
276              (pv-map (make-array pv-size :initial-element nil)))
277         (let ((map-index 0) (param-index 0))
278           (dolist (slot-name-list slot-name-lists)
279             (dolist (slot-name (cdr slot-name-list))
280               (let ((a (assoc slot-name new-values)))
281                 (setf (svref pv-map map-index)
282                       (and a (cons param-index (cdr a)))))
283               (incf map-index))
284             (incf param-index)))
285         (when cache
286           (map-cache (lambda (wrappers pv-cell)
287                        (update-slots-in-pv wrappers (car pv-cell)
288                                            cwrapper pv-size pv-map))
289                      cache))))))
290
291 (defun update-slots-in-pv (wrappers pv cwrapper pv-size pv-map)
292   (if (atom wrappers)
293       (when (eq cwrapper wrappers)
294         (dotimes-fixnum (i pv-size)
295           (let ((map (svref pv-map i)))
296             (when map
297               (aver (= (car map) 0))
298               (setf (pvref pv i) (cdr map))))))
299       (when (memq cwrapper wrappers)
300         (let ((param 0))
301           (dolist (wrapper wrappers)
302             (when (eq wrapper cwrapper)
303               (dotimes-fixnum (i pv-size)
304                 (let ((map (svref pv-map i)))
305                   (when (and map (= (car map) param))
306                     (setf (pvref pv i) (cdr map))))))
307             (incf param))))))
308 \f
309 (defun can-optimize-access (form required-parameters env)
310   (let ((type (ecase (car form)
311                 (slot-value 'reader)
312                 (set-slot-value 'writer)
313                 (slot-boundp 'boundp)))
314         (var (cadr form))
315         (slot-name (eval (caddr form)))) ; known to be constant
316     (can-optimize-access1 var required-parameters env type slot-name)))
317
318 ;;; FIXME: This looks like an internal helper function for
319 ;;; CAN-OPTIMIZE-ACCESS, and it is used that way, but it's also called
320 ;;; bare from several places in the code. Perhaps the two functions
321 ;;; should be renamed CAN-OPTIMIZE-ACCESS-FOR-FORM and
322 ;;; CAN-OPTIMIZE-ACCESS-FOR-VAR. If so, I'd just as soon use keyword
323 ;;; args instead of optional ones, too.
324 (defun can-optimize-access1 (var required-parameters env
325                              &optional type slot-name)
326   (when (and (consp var) (eq 'the (car var)))
327     ;; FIXME: We should assert list of length 3 here. Or maybe we
328     ;; should just define EXTRACT-THE, replace the whole
329     ;;   (WHEN ..)
330     ;; form with
331     ;;   (AWHEN (EXTRACT-THE VAR)
332     ;;     (SETF VAR IT))
333     ;; and then use EXTRACT-THE similarly to clean up the other tests
334     ;; against 'THE scattered through the PCL code.
335     (setq var (caddr var)))
336   (when (symbolp var)
337     (let* ((rebound? (caddr (var-declaration '%variable-rebinding var env)))
338            (parameter-or-nil (car (memq (or rebound? var)
339                                         required-parameters))))
340       (when parameter-or-nil
341         (let* ((class-name (caddr (var-declaration '%class
342                                                    parameter-or-nil
343                                                    env)))
344                (class (find-class class-name nil)))
345           (when (or (not (eq *boot-state* 'complete))
346                     (and class (not (class-finalized-p class))))
347             (setq class nil))
348           (when (and class-name (not (eq class-name t)))
349             (when (or (null type)
350                       (not (and class
351                                 (memq *the-class-structure-object*
352                                       (class-precedence-list class))))
353                       (optimize-slot-value-by-class-p class slot-name type))
354               (cons parameter-or-nil (or class class-name)))))))))
355
356 ;;; Check whether the binding of the named variable is modified in the
357 ;;; method body.
358 (defun parameter-modified-p (parameter-name env)
359   (let ((modified-variables (macroexpand '%parameter-binding-modified env)))
360     (memq parameter-name modified-variables)))
361
362 (defun optimize-slot-value (slots sparameter form)
363   (if sparameter
364       (let ((optimized-form
365              (destructuring-bind (ignore1 ignore2 slot-name-form) form
366                (declare (ignore ignore1 ignore2))
367                (let ((slot-name (eval slot-name-form)))
368                  (optimize-instance-access slots :read sparameter
369                                            slot-name nil)))))
370         ;; We don't return the optimized form directly, since there's
371         ;; still a chance that we'll find out later on that the
372         ;; optimization should not have been done, for example due to
373         ;; the walker encountering a SETQ on SPARAMETER later on in
374         ;; the body [ see for example clos.impure.lisp test with :name
375         ;; ((:setq :method-parameter) slot-value)) ]. Instead we defer
376         ;; the decision until the compiler macroexpands
377         ;; OPTIMIZED-SLOT-VALUE.
378         ;;
379         ;; Note that we must still call OPTIMIZE-INSTANCE-ACCESS at
380         ;; this point (instead of when expanding
381         ;; OPTIMIZED-SLOT-VALUE), since it mutates the structure of
382         ;; SLOTS. If that mutation isn't done while during the
383         ;; walking, MAKE-METHOD-LAMBDA-INTERNAL won't wrap a correct
384         ;; PV-BINDING form around the body, and compilation will fail.
385         ;; -- JES, 2006-09-18
386         `(optimized-slot-value ,form ,(car sparameter) ,optimized-form))
387       `(accessor-slot-value ,@(cdr form))))
388
389 (defmacro optimized-slot-value (form parameter-name optimized-form
390                                 &environment env)
391   ;; Either use OPTIMIZED-FORM or fall back to the safe
392   ;; ACCESSOR-SLOT-VALUE.
393   (if (parameter-modified-p parameter-name env)
394       `(accessor-slot-value ,@(cdr form))
395       optimized-form))
396
397 (defun optimize-set-slot-value (slots sparameter form)
398   (if sparameter
399       (let ((optimized-form
400              (destructuring-bind (ignore1 ignore2 slot-name-form new-value) form
401                (declare (ignore ignore1 ignore2))
402                (let ((slot-name (eval slot-name-form)))
403                  (optimize-instance-access slots
404                                            :write
405                                            sparameter
406                                            slot-name
407                                            new-value)))))
408         ;; See OPTIMIZE-SLOT-VALUE
409         `(optimized-set-slot-value ,form ,(car sparameter) ,optimized-form))
410       `(accessor-set-slot-value ,@(cdr form))))
411
412 (defmacro optimized-set-slot-value (form parameter-name optimized-form
413                                     &environment env)
414   (cond ((safe-code-p env)
415          ;; Don't optimize slot value setting in safe code, since the
416          ;; optimized version will fail to catch some type errors
417          ;; (for example when a subclass declares a tighter type for
418          ;; the slot than a superclass).
419          `(safe-set-slot-value ,@(cdr form)))
420         ((parameter-modified-p parameter-name env)
421          `(accessor-set-slot-value ,@(cdr form)))
422         (t
423          optimized-form)))
424
425 (defun optimize-slot-boundp (slots sparameter form)
426   (if sparameter
427       (let ((optimized-form
428              (destructuring-bind
429                    ;; FIXME: In CMU CL ca. 19991205, this binding list
430                    ;; had a fourth element in it, NEW-VALUE. It's hard
431                    ;; to see how that could possibly be right, since
432                    ;; SLOT-BOUNDP has no NEW-VALUE. Since it was
433                    ;; causing a failure in building PCL for SBCL, so I
434                    ;; changed it to match the definition of
435                    ;; SLOT-BOUNDP (and also to match the list used in
436                    ;; the similar OPTIMIZE-SLOT-VALUE,
437                    ;; above). However, I'm weirded out by this, since
438                    ;; this is old code which has worked for ages to
439                    ;; build PCL for CMU CL, so it's hard to see why it
440                    ;; should need a patch like this in order to build
441                    ;; PCL for SBCL. I'd like to return to this and
442                    ;; find a test case which exercises this function
443                    ;; both in CMU CL, to see whether it's really a
444                    ;; previously-unexercised bug or whether I've
445                    ;; misunderstood something (and, presumably,
446                    ;; patched it wrong).
447                    (slot-boundp-symbol instance slot-name-form)
448                  form
449                (declare (ignore slot-boundp-symbol instance))
450                (let ((slot-name (eval slot-name-form)))
451                  (optimize-instance-access slots
452                                            :boundp
453                                            sparameter
454                                            slot-name
455                                            nil)))))
456         ;; See OPTIMIZE-SLOT-VALUE
457         `(optimized-slot-boundp ,form ,(car sparameter) ,optimized-form))
458       `(accessor-slot-boundp ,@(cdr form))))
459
460 (defmacro optimized-slot-boundp (form parameter-name optimized-form
461                                  &environment env)
462   (if (parameter-modified-p parameter-name env)
463       `(accessor-slot-boundp ,@(cdr form))
464       optimized-form))
465
466 ;;; The SLOTS argument is an alist, the CAR of each entry is the name
467 ;;; of a required parameter to the function. The alist is in order, so
468 ;;; the position of an entry in the alist corresponds to the
469 ;;; argument's position in the lambda list.
470 (defun optimize-instance-access (slots
471                                  read/write
472                                  sparameter
473                                  slot-name
474                                  new-value)
475   (let ((class (if (consp sparameter) (cdr sparameter) *the-class-t*))
476         (parameter (if (consp sparameter) (car sparameter) sparameter)))
477     (if (and (eq *boot-state* 'complete)
478              (classp class)
479              (memq *the-class-structure-object* (class-precedence-list class)))
480         (let ((slotd (find-slot-definition class slot-name)))
481           (ecase read/write
482             (:read
483              `(,(slot-definition-defstruct-accessor-symbol slotd) ,parameter))
484             (:write
485              `(setf (,(slot-definition-defstruct-accessor-symbol slotd)
486                      ,parameter)
487                     ,new-value))
488             (:boundp
489              t)))
490         (let* ((parameter-entry (assq parameter slots))
491                (slot-entry      (assq slot-name (cdr parameter-entry)))
492                (position (posq parameter-entry slots))
493                (pv-offset-form (list 'pv-offset ''.PV-OFFSET.)))
494           (unless parameter-entry
495             (bug "slot optimization bewilderment: O-I-A"))
496           (unless slot-entry
497             (setq slot-entry (list slot-name))
498             (push slot-entry (cdr parameter-entry)))
499           (push pv-offset-form (cdr slot-entry))
500           (ecase read/write
501             (:read
502              `(instance-read ,pv-offset-form ,parameter ,position
503                              ',slot-name ',class))
504             (:write
505              `(let ((.new-value. ,new-value))
506                 (instance-write ,pv-offset-form ,parameter ,position
507                                 ',slot-name ',class .new-value.)))
508             (:boundp
509              `(instance-boundp ,pv-offset-form ,parameter ,position
510                                ',slot-name ',class)))))))
511
512 (defvar *unspecific-arg* '..unspecific-arg..)
513
514 (defun optimize-gf-call-internal (form slots env)
515   (when (and (consp form)
516              (eq (car form) 'the))
517     (setq form (caddr form)))
518   (or (and (symbolp form)
519            (let* ((rebound? (caddr (var-declaration '%variable-rebinding
520                                                     form
521                                                     env)))
522                   (parameter-or-nil (car (assq (or rebound? form) slots))))
523              (when parameter-or-nil
524                (let* ((class-name (caddr (var-declaration 'class
525                                                           parameter-or-nil
526                                                           env))))
527                  (when (and class-name (not (eq class-name t)))
528                    (position parameter-or-nil slots :key #'car))))))
529       (if (constantp form)
530           (let ((form (constant-form-value form)))
531             (if (symbolp form)
532                 form
533                 *unspecific-arg*))
534           *unspecific-arg*)))
535
536 (defun optimize-gf-call (slots calls gf-call-form nreq restp env)
537   (unless (eq (car gf-call-form) 'make-instance) ; XXX needs more work
538     (let* ((args (cdr gf-call-form))
539            (all-args-p (eq (car gf-call-form) 'make-instance))
540            (non-required-args (nthcdr nreq args))
541            (required-args (ldiff args non-required-args))
542            (call-spec (list (car gf-call-form) nreq restp
543                             (mapcar (lambda (form)
544                                       (optimize-gf-call-internal form slots env))
545                                     (if all-args-p
546                                         args
547                                         required-args))))
548            (call-entry (assoc call-spec calls :test #'equal))
549            (pv-offset-form (list 'pv-offset ''.PV-OFFSET.)))
550       (unless (some #'integerp
551                     (let ((spec-args (cdr call-spec)))
552                       (if all-args-p
553                           (ldiff spec-args (nthcdr nreq spec-args))
554                           spec-args)))
555         (return-from optimize-gf-call nil))
556       (unless call-entry
557         (setq call-entry (list call-spec))
558         (push call-entry (cdr calls)))
559       (push pv-offset-form (cdr call-entry))
560       (if (eq (car call-spec) 'make-instance)
561           `(funcall (pv-ref .pv. ,pv-offset-form) ,@(cdr gf-call-form))
562           `(let ((.emf. (pv-ref .pv. ,pv-offset-form)))
563             (invoke-effective-method-function .emf. ,restp
564              ,@required-args ,@(when restp `((list ,@non-required-args)))))))))
565
566 (define-walker-template pv-offset) ; These forms get munged by mutate slots.
567 (defmacro pv-offset (arg) arg)
568 (define-walker-template instance-accessor-parameter)
569 (defmacro instance-accessor-parameter (x) x)
570
571 ;;; It is safe for these two functions to be wrong. They just try to
572 ;;; guess what the most likely case will be.
573 (defun generate-fast-class-slot-access-p (class-form slot-name-form)
574   (let ((class (and (constantp class-form) (constant-form-value class-form)))
575         (slot-name (and (constantp slot-name-form)
576                         (constant-form-value slot-name-form))))
577     (and (eq *boot-state* 'complete)
578          (standard-class-p class)
579          (not (eq class *the-class-t*)) ; shouldn't happen, though.
580          (let ((slotd (find-slot-definition class slot-name)))
581            (and slotd (eq :class (slot-definition-allocation slotd)))))))
582
583 (defun skip-fast-slot-access-p (class-form slot-name-form type)
584   (let ((class (and (constantp class-form) (constant-form-value class-form)))
585         (slot-name (and (constantp slot-name-form)
586                         (constant-form-value slot-name-form))))
587     (and (eq *boot-state* 'complete)
588          (standard-class-p class)
589          (not (eq class *the-class-t*)) ; shouldn't happen, though.
590          (let ((slotd (find-slot-definition class slot-name)))
591            (and slotd (skip-optimize-slot-value-by-class-p class
592                                                            slot-name
593                                                            type))))))
594
595 (defun skip-optimize-slot-value-by-class-p (class slot-name type)
596   (let ((slotd (find-slot-definition class slot-name)))
597     (and slotd
598          (eq *boot-state* 'complete)
599          (not (slot-accessor-std-p slotd type)))))
600
601 (defmacro instance-read-internal (pv slots pv-offset default &optional kind)
602   (unless (member kind '(nil :instance :class :default))
603     (error "illegal kind argument to ~S: ~S" 'instance-read-internal kind))
604   (if (eq kind :default)
605       default
606       (let* ((index (gensym))
607              (value index))
608         `(locally (declare #.*optimize-speed*)
609           (let ((,index (pvref ,pv ,pv-offset)))
610             (setq ,value (typecase ,index
611                            ;; FIXME: the line marked by KLUDGE below
612                            ;; (and the analogous spot in
613                            ;; INSTANCE-WRITE-INTERNAL) is there purely
614                            ;; to suppress a type mismatch warning that
615                            ;; propagates through to user code.
616                            ;; Presumably SLOTS at this point can never
617                            ;; actually be NIL, but the compiler seems
618                            ;; to think it could, so we put this here
619                            ;; to shut it up.  (see also mail Rudi
620                            ;; Schlatte sbcl-devel 2003-09-21) -- CSR,
621                            ;; 2003-11-30
622                            ,@(when (or (null kind) (eq kind :instance))
623                                `((fixnum
624                                   (and ,slots ; KLUDGE
625                                    (clos-slots-ref ,slots ,index)))))
626                            ,@(when (or (null kind) (eq kind :class))
627                                `((cons (cdr ,index))))
628                            (t +slot-unbound+)))
629             (if (eq ,value +slot-unbound+)
630                 ,default
631                 ,value))))))
632
633 (defmacro instance-read (pv-offset parameter position slot-name class)
634   (if (skip-fast-slot-access-p class slot-name 'reader)
635       `(accessor-slot-value ,parameter ,slot-name)
636       `(instance-read-internal .pv. ,(slot-vector-symbol position)
637         ,pv-offset (accessor-slot-value ,parameter ,slot-name)
638         ,(if (generate-fast-class-slot-access-p class slot-name)
639              :class :instance))))
640
641 (defmacro instance-write-internal (pv slots pv-offset new-value default
642                                       &optional kind)
643   (unless (member kind '(nil :instance :class :default))
644     (error "illegal kind argument to ~S: ~S" 'instance-write-internal kind))
645   (if (eq kind :default)
646       default
647       (let* ((index (gensym)))
648         `(locally (declare #.*optimize-speed*)
649           (let ((,index (pvref ,pv ,pv-offset)))
650             (typecase ,index
651               ,@(when (or (null kind) (eq kind :instance))
652                   `((fixnum (and ,slots
653                              (setf (clos-slots-ref ,slots ,index)
654                                    ,new-value)))))
655               ,@(when (or (null kind) (eq kind :class))
656                   `((cons (setf (cdr ,index) ,new-value))))
657               (t ,default)))))))
658
659 (defmacro instance-write (pv-offset
660                           parameter
661                           position
662                           slot-name
663                           class
664                           new-value)
665   (if (skip-fast-slot-access-p class slot-name 'writer)
666       `(accessor-set-slot-value ,parameter ,slot-name ,new-value)
667       `(instance-write-internal .pv. ,(slot-vector-symbol position)
668         ,pv-offset ,new-value
669         (accessor-set-slot-value ,parameter ,slot-name ,new-value)
670         ,(if (generate-fast-class-slot-access-p class slot-name)
671              :class :instance))))
672
673 (defmacro instance-boundp-internal (pv slots pv-offset default
674                                        &optional kind)
675   (unless (member kind '(nil :instance :class :default))
676     (error "illegal kind argument to ~S: ~S" 'instance-boundp-internal kind))
677   (if (eq kind :default)
678       default
679       (let* ((index (gensym)))
680         `(locally (declare #.*optimize-speed*)
681           (let ((,index (pvref ,pv ,pv-offset)))
682             (typecase ,index
683               ,@(when (or (null kind) (eq kind :instance))
684                   `((fixnum (not (and ,slots
685                                       (eq (clos-slots-ref ,slots ,index)
686                                           +slot-unbound+))))))
687               ,@(when (or (null kind) (eq kind :class))
688                   `((cons (not (eq (cdr ,index) +slot-unbound+)))))
689               (t ,default)))))))
690
691 (defmacro instance-boundp (pv-offset parameter position slot-name class)
692   (if (skip-fast-slot-access-p class slot-name 'boundp)
693       `(accessor-slot-boundp ,parameter ,slot-name)
694       `(instance-boundp-internal .pv. ,(slot-vector-symbol position)
695         ,pv-offset (accessor-slot-boundp ,parameter ,slot-name)
696         ,(if (generate-fast-class-slot-access-p class slot-name)
697              :class :instance))))
698
699 ;;; This magic function has quite a job to do indeed.
700 ;;;
701 ;;; The careful reader will recall that <slots> contains all of the
702 ;;; optimized slot access forms produced by OPTIMIZE-INSTANCE-ACCESS.
703 ;;; Each of these is a call to either INSTANCE-READ or INSTANCE-WRITE.
704 ;;;
705 ;;; At the time these calls were produced, the first argument was
706 ;;; specified as the symbol .PV-OFFSET.; what we have to do now is
707 ;;; convert those pv-offset arguments into the actual number that is
708 ;;; the correct offset into the pv.
709 ;;;
710 ;;; But first, oh but first, we sort <slots> a bit so that for each
711 ;;; argument we have the slots in alphabetical order. This
712 ;;; canonicalizes the PV-TABLE's a bit and will hopefully lead to
713 ;;; having fewer PV's floating around. Even if the gain is only
714 ;;; modest, it costs nothing.
715 (defun slot-name-lists-from-slots (slots calls)
716   (multiple-value-bind (slots calls) (mutate-slots-and-calls slots calls)
717     (let* ((slot-name-lists
718             (mapcar (lambda (parameter-entry)
719                       (cons nil (mapcar #'car (cdr parameter-entry))))
720                     slots))
721            (call-list
722             (mapcar #'car calls)))
723       (dolist (call call-list)
724         (dolist (arg (cdr call))
725           (when (integerp arg)
726             (setf (car (nth arg slot-name-lists)) t))))
727       (setq slot-name-lists (mapcar (lambda (r+snl)
728                                       (when (or (car r+snl) (cdr r+snl))
729                                         r+snl))
730                                     slot-name-lists))
731       (let ((cvt (apply #'vector
732                         (let ((i -1))
733                           (mapcar (lambda (r+snl)
734                                     (when r+snl (incf i)))
735                                   slot-name-lists)))))
736         (setq call-list (mapcar (lambda (call)
737                                   (cons (car call)
738                                         (mapcar (lambda (arg)
739                                                   (if (integerp arg)
740                                                       (svref cvt arg)
741                                                       arg))
742                                                 (cdr call))))
743                                 call-list)))
744       (values slot-name-lists call-list))))
745
746 (defun mutate-slots-and-calls (slots calls)
747   (let ((sorted-slots (sort-slots slots))
748         (sorted-calls (sort-calls (cdr calls)))
749         (pv-offset -1))
750     (dolist (parameter-entry sorted-slots)
751       (dolist (slot-entry (cdr parameter-entry))
752         (incf pv-offset)
753         (dolist (form (cdr slot-entry))
754           (setf (cadr form) pv-offset))))
755     (dolist (call-entry sorted-calls)
756       (incf pv-offset)
757       (dolist (form (cdr call-entry))
758         (setf (cadr form) pv-offset)))
759     (values sorted-slots sorted-calls)))
760
761 (defun symbol-pkg-name (sym)
762   (let ((pkg (symbol-package sym)))
763     (if pkg (package-name pkg) "")))
764
765 ;;; FIXME: Because of the existence of UNINTERN and RENAME-PACKAGE,
766 ;;; the part of this ordering which is based on SYMBOL-PKG-NAME is not
767 ;;; stable. This ordering is only used in to
768 ;;; SLOT-NAME-LISTS-FROM-SLOTS, where it serves to "canonicalize the
769 ;;; PV-TABLE's a bit and will hopefully lead to having fewer PV's
770 ;;; floating around", so it sounds as though the instability won't
771 ;;; actually lead to bugs, just small inefficiency. But still, it
772 ;;; would be better to reimplement this function as a comparison based
773 ;;; on SYMBOL-HASH:
774 ;;;   * stable comparison
775 ;;;   * smaller code (here, and in being able to discard SYMBOL-PKG-NAME)
776 ;;;   * faster code.
777 (defun symbol-lessp (a b)
778   (if (eq (symbol-package a)
779           (symbol-package b))
780       (string-lessp (symbol-name a)
781                     (symbol-name b))
782       (string-lessp (symbol-pkg-name a)
783                     (symbol-pkg-name b))))
784
785 (defun symbol-or-cons-lessp (a b)
786   (etypecase a
787     (symbol (etypecase b
788               (symbol (symbol-lessp a b))
789               (cons t)))
790     (cons   (etypecase b
791               (symbol nil)
792               (cons (if (eq (car a) (car b))
793                         (symbol-or-cons-lessp (cdr a) (cdr b))
794                         (symbol-or-cons-lessp (car a) (car b))))))))
795
796 (defun sort-slots (slots)
797   (mapcar (lambda (parameter-entry)
798             (cons (car parameter-entry)
799                   (sort (cdr parameter-entry)   ;slot entries
800                         #'symbol-or-cons-lessp
801                         :key #'car)))
802           slots))
803
804 (defun sort-calls (calls)
805   (sort calls #'symbol-or-cons-lessp :key #'car))
806 \f
807 ;;;; This needs to work in terms of metatypes and also needs to work
808 ;;;; for automatically generated reader and writer functions.
809 ;;;; Automatically generated reader and writer functions use this
810 ;;;; stuff too.
811
812 (defmacro pv-binding ((required-parameters slot-name-lists pv-table-form)
813                       &body body)
814   (let (slot-vars pv-parameters)
815     (loop for slots in slot-name-lists
816           for required-parameter in required-parameters
817           for i from 0
818           do (when slots
819                (push required-parameter pv-parameters)
820                (push (slot-vector-symbol i) slot-vars)))
821     `(pv-binding1 (.pv. .calls. ,pv-table-form
822                    ,(nreverse pv-parameters) ,(nreverse slot-vars))
823        ,@body)))
824
825 (defmacro pv-binding1 ((pv calls pv-table-form pv-parameters slot-vars)
826                        &body body)
827   `(pv-env (,pv ,calls ,pv-table-form ,pv-parameters)
828      (let (,@(mapcar (lambda (slot-var p) `(,slot-var (get-slots-or-nil ,p)))
829                      slot-vars pv-parameters))
830        (declare (ignorable ,@(mapcar #'identity slot-vars)))
831        ,@body)))
832
833 ;;; This will only be visible in PV-ENV when the default MAKE-METHOD-LAMBDA is
834 ;;; overridden.
835 (define-symbol-macro pv-env-environment overridden)
836
837 (defmacro pv-env (&environment env
838                   (pv calls pv-table-form pv-parameters)
839                   &rest forms)
840   ;; Decide which expansion to use based on the state of the PV-ENV-ENVIRONMENT
841   ;; symbol-macrolet.
842   (if (eq (macroexpand 'pv-env-environment env) 'default)
843       `(let ((,pv (car .pv-cell.))
844              (,calls (cdr .pv-cell.)))
845          (declare ,(make-pv-type-declaration pv)
846                   ,(make-calls-type-declaration calls))
847          ,pv ,calls
848          ,@forms)
849       `(let* ((.pv-table. ,pv-table-form)
850               (.pv-cell. (pv-table-lookup-pv-args .pv-table. ,@pv-parameters))
851               (,pv (car .pv-cell.))
852               (,calls (cdr .pv-cell.)))
853         (declare ,(make-pv-type-declaration pv))
854         (declare ,(make-calls-type-declaration calls))
855         ,pv ,calls
856         ,@forms)))
857
858 (defvar *non-var-declarations*
859   ;; FIXME: VALUES was in this list, conditionalized with #+CMU, but I
860   ;; don't *think* CMU CL had, or SBCL has, VALUES declarations. If
861   ;; SBCL doesn't have 'em, VALUES should probably be removed from
862   ;; this list.
863   '(values
864     %method-name
865     %method-lambda-list
866     optimize
867     ftype
868     inline
869     notinline))
870
871 (defvar *var-declarations-with-arg*
872   '(%class
873     type))
874
875 (defvar *var-declarations-without-arg*
876   '(ignore
877     ignorable special dynamic-extent
878     ;; FIXME: Possibly this entire list and variable could go away.
879     ;; If not, certainly we should remove all these built-in typenames
880     ;; from the list, and replace them with a test for "is it a type
881     ;; name?" (CLTL1 allowed only built-in type names as declarations,
882     ;; but ANSI CL allows any type name as a declaration.)
883     array atom base-char bignum bit bit-vector character compiled-function
884     complex cons double-float extended-char
885     fixnum float function hash-table integer
886     keyword list long-float nil null number package pathname random-state ratio
887     rational readtable sequence short-float signed-byte simple-array
888     simple-bit-vector simple-string simple-vector single-float standard-char
889     stream string symbol t unsigned-byte vector))
890
891 (defun split-declarations (body args maybe-reads-params-p)
892   (let ((inner-decls nil)
893         (outer-decls nil)
894         decl)
895     (loop (when (null body) (return nil))
896           (setq decl (car body))
897           (unless (and (consp decl)
898                        (eq (car decl) 'declare))
899             (return nil))
900           (dolist (form (cdr decl))
901             (when (consp form)
902               (let ((declaration-name (car form)))
903                 (if (member declaration-name *non-var-declarations*)
904                     (push `(declare ,form) outer-decls)
905                     (let ((arg-p
906                            (member declaration-name
907                                    *var-declarations-with-arg*))
908                           (non-arg-p
909                            (member declaration-name
910                                    *var-declarations-without-arg*))
911                           (dname (list (pop form)))
912                           (inners nil) (outers nil))
913                       (unless (or arg-p non-arg-p)
914                         ;; FIXME: This warning, and perhaps the
915                         ;; various *VAR-DECLARATIONS-FOO* and/or
916                         ;; *NON-VAR-DECLARATIONS* variables,
917                         ;; could probably go away now that we're not
918                         ;; trying to be portable between different
919                         ;; CLTL1 hosts the way PCL was. (Note that to
920                         ;; do this right, we need to be able to handle
921                         ;; user-defined (DECLAIM (DECLARATION FOO))
922                         ;; stuff.)
923                         (warn "The declaration ~S is not understood by ~S.~@
924                                Please put ~S on one of the lists ~S,~%~S, or~%~S.~@
925                         (Assuming it is a variable declaration without argument)."
926                               declaration-name 'split-declarations
927                               declaration-name
928                               '*non-var-declarations*
929                               '*var-declarations-with-arg*
930                               '*var-declarations-without-arg*)
931                         (push declaration-name *var-declarations-without-arg*))
932                       (when arg-p
933                         (setq dname (append dname (list (pop form)))))
934                       (case (car dname)
935                         (%class (push `(declare (,@dname ,@form)) inner-decls))
936                         (t
937                          (dolist (var form)
938                            (if (member var args)
939                                ;; Quietly remove IGNORE declarations
940                                ;; on args when a next-method is
941                                ;; involved, to prevent compiler
942                                ;; warnings about ignored args being
943                                ;; read.
944                                (unless (and maybe-reads-params-p
945                                             (eq (car dname) 'ignore))
946                                  (push var outers))
947                                (push var inners)))
948                          (when outers
949                            (push `(declare (,@dname ,@outers)) outer-decls))
950                          (when inners
951                            (push
952                             `(declare (,@dname ,@inners))
953                             inner-decls)))))))))
954           (setq body (cdr body)))
955     (values outer-decls inner-decls body)))
956
957 ;;; Pull a name out of the %METHOD-NAME declaration in the function
958 ;;; body given, or return NIL if no %METHOD-NAME declaration is found.
959 (defun body-method-name (body)
960   (multiple-value-bind (real-body declarations documentation)
961       (parse-body body)
962     (declare (ignore real-body documentation))
963     (let ((name-decl (get-declaration '%method-name declarations)))
964       (and name-decl
965            (destructuring-bind (name) name-decl
966              name)))))
967
968 ;;; Convert a lambda expression containing a SB-PCL::%METHOD-NAME
969 ;;; declaration (which is a naming style internal to PCL) into an
970 ;;; SB-INT:NAMED-LAMBDA expression (which is a naming style used
971 ;;; throughout SBCL, understood by the main compiler); or if there's
972 ;;; no SB-PCL::%METHOD-NAME declaration, then just return the original
973 ;;; lambda expression.
974 (defun name-method-lambda (method-lambda)
975   (let ((method-name (body-method-name (cddr method-lambda))))
976     (if method-name
977         `(named-lambda (slow-method ,method-name) ,(rest method-lambda))
978         method-lambda)))
979
980 (defun make-method-initargs-form-internal (method-lambda initargs env)
981   (declare (ignore env))
982   (let (method-lambda-args
983         lmf ; becomes body of function
984         lmf-params)
985     (if (not (and (= 3 (length method-lambda))
986                   (= 2 (length (setq method-lambda-args (cadr method-lambda))))
987                   (consp (setq lmf (third method-lambda)))
988                   (eq 'simple-lexical-method-functions (car lmf))
989                   (eq (car method-lambda-args)
990                       (cadr (setq lmf-params (cadr lmf))))
991                   (eq (cadr method-lambda-args)
992                       (caddr lmf-params))))
993         `(list* :function ,(name-method-lambda method-lambda)
994                 ',initargs)
995         (let* ((lambda-list (car lmf-params))
996                (nreq 0)
997                (restp nil)
998                (args nil))
999           (dolist (arg lambda-list)
1000             (when (member arg '(&optional &rest &key))
1001               (setq restp t)
1002               (return nil))
1003             (when (eq arg '&aux)
1004               (return nil))
1005             (incf nreq)
1006             (push arg args))
1007           (setq args (nreverse args))
1008           (setf (getf (getf initargs 'plist) :arg-info) (cons nreq restp))
1009           (make-method-initargs-form-internal1
1010            initargs (cddr lmf) args lmf-params restp)))))
1011
1012 (defun make-method-initargs-form-internal1
1013     (initargs body req-args lmf-params restp)
1014   (multiple-value-bind (outer-decls inner-decls body-sans-decls)
1015       (split-declarations
1016        body req-args (or (getf (cdr lmf-params) :call-next-method-p)
1017                          (getf (cdr lmf-params) :setq-p)))
1018     (let* ((rest-arg (when restp '.rest-arg.))
1019            (args+rest-arg (if restp
1020                               (append req-args (list rest-arg))
1021                               req-args)))
1022       `(list*
1023         :function
1024         (let* ((fmf (,(if (body-method-name body) 'named-lambda 'lambda)
1025                      ,@(when (body-method-name body)
1026                          ;; function name
1027                          (list (cons 'fast-method (body-method-name body))))
1028                      (.pv-cell. .next-method-call. ,@args+rest-arg) ; function args
1029                      ;; body of the function
1030                      (declare (ignorable .pv-cell. .next-method-call.)
1031                               (disable-package-locks pv-env-environment))
1032                      ,@outer-decls
1033                      (symbol-macrolet ((pv-env-environment default))
1034                          (fast-lexical-method-functions
1035                           (,(car lmf-params) .next-method-call. ,req-args ,rest-arg
1036                             ,@(cdddr lmf-params))
1037                           ,@inner-decls
1038                           ,@body-sans-decls))))
1039               (mf (%make-method-function fmf nil)))
1040           (set-funcallable-instance-function
1041            mf (method-function-from-fast-function fmf ',(getf initargs 'plist)))
1042           mf)
1043         ',initargs))))
1044
1045 ;;; Use arrays and hash tables and the fngen stuff to make this much
1046 ;;; better. It doesn't really matter, though, because a function
1047 ;;; returned by this will get called only when the user explicitly
1048 ;;; funcalls a result of method-function. BUT, this is needed to make
1049 ;;; early methods work.
1050 (defun method-function-from-fast-function (fmf plist)
1051   (declare (type function fmf))
1052   (let* ((method-function nil)
1053          (calls (getf plist :call-list))
1054          (snl (getf plist :slot-name-lists))
1055          (pv-table (when (or calls snl)
1056                      (intern-pv-table :call-list calls :slot-name-lists snl)))
1057          (arg-info (getf plist :arg-info))
1058          (nreq (car arg-info))
1059          (restp (cdr arg-info)))
1060     (setq method-function
1061           (lambda (method-args next-methods)
1062             (let* ((pv-cell (when pv-table
1063                               (get-pv-cell method-args pv-table)))
1064                    (nm (car next-methods))
1065                    (nms (cdr next-methods))
1066                    (nmc (when nm
1067                           (make-method-call
1068                            :function (if (std-instance-p nm)
1069                                          (method-function nm)
1070                                          nm)
1071                            :call-method-args (list nms)))))
1072               (if restp
1073                   (let* ((rest (nthcdr nreq method-args))
1074                          (args (ldiff method-args rest)))
1075                     (apply fmf pv-cell nmc (nconc args (list rest))))
1076                   (apply fmf pv-cell nmc method-args)))))
1077     ;; FIXME: this looks dangerous.
1078     (let* ((fname (%fun-name fmf)))
1079       (when (and fname (eq (car fname) 'fast-method))
1080         (set-fun-name method-function (cons 'slow-method (cdr fname)))))
1081     method-function))
1082
1083 ;;; this is similar to the above, only not quite.  Only called when
1084 ;;; the MOP is heavily involved.  Not quite parallel to
1085 ;;; METHOD-FUNCTION-FROM-FAST-METHOD-FUNCTION, because we can close
1086 ;;; over the actual PV-CELL in this case.
1087 (defun method-function-from-fast-method-call (fmc)
1088   (let* ((fmf (fast-method-call-function fmc))
1089          (pv-cell (fast-method-call-pv-cell fmc))
1090          (arg-info (fast-method-call-arg-info fmc))
1091          (nreq (car arg-info))
1092          (restp (cdr arg-info)))
1093     (lambda (method-args next-methods)
1094       (let* ((nm (car next-methods))
1095              (nms (cdr next-methods))
1096              (nmc (when nm
1097                     (make-method-call
1098                      :function (if (std-instance-p nm)
1099                                    (method-function nm)
1100                                    nm)
1101                      :call-method-args (list nms)))))
1102         (if restp
1103             (let* ((rest (nthcdr nreq method-args))
1104                    (args (ldiff method-args rest)))
1105               (apply fmf pv-cell nmc (nconc args (list rest))))
1106             (apply fmf pv-cell nmc method-args))))))
1107
1108 (defun get-pv-cell (method-args pv-table)
1109   (let ((pv-wrappers (pv-wrappers-from-all-args pv-table method-args)))
1110     (when pv-wrappers
1111       (pv-table-lookup pv-table pv-wrappers))))
1112
1113 (defun pv-table-lookup-pv-args (pv-table &rest pv-parameters)
1114   (pv-table-lookup pv-table (pv-wrappers-from-pv-args pv-parameters)))
1115
1116 (defun pv-wrappers-from-pv-args (&rest args)
1117   (let (wrappers)
1118     (dolist (arg args (if (cdr wrappers) (nreverse wrappers) (car wrappers)))
1119       (let ((wrapper (wrapper-of arg)))
1120         (push (if (invalid-wrapper-p wrapper)
1121                   (check-wrapper-validity wrapper)
1122                   wrapper)
1123               wrappers)))))
1124
1125 (defun pv-wrappers-from-all-args (pv-table args)
1126   (loop for snl in (pv-table-slot-name-lists pv-table) and arg in args
1127         when snl
1128           collect (wrapper-of arg) into wrappers
1129         finally (return (if (cdr wrappers) wrappers (car wrappers)))))
1130
1131 ;;; Return the subset of WRAPPERS which is used in the cache
1132 ;;; of PV-TABLE.
1133 (defun pv-wrappers-from-all-wrappers (pv-table wrappers)
1134   (loop for snl in (pv-table-slot-name-lists pv-table) and w in wrappers
1135         when snl
1136           collect w into result
1137         finally (return (if (cdr result) result (car result)))))
1138