1 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; This software is derived from software originally released by Xerox
5 ;;;; Corporation. Copyright and release statements follow. Later modifications
6 ;;;; to the software are in the public domain and are provided with
7 ;;;; absolutely no warranty. See the COPYING and CREDITS files for more
10 ;;;; copyright information from original PCL sources:
12 ;;;; Copyright (c) 1985, 1986, 1987, 1988, 1989, 1990 Xerox Corporation.
13 ;;;; All rights reserved.
15 ;;;; Use and copying of this software and preparation of derivative works based
16 ;;;; upon this software are permitted. Any distribution of this software or
17 ;;;; derivative works must comply with all applicable United States export
20 ;;;; This software is made available AS IS, and Xerox Corporation makes no
21 ;;;; warranty about the software, its performance or its conformity to any
29 ;;; Methods themselves are simple inanimate objects. Most properties of
30 ;;; methods are immutable, methods cannot be reinitialized. The following
31 ;;; properties of methods can be changed:
32 ;;; METHOD-GENERIC-FUNCTION
33 ;;; METHOD-FUNCTION ??
35 (defmethod method-function ((method standard-method))
36 (or (slot-value method 'function)
37 (let ((fmf (slot-value method 'fast-function)))
38 (unless fmf ; The :BEFORE SHARED-INITIALIZE method prevents this.
39 (error "~S doesn't seem to have a METHOD-FUNCTION." method))
40 (setf (slot-value method 'function)
41 (method-function-from-fast-function fmf)))))
43 (defmethod accessor-method-class ((method standard-accessor-method))
44 (car (slot-value method 'specializers)))
46 (defmethod accessor-method-class ((method standard-writer-method))
47 (cadr (slot-value method 'specializers)))
51 ;;; Error checking is done in before methods. Because of the simplicity of
52 ;;; standard method objects the standard primary method can fill the slots.
54 ;;; Methods are not reinitializable.
56 (defmethod reinitialize-instance ((method standard-method) &rest initargs)
57 (declare (ignore initargs))
58 (error "An attempt was made to reinitialize the method ~S.~%~
59 Method objects cannot be reinitialized."
62 (defmethod legal-documentation-p ((object standard-method) x)
63 (if (or (null x) (stringp x))
67 (defmethod legal-lambda-list-p ((object standard-method) x)
71 (defmethod legal-method-function-p ((object standard-method) x)
76 (defmethod legal-qualifiers-p ((object standard-method) x)
77 (flet ((improper-list ()
78 (return-from legal-qualifiers-p "Is not a proper list.")))
79 (dolist-carefully (q x improper-list)
80 (let ((ok (legal-qualifier-p object q)))
82 (return-from legal-qualifiers-p
83 (format nil "Contains ~S which ~A" q ok)))))
86 (defmethod legal-qualifier-p ((object standard-method) x)
89 "is not a non-null atom"))
91 (defmethod legal-slot-name-p ((object standard-method) x)
92 (cond ((not (symbolp x)) "is not a symbol")
95 (defmethod legal-specializers-p ((object standard-method) x)
96 (flet ((improper-list ()
97 (return-from legal-specializers-p "Is not a proper list.")))
98 (dolist-carefully (s x improper-list)
99 (let ((ok (legal-specializer-p object s)))
101 (return-from legal-specializers-p
102 (format nil "Contains ~S which ~A" s ok)))))
105 (defvar *allow-experimental-specializers-p* nil)
107 (defmethod legal-specializer-p ((object standard-method) x)
108 (if (if *allow-experimental-specializers-p*
111 (eql-specializer-p x)))
113 "is neither a class object nor an EQL specializer"))
115 (defmethod shared-initialize :before ((method standard-method)
123 (declare (ignore slot-names))
124 (flet ((lose (initarg value string)
125 (error "when initializing the method ~S:~%~
126 The ~S initialization argument was: ~S.~%~
128 method initarg value string)))
129 (let ((check-qualifiers (legal-qualifiers-p method qualifiers))
130 (check-lambda-list (legal-lambda-list-p method lambda-list))
131 (check-specializers (legal-specializers-p method specializers))
132 (check-fun (legal-method-function-p method
135 (check-documentation (legal-documentation-p method documentation)))
136 (unless (eq check-qualifiers t)
137 (lose :qualifiers qualifiers check-qualifiers))
138 (unless (eq check-lambda-list t)
139 (lose :lambda-list lambda-list check-lambda-list))
140 (unless (eq check-specializers t)
141 (lose :specializers specializers check-specializers))
142 (unless (eq check-fun t)
143 (lose :function function check-fun))
144 (unless (eq check-documentation t)
145 (lose :documentation documentation check-documentation)))))
147 (defmethod shared-initialize :before ((method standard-accessor-method)
149 &key slot-name slot-definition)
150 (declare (ignore slot-names))
151 (unless slot-definition
152 (let ((legalp (legal-slot-name-p method slot-name)))
153 ;; FIXME: nasty convention; should be renamed to ILLEGAL-SLOT-NAME-P and
154 ;; ILLEGALP, and the convention redone to be less twisty
155 (unless (eq legalp t)
156 (error "The value of the :SLOT-NAME initarg ~A." legalp)))))
158 (defmethod shared-initialize :after ((method standard-method) slot-names
160 &key qualifiers method-spec plist)
161 (declare (ignore slot-names method-spec plist))
162 (initialize-method-function initargs nil method)
163 (setf (plist-value method 'qualifiers) qualifiers)
165 (setf (slot-value method 'closure-generator)
166 (method-function-closure-generator (slot-value method 'function))))
168 (defmethod shared-initialize :after ((method standard-accessor-method)
171 (declare (ignore slot-names))
172 (with-slots (slot-name slot-definition)
174 (unless slot-definition
175 (let ((class (accessor-method-class method)))
176 (when (slot-class-p class)
177 (setq slot-definition (find slot-name (class-direct-slots class)
178 :key #'slot-definition-name)))))
179 (when (and slot-definition (null slot-name))
180 (setq slot-name (slot-definition-name slot-definition)))))
182 (defmethod method-qualifiers ((method standard-method))
183 (plist-value method 'qualifiers))
185 (defvar *the-class-generic-function*
186 (find-class 'generic-function))
187 (defvar *the-class-standard-generic-function*
188 (find-class 'standard-generic-function))
190 (defmethod shared-initialize :before
191 ((generic-function standard-generic-function)
193 &key (name nil namep)
194 (lambda-list () lambda-list-p)
195 argument-precedence-order
198 (method-class nil method-class-supplied-p)
199 (method-combination nil method-combination-supplied-p))
200 (declare (ignore slot-names
201 declarations argument-precedence-order documentation
202 lambda-list lambda-list-p))
205 (set-fun-name generic-function name))
207 (flet ((initarg-error (initarg value string)
208 (error "when initializing the generic function ~S:~%~
209 The ~S initialization argument was: ~A.~%~
211 generic-function initarg value string)))
212 (cond (method-class-supplied-p
213 (when (symbolp method-class)
214 (setq method-class (find-class method-class)))
215 (unless (and (classp method-class)
216 (*subtypep (class-eq-specializer method-class)
218 (initarg-error :method-class
220 "a subclass of the class METHOD"))
221 (setf (slot-value generic-function 'method-class) method-class))
222 ((slot-boundp generic-function 'method-class))
224 (initarg-error :method-class
226 "a subclass of the class METHOD")))
227 (cond (method-combination-supplied-p
228 (unless (method-combination-p method-combination)
229 (initarg-error :method-combination
231 "a method combination object")))
232 ((slot-boundp generic-function 'method-combination))
234 (initarg-error :method-combination
236 "a method combination object")))))
239 (defmethod reinitialize-instance ((generic-function standard-generic-function)
243 argument-precedence-order
248 (declare (ignore documentation declarations argument-precedence-order
249 lambda-list name method-class method-combination))
250 (macrolet ((add-initarg (check name slot-name)
252 (push (slot-value generic-function ,slot-name) initargs)
253 (push ,name initargs))))
254 ; (add-initarg name :name 'name)
255 ; (add-initarg lambda-list :lambda-list 'lambda-list)
256 ; (add-initarg argument-precedence-order
257 ; :argument-precedence-order
258 ; 'argument-precedence-order)
259 ; (add-initarg declarations :declarations 'declarations)
260 ; (add-initarg documentation :documentation 'documentation)
261 ; (add-initarg method-class :method-class 'method-class)
262 ; (add-initarg method-combination :method-combination 'method-combination)
263 (apply #'call-next-method generic-function initargs)))
266 ;;; These three are scheduled for demolition.
268 (defmethod remove-named-method (generic-function-name argument-specifiers
270 (let ((generic-function ())
272 (cond ((or (null (fboundp generic-function-name))
273 (not (generic-function-p
274 (setq generic-function
275 (fdefinition generic-function-name)))))
276 (error "~S does not name a generic function."
277 generic-function-name))
278 ((null (setq method (get-method generic-function
283 (error "There is no method for the generic function ~S~%~
284 which matches the ARGUMENT-SPECIFIERS ~S."
286 argument-specifiers))
288 (remove-method generic-function method)))))
290 (defun real-add-named-method (generic-function-name
294 &rest other-initargs)
295 (unless (and (fboundp generic-function-name)
296 (typep (fdefinition generic-function-name) 'generic-function))
297 (style-warn "implicitly creating new generic function ~S"
298 generic-function-name))
299 ;; XXX What about changing the class of the generic function if
300 ;; there is one? Whose job is that, anyway? Do we need something
301 ;; kind of like CLASS-FOR-REDEFINITION?
302 (let* ((generic-function
303 (ensure-generic-function generic-function-name))
304 (specs (parse-specializers specializers))
305 (proto (method-prototype-for-gf generic-function-name))
306 (new (apply #'make-instance (class-of proto)
307 :qualifiers qualifiers
309 :lambda-list lambda-list
311 (add-method generic-function new)))
313 (defun real-get-method (generic-function qualifiers specializers
314 &optional (errorp t))
316 (dolist (method (generic-function-methods generic-function))
317 (let ((mspecializers (method-specializers method)))
318 (when (and (equal qualifiers (method-qualifiers method))
319 (= (length specializers) (length mspecializers))
320 (every #'same-specializer-p specializers
321 (method-specializers method)))
326 (error "no method on ~S with qualifiers ~:S and specializers ~:S"
327 generic-function qualifiers specializers)))))
329 (defmethod find-method ((generic-function standard-generic-function)
330 qualifiers specializers &optional (errorp t))
331 (real-get-method generic-function qualifiers
332 (parse-specializers specializers) errorp))
334 ;;; Compute various information about a generic-function's arglist by looking
335 ;;; at the argument lists of the methods. The hair for trying not to use
336 ;;; &REST arguments lives here.
337 ;;; The values returned are:
338 ;;; number-of-required-arguments
339 ;;; the number of required arguments to this generic-function's
340 ;;; discriminating function
342 ;;; whether or not this generic-function's discriminating
343 ;;; function takes an &rest argument.
344 ;;; specialized-argument-positions
345 ;;; a list of the positions of the arguments this generic-function
346 ;;; specializes (e.g. for a classical generic-function this is the
348 (defmethod compute-discriminating-function-arglist-info
349 ((generic-function standard-generic-function))
350 ;;(declare (values number-of-required-arguments &rest-argument-p
351 ;; specialized-argument-postions))
352 (let ((number-required nil)
354 (specialized-positions ())
355 (methods (generic-function-methods generic-function)))
356 (dolist (method methods)
357 (multiple-value-setq (number-required restp specialized-positions)
358 (compute-discriminating-function-arglist-info-internal
359 generic-function method number-required restp specialized-positions)))
360 (values number-required restp (sort specialized-positions #'<))))
362 (defun compute-discriminating-function-arglist-info-internal
363 (generic-function method number-of-requireds restp
364 specialized-argument-positions)
365 (declare (ignore generic-function)
366 (type (or null fixnum) number-of-requireds))
368 (declare (fixnum requireds))
369 ;; Go through this methods arguments seeing how many are required,
370 ;; and whether there is an &rest argument.
371 (dolist (arg (method-lambda-list method))
372 (cond ((eq arg '&aux) (return))
373 ((memq arg '(&optional &rest &key))
374 (return (setq restp t)))
375 ((memq arg lambda-list-keywords))
376 (t (incf requireds))))
377 ;; Now go through this method's type specifiers to see which
378 ;; argument positions are type specified. Treat T specially
379 ;; in the usual sort of way. For efficiency don't bother to
380 ;; keep specialized-argument-positions sorted, rather depend
381 ;; on our caller to do that.
383 (dolist (type-spec (method-specializers method))
384 (unless (eq type-spec *the-class-t*)
385 (pushnew pos specialized-argument-positions))
387 ;; Finally merge the values for this method into the values
388 ;; for the exisiting methods and return them. Note that if
389 ;; num-of-requireds is NIL it means this is the first method
390 ;; and we depend on that.
391 (values (min (or number-of-requireds requireds) requireds)
393 (and number-of-requireds (/= number-of-requireds requireds)))
394 specialized-argument-positions)))
396 (defun make-discriminating-function-arglist (number-required-arguments restp)
397 (nconc (let ((args nil))
398 (dotimes (i number-required-arguments)
399 (push (intern (format nil "Discriminating Function Arg ~D" i))
403 `(&rest ,(intern "Discriminating Function &rest Arg")))))
405 (defmethod generic-function-argument-precedence-order
406 ((gf standard-generic-function))
407 (aver (eq *boot-state* 'complete))
408 (loop with arg-info = (gf-arg-info gf)
409 with lambda-list = (arg-info-lambda-list arg-info)
410 for argument-position in (arg-info-precedence arg-info)
411 collect (nth argument-position lambda-list)))
413 (defmethod generic-function-lambda-list ((gf generic-function))
416 (defmethod gf-fast-method-function-p ((gf standard-generic-function))
417 (gf-info-fast-mf-p (slot-value gf 'arg-info)))
419 (defmethod initialize-instance :after ((gf standard-generic-function)
420 &key (lambda-list nil lambda-list-p)
421 argument-precedence-order)
422 (with-slots (arg-info)
426 :lambda-list lambda-list
427 :argument-precedence-order argument-precedence-order)
429 (when (arg-info-valid-p arg-info)
432 (defmethod reinitialize-instance :after ((gf standard-generic-function)
434 &key (lambda-list nil lambda-list-p)
435 (argument-precedence-order
436 nil argument-precedence-order-p))
437 (with-slots (arg-info)
440 (if argument-precedence-order-p
442 :lambda-list lambda-list
443 :argument-precedence-order argument-precedence-order)
445 :lambda-list lambda-list))
447 (when (and (arg-info-valid-p arg-info)
449 (or lambda-list-p (cddr args)))
452 (declaim (special *lazy-dfun-compute-p*))
454 (defun set-methods (gf methods)
455 (setf (generic-function-methods gf) nil)
456 (loop (when (null methods) (return gf))
457 (real-add-method gf (pop methods) methods)))
459 (defun real-add-method (generic-function method &optional skip-dfun-update-p)
460 (when (method-generic-function method)
461 (error "The method ~S is already part of the generic~@
462 function ~S. It can't be added to another generic~@
463 function until it is removed from the first one."
464 method (method-generic-function method)))
465 (flet ((similar-lambda-lists-p (method-a method-b)
466 (multiple-value-bind (a-nreq a-nopt a-keyp a-restp)
467 (analyze-lambda-list (method-lambda-list method-a))
468 (multiple-value-bind (b-nreq b-nopt b-keyp b-restp)
469 (analyze-lambda-list (method-lambda-list method-b))
470 (and (= a-nreq b-nreq)
472 (eq (or a-keyp a-restp)
473 (or b-keyp b-restp)))))))
474 (let* ((name (generic-function-name generic-function))
475 (qualifiers (method-qualifiers method))
476 (specializers (method-specializers method))
477 (existing (get-method generic-function
482 ;; If there is already a method like this one then we must get
483 ;; rid of it before proceeding. Note that we call the generic
484 ;; function REMOVE-METHOD to remove it rather than doing it in
485 ;; some internal way.
486 (when (and existing (similar-lambda-lists-p existing method))
487 (remove-method generic-function existing))
489 (setf (method-generic-function method) generic-function)
490 (pushnew method (generic-function-methods generic-function))
491 (dolist (specializer specializers)
492 (add-direct-method specializer method))
494 ;; KLUDGE: SET-ARG-INFO contains the error-detecting logic for
495 ;; detecting attempts to add methods with incongruent lambda
496 ;; lists. However, according to Gerd Moellmann on cmucl-imp,
497 ;; it also depends on the new method already having been added
498 ;; to the generic function. Therefore, we need to remove it
500 (let ((remove-again-p t))
503 (set-arg-info generic-function :new-method method)
504 (setq remove-again-p nil))
506 (remove-method generic-function method))))
507 (unless skip-dfun-update-p
508 (update-ctors 'add-method
509 :generic-function generic-function
511 (update-dfun generic-function))
514 (defun real-remove-method (generic-function method)
515 (when (eq generic-function (method-generic-function method))
516 (let* ((name (generic-function-name generic-function))
517 (specializers (method-specializers method))
518 (methods (generic-function-methods generic-function))
519 (new-methods (remove method methods)))
520 (setf (method-generic-function method) nil)
521 (setf (generic-function-methods generic-function) new-methods)
522 (dolist (specializer (method-specializers method))
523 (remove-direct-method specializer method))
524 (set-arg-info generic-function)
525 (update-ctors 'remove-method
526 :generic-function generic-function
528 (update-dfun generic-function)))
531 (defun compute-applicable-methods-function (generic-function arguments)
532 (values (compute-applicable-methods-using-types
534 (types-from-args generic-function arguments 'eql))))
536 (defmethod compute-applicable-methods
537 ((generic-function generic-function) arguments)
538 (values (compute-applicable-methods-using-types
540 (types-from-args generic-function arguments 'eql))))
542 (defmethod compute-applicable-methods-using-classes
543 ((generic-function generic-function) classes)
544 (compute-applicable-methods-using-types
546 (types-from-args generic-function classes 'class-eq)))
548 (defun proclaim-incompatible-superclasses (classes)
549 (setq classes (mapcar (lambda (class)
554 (dolist (class classes)
555 (dolist (other-class classes)
556 (unless (eq class other-class)
557 (pushnew other-class (class-incompatible-superclass-list class))))))
559 (defun superclasses-compatible-p (class1 class2)
560 (let ((cpl1 (cpl-or-nil class1))
561 (cpl2 (cpl-or-nil class2)))
563 (dolist (ic (class-incompatible-superclass-list sc1))
565 (return-from superclasses-compatible-p nil))))))
568 #'proclaim-incompatible-superclasses
569 '(;; superclass class
570 (built-in-class std-class structure-class) ; direct subclasses of pcl-class
571 (standard-class funcallable-standard-class)
572 ;; superclass metaobject
573 (class eql-specializer class-eq-specializer method method-combination
574 generic-function slot-definition)
575 ;; metaclass built-in-class
576 (number sequence character ; direct subclasses of t, but not array
577 standard-object structure-object) ; or symbol
578 (number array character symbol ; direct subclasses of t, but not
579 standard-object structure-object) ; sequence
580 (complex float rational) ; direct subclasses of number
581 (integer ratio) ; direct subclasses of rational
582 (list vector) ; direct subclasses of sequence
583 (cons null) ; direct subclasses of list
584 (string bit-vector) ; direct subclasses of vector
587 (defmethod same-specializer-p ((specl1 specializer) (specl2 specializer))
590 (defmethod same-specializer-p ((specl1 class) (specl2 class))
593 (defmethod specializer-class ((specializer class))
596 (defmethod same-specializer-p ((specl1 class-eq-specializer)
597 (specl2 class-eq-specializer))
598 (eq (specializer-class specl1) (specializer-class specl2)))
600 (defmethod same-specializer-p ((specl1 eql-specializer)
601 (specl2 eql-specializer))
602 (eq (specializer-object specl1) (specializer-object specl2)))
604 (defmethod specializer-class ((specializer eql-specializer))
605 (class-of (slot-value specializer 'object)))
607 (defvar *in-gf-arg-info-p* nil)
608 (setf (gdefinition 'arg-info-reader)
609 (let ((mf (initialize-method-function
610 (make-internal-reader-method-function
611 'standard-generic-function 'arg-info)
613 (lambda (&rest args) (funcall mf args nil))))
616 (defun error-need-at-least-n-args (function n)
617 (error "~@<The function ~2I~_~S ~I~_requires at least ~W argument~:P.~:>"
621 (defun types-from-args (generic-function arguments &optional type-modifier)
622 (multiple-value-bind (nreq applyp metatypes nkeys arg-info)
623 (get-generic-fun-info generic-function)
624 (declare (ignore applyp metatypes nkeys))
625 (let ((types-rev nil))
626 (dotimes-fixnum (i nreq)
629 (error-need-at-least-n-args (generic-function-name generic-function)
631 (let ((arg (pop arguments)))
632 (push (if type-modifier `(,type-modifier ,arg) arg) types-rev)))
633 (values (nreverse types-rev) arg-info))))
635 (defun get-wrappers-from-classes (nkeys wrappers classes metatypes)
636 (let* ((w wrappers) (w-tail w) (mt-tail metatypes))
637 (dolist (class (if (listp classes) classes (list classes)))
638 (unless (eq t (car mt-tail))
639 (let ((c-w (class-wrapper class)))
640 (unless c-w (return-from get-wrappers-from-classes nil))
643 (setf (car w-tail) c-w
644 w-tail (cdr w-tail)))))
645 (setq mt-tail (cdr mt-tail)))
648 (defun sdfun-for-caching (gf classes)
649 (let ((types (mapcar #'class-eq-type classes)))
650 (multiple-value-bind (methods all-applicable-and-sorted-p)
651 (compute-applicable-methods-using-types gf types)
652 (function-funcall (get-secondary-dispatch-function1
653 gf methods types nil t all-applicable-and-sorted-p)
654 nil (mapcar #'class-wrapper classes)))))
656 (defun value-for-caching (gf classes)
657 (let ((methods (compute-applicable-methods-using-types
658 gf (mapcar #'class-eq-type classes))))
659 (method-function-get (or (method-fast-function (car methods))
660 (method-function (car methods)))
663 (defun default-secondary-dispatch-function (generic-function)
665 (let ((methods (compute-applicable-methods generic-function args)))
667 (let ((emf (get-effective-method-function generic-function
669 (invoke-emf emf args))
670 (apply #'no-applicable-method generic-function args)))))
673 (loop (when (atom x) (return (eq x y)))
674 (when (atom y) (return nil))
675 (unless (eq (car x) (car y)) (return nil))
676 (setq x (cdr x) y (cdr y))))
678 (defvar *std-cam-methods* nil)
680 (defun compute-applicable-methods-emf (generic-function)
681 (if (eq *boot-state* 'complete)
682 (let* ((cam (gdefinition 'compute-applicable-methods))
683 (cam-methods (compute-applicable-methods-using-types
684 cam (list `(eql ,generic-function) t))))
685 (values (get-effective-method-function cam cam-methods)
687 (or *std-cam-methods*
688 (setq *std-cam-methods*
689 (compute-applicable-methods-using-types
690 cam (list `(eql ,cam) t)))))))
691 (values #'compute-applicable-methods-function t)))
693 (defun compute-applicable-methods-emf-std-p (gf)
694 (gf-info-c-a-m-emf-std-p (gf-arg-info gf)))
696 (defvar *old-c-a-m-gf-methods* nil)
698 (defun update-all-c-a-m-gf-info (c-a-m-gf)
699 (let ((methods (generic-function-methods c-a-m-gf)))
700 (if (and *old-c-a-m-gf-methods*
701 (every (lambda (old-method)
702 (member old-method methods))
703 *old-c-a-m-gf-methods*))
704 (let ((gfs-to-do nil)
705 (gf-classes-to-do nil))
706 (dolist (method methods)
707 (unless (member method *old-c-a-m-gf-methods*)
708 (let ((specl (car (method-specializers method))))
709 (if (eql-specializer-p specl)
710 (pushnew (specializer-object specl) gfs-to-do)
711 (pushnew (specializer-class specl) gf-classes-to-do)))))
712 (map-all-generic-functions
714 (when (or (member gf gfs-to-do)
715 (dolist (class gf-classes-to-do nil)
717 (class-precedence-list (class-of gf)))))
718 (update-c-a-m-gf-info gf)))))
719 (map-all-generic-functions #'update-c-a-m-gf-info))
720 (setq *old-c-a-m-gf-methods* methods)))
722 (defun update-gf-info (gf)
723 (update-c-a-m-gf-info gf)
724 (update-gf-simple-accessor-type gf))
726 (defun update-c-a-m-gf-info (gf)
727 (unless (early-gf-p gf)
728 (multiple-value-bind (c-a-m-emf std-p)
729 (compute-applicable-methods-emf gf)
730 (let ((arg-info (gf-arg-info gf)))
731 (setf (gf-info-static-c-a-m-emf arg-info) c-a-m-emf)
732 (setf (gf-info-c-a-m-emf-std-p arg-info) std-p)))))
734 (defun update-gf-simple-accessor-type (gf)
735 (let ((arg-info (gf-arg-info gf)))
736 (setf (gf-info-simple-accessor-type arg-info)
737 (let* ((methods (generic-function-methods gf))
738 (class (and methods (class-of (car methods))))
741 *the-class-standard-reader-method*)
744 *the-class-standard-writer-method*)
747 *the-class-standard-boundp-method*)
749 (when (and (gf-info-c-a-m-emf-std-p arg-info)
751 (dolist (method (cdr methods) t)
752 (unless (eq class (class-of method)) (return nil)))
753 (eq (generic-function-method-combination gf)
754 *standard-method-combination*))
758 ;;; CMUCL (Gerd's PCL, 2002-04-25) comment:
760 ;;; Return two values. First value is a function to be stored in
761 ;;; effective slot definition SLOTD for reading it with
762 ;;; SLOT-VALUE-USING-CLASS, setting it with (SETF
763 ;;; SLOT-VALUE-USING-CLASS) or testing it with
764 ;;; SLOT-BOUNDP-USING-CLASS. GF is one of these generic functions,
765 ;;; TYPE is one of the symbols READER, WRITER, BOUNDP. CLASS is
768 ;;; Second value is true if the function returned is one of the
769 ;;; optimized standard functions for the purpose, which are used
770 ;;; when only standard methods are applicable.
772 ;;; FIXME: Change all these wacky function names to something sane.
773 (defun get-accessor-method-function (gf type class slotd)
774 (let* ((std-method (standard-svuc-method type))
775 (str-method (structure-svuc-method type))
776 (types1 `((eql ,class) (class-eq ,class) (eql ,slotd)))
777 (types (if (eq type 'writer) `(t ,@types1) types1))
778 (methods (compute-applicable-methods-using-types gf types))
779 (std-p (null (cdr methods))))
782 (get-optimized-std-accessor-method-function class slotd type)
783 (let* ((optimized-std-fun
784 (get-optimized-std-slot-value-using-class-method-function
787 `((,(car (or (member std-method methods)
788 (member str-method methods)
790 'get-accessor-method-function)))
791 ,optimized-std-fun)))
793 (let ((wrappers (list (wrapper-of class)
794 (class-wrapper class)
795 (wrapper-of slotd))))
796 (if (eq type 'writer)
797 (cons (class-wrapper *the-class-t*) wrappers)
799 (sdfun (get-secondary-dispatch-function
800 gf methods types method-alist wrappers)))
801 (get-accessor-from-svuc-method-function class slotd sdfun type)))
804 ;;; used by OPTIMIZE-SLOT-VALUE-BY-CLASS-P (vector.lisp)
805 (defun update-slot-value-gf-info (gf type)
807 (update-std-or-str-methods gf type))
808 (when (and (standard-svuc-method type) (structure-svuc-method type))
809 (flet ((update-class (class)
810 (when (class-finalized-p class)
811 (dolist (slotd (class-slots class))
812 (compute-slot-accessor-info slotd type gf)))))
814 (update-class *new-class*)
815 (map-all-classes #'update-class 'slot-object)))))
817 (defvar *standard-slot-value-using-class-method* nil)
818 (defvar *standard-setf-slot-value-using-class-method* nil)
819 (defvar *standard-slot-boundp-using-class-method* nil)
820 (defvar *condition-slot-value-using-class-method* nil)
821 (defvar *condition-setf-slot-value-using-class-method* nil)
822 (defvar *condition-slot-boundp-using-class-method* nil)
823 (defvar *structure-slot-value-using-class-method* nil)
824 (defvar *structure-setf-slot-value-using-class-method* nil)
825 (defvar *structure-slot-boundp-using-class-method* nil)
827 (defun standard-svuc-method (type)
829 (reader *standard-slot-value-using-class-method*)
830 (writer *standard-setf-slot-value-using-class-method*)
831 (boundp *standard-slot-boundp-using-class-method*)))
833 (defun set-standard-svuc-method (type method)
835 (reader (setq *standard-slot-value-using-class-method* method))
836 (writer (setq *standard-setf-slot-value-using-class-method* method))
837 (boundp (setq *standard-slot-boundp-using-class-method* method))))
839 (defun condition-svuc-method (type)
841 (reader *condition-slot-value-using-class-method*)
842 (writer *condition-setf-slot-value-using-class-method*)
843 (boundp *condition-slot-boundp-using-class-method*)))
845 (defun set-condition-svuc-method (type method)
847 (reader (setq *condition-slot-value-using-class-method* method))
848 (writer (setq *condition-setf-slot-value-using-class-method* method))
849 (boundp (setq *condition-slot-boundp-using-class-method* method))))
851 (defun structure-svuc-method (type)
853 (reader *structure-slot-value-using-class-method*)
854 (writer *structure-setf-slot-value-using-class-method*)
855 (boundp *structure-slot-boundp-using-class-method*)))
857 (defun set-structure-svuc-method (type method)
859 (reader (setq *structure-slot-value-using-class-method* method))
860 (writer (setq *structure-setf-slot-value-using-class-method* method))
861 (boundp (setq *structure-slot-boundp-using-class-method* method))))
863 (defun update-std-or-str-methods (gf type)
864 (dolist (method (generic-function-methods gf))
865 (let ((specls (method-specializers method)))
866 (when (and (or (not (eq type 'writer))
867 (eq (pop specls) *the-class-t*))
868 (every #'classp specls))
869 (cond ((and (eq (class-name (car specls)) 'std-class)
870 (eq (class-name (cadr specls)) 'std-object)
871 (eq (class-name (caddr specls))
872 'standard-effective-slot-definition))
873 (set-standard-svuc-method type method))
874 ((and (eq (class-name (car specls)) 'condition-class)
875 (eq (class-name (cadr specls)) 'condition)
876 (eq (class-name (caddr specls))
877 'condition-effective-slot-definition))
878 (set-condition-svuc-method type method))
879 ((and (eq (class-name (car specls)) 'structure-class)
880 (eq (class-name (cadr specls)) 'structure-object)
881 (eq (class-name (caddr specls))
882 'structure-effective-slot-definition))
883 (set-structure-svuc-method type method)))))))
885 (defun mec-all-classes-internal (spec precompute-p)
886 (cons (specializer-class spec)
889 (not (or (eq spec *the-class-t*)
890 (eq spec *the-class-slot-object*)
891 (eq spec *the-class-std-object*)
892 (eq spec *the-class-standard-object*)
893 (eq spec *the-class-structure-object*)))
894 (let ((sc (class-direct-subclasses spec)))
896 (mapcan (lambda (class)
897 (mec-all-classes-internal class precompute-p))
900 (defun mec-all-classes (spec precompute-p)
901 (let ((classes (mec-all-classes-internal spec precompute-p)))
902 (if (null (cdr classes))
904 (let* ((a-classes (cons nil classes))
906 (loop (when (null (cdr tail))
907 (return (cdr a-classes)))
908 (let ((class (cadr tail))
910 (if (dolist (c ttail nil)
911 (when (eq class c) (return t)))
912 (setf (cdr tail) (cddr tail))
913 (setf tail (cdr tail)))))))))
915 (defun mec-all-class-lists (spec-list precompute-p)
918 (let* ((car-all-classes (mec-all-classes (car spec-list)
920 (all-class-lists (mec-all-class-lists (cdr spec-list)
922 (mapcan (lambda (list)
923 (mapcar (lambda (c) (cons c list)) car-all-classes))
926 (defun make-emf-cache (generic-function valuep cache classes-list new-class)
927 (let* ((arg-info (gf-arg-info generic-function))
928 (nkeys (arg-info-nkeys arg-info))
929 (metatypes (arg-info-metatypes arg-info))
930 (wrappers (unless (eq nkeys 1) (make-list nkeys)))
931 (precompute-p (gf-precompute-dfun-and-emf-p arg-info))
932 (default '(default)))
933 (flet ((add-class-list (classes)
934 (when (or (null new-class) (memq new-class classes))
935 (let ((wrappers (get-wrappers-from-classes
936 nkeys wrappers classes metatypes)))
938 (eq default (probe-cache cache wrappers default)))
939 (let ((value (cond ((eq valuep t)
940 (sdfun-for-caching generic-function
942 ((eq valuep :constant-value)
943 (value-for-caching generic-function
945 (setq cache (fill-cache cache wrappers value))))))))
947 (mapc #'add-class-list classes-list)
948 (dolist (method (generic-function-methods generic-function))
949 (mapc #'add-class-list
950 (mec-all-class-lists (method-specializers method)
954 (defmacro class-test (arg class)
955 (cond ((eq class *the-class-t*)
957 ((eq class *the-class-slot-object*)
958 `(not (typep (classoid-of ,arg)
959 'built-in-classoid)))
960 ((eq class *the-class-std-object*)
961 `(or (std-instance-p ,arg) (fsc-instance-p ,arg)))
962 ((eq class *the-class-standard-object*)
963 `(std-instance-p ,arg))
964 ((eq class *the-class-funcallable-standard-object*)
965 `(fsc-instance-p ,arg))
967 `(typep ,arg ',(class-name class)))))
969 (defmacro class-eq-test (arg class)
970 `(eq (class-of ,arg) ',class))
972 (defmacro eql-test (arg object)
973 `(eql ,arg ',object))
975 (defun dnet-methods-p (form)
977 (or (eq (car form) 'methods)
978 (eq (car form) 'unordered-methods))))
980 ;;; This is CASE, but without gensyms.
981 (defmacro scase (arg &rest clauses)
982 `(let ((.case-arg. ,arg))
983 (cond ,@(mapcar (lambda (clause)
984 (list* (cond ((null (car clause))
986 ((consp (car clause))
987 (if (null (cdar clause))
992 ((member (car clause) '(t otherwise))
995 `(eql .case-arg. ',(car clause))))
1000 (defmacro mcase (arg &rest clauses) `(scase ,arg ,@clauses))
1002 (defun generate-discrimination-net (generic-function methods types sorted-p)
1003 (let* ((arg-info (gf-arg-info generic-function))
1004 (precedence (arg-info-precedence arg-info)))
1005 (generate-discrimination-net-internal
1006 generic-function methods types
1007 (lambda (methods known-types)
1010 (let ((sorted-methods nil))
1012 (copy-list methods) precedence
1014 (when sorted-methods (return-from one-order-p nil))
1015 (setq sorted-methods methods)))
1016 (setq methods sorted-methods))
1018 `(methods ,methods ,known-types)
1019 `(unordered-methods ,methods ,known-types)))
1020 (lambda (position type true-value false-value)
1021 (let ((arg (dfun-arg-symbol position)))
1022 (if (eq (car type) 'eql)
1023 (let* ((false-case-p (and (consp false-value)
1024 (or (eq (car false-value) 'scase)
1025 (eq (car false-value) 'mcase))
1026 (eq arg (cadr false-value))))
1027 (false-clauses (if false-case-p
1029 `((t ,false-value))))
1030 (case-sym (if (and (dnet-methods-p true-value)
1032 (eq (car false-value) 'mcase)
1033 (dnet-methods-p false-value)))
1036 (type-sym `(,(cadr type))))
1038 (,type-sym ,true-value)
1040 `(if ,(let ((arg (dfun-arg-symbol position)))
1042 (class `(class-test ,arg ,(cadr type)))
1043 (class-eq `(class-eq-test ,arg ,(cadr type)))))
1048 (defun class-from-type (type)
1049 (if (or (atom type) (eq (car type) t))
1052 (and (dolist (type (cdr type) *the-class-t*)
1053 (when (and (consp type) (not (eq (car type) 'not)))
1054 (return (class-from-type type)))))
1056 (eql (class-of (cadr type)))
1057 (class-eq (cadr type))
1058 (class (cadr type)))))
1060 (defun precompute-effective-methods (gf caching-p &optional classes-list-p)
1061 (let* ((arg-info (gf-arg-info gf))
1062 (methods (generic-function-methods gf))
1063 (precedence (arg-info-precedence arg-info))
1064 (*in-precompute-effective-methods-p* t)
1066 (generate-discrimination-net-internal
1068 (lambda (methods known-types)
1070 (when classes-list-p
1071 (push (mapcar #'class-from-type known-types) classes-list))
1072 (let ((no-eql-specls-p (not (methods-contain-eql-specializer-p
1077 (get-secondary-dispatch-function1
1078 gf methods known-types
1079 nil caching-p no-eql-specls-p))))))
1080 (lambda (position type true-value false-value)
1081 (declare (ignore position type true-value false-value))
1084 (if (and (consp type) (eq (car type) 'eql))
1085 `(class-eq ,(class-of (cadr type)))
1089 ;;; We know that known-type implies neither new-type nor `(not ,new-type).
1090 (defun augment-type (new-type known-type)
1091 (if (or (eq known-type t)
1092 (eq (car new-type) 'eql))
1094 (let ((so-far (if (and (consp known-type) (eq (car known-type) 'and))
1096 (list known-type))))
1097 (unless (eq (car new-type) 'not)
1099 (mapcan (lambda (type)
1100 (unless (*subtypep new-type type)
1105 `(and ,new-type ,@so-far)))))
1107 (defun generate-discrimination-net-internal
1108 (gf methods types methods-function test-fun type-function)
1109 (let* ((arg-info (gf-arg-info gf))
1110 (precedence (arg-info-precedence arg-info))
1111 (nreq (arg-info-number-required arg-info))
1112 (metatypes (arg-info-metatypes arg-info)))
1113 (labels ((do-column (p-tail contenders known-types)
1115 (let* ((position (car p-tail))
1116 (known-type (or (nth position types) t)))
1117 (if (eq (nth position metatypes) t)
1118 (do-column (cdr p-tail) contenders
1119 (cons (cons position known-type)
1121 (do-methods p-tail contenders
1122 known-type () known-types)))
1123 (funcall methods-function contenders
1124 (let ((k-t (make-list nreq)))
1125 (dolist (index+type known-types)
1126 (setf (nth (car index+type) k-t)
1129 (do-methods (p-tail contenders known-type winners known-types)
1131 ;; is a (sorted) list of methods that must be discriminated.
1133 ;; is the type of this argument, constructed from tests
1136 ;; is a (sorted) list of methods that are potentially
1137 ;; applicable after the discrimination has been made.
1138 (if (null contenders)
1139 (do-column (cdr p-tail)
1141 (cons (cons (car p-tail) known-type)
1143 (let* ((position (car p-tail))
1144 (method (car contenders))
1145 (specl (nth position (method-specializers method)))
1146 (type (funcall type-function
1147 (type-from-specializer specl))))
1148 (multiple-value-bind (app-p maybe-app-p)
1149 (specializer-applicable-using-type-p type known-type)
1150 (flet ((determined-to-be (truth-value)
1151 (if truth-value app-p (not maybe-app-p)))
1152 (do-if (truth &optional implied)
1153 (let ((ntype (if truth type `(not ,type))))
1158 (augment-type ntype known-type))
1160 (append winners `(,method))
1163 (cond ((determined-to-be nil) (do-if nil t))
1164 ((determined-to-be t) (do-if t t))
1165 (t (funcall test-fun position type
1166 (do-if t) (do-if nil))))))))))
1167 (do-column precedence methods ()))))
1169 (defun compute-secondary-dispatch-function (generic-function net &optional
1170 method-alist wrappers)
1171 (function-funcall (compute-secondary-dispatch-function1 generic-function net)
1172 method-alist wrappers))
1174 (defvar *eq-case-table-limit* 15)
1175 (defvar *case-table-limit* 10)
1177 (defun compute-mcase-parameters (case-list)
1178 (unless (eq t (caar (last case-list)))
1179 (error "The key for the last case arg to mcase was not T"))
1180 (let* ((eq-p (dolist (case case-list t)
1181 (unless (or (eq (car case) t)
1182 (symbolp (caar case)))
1184 (len (1- (length case-list)))
1185 (type (cond ((= len 1)
1189 *eq-case-table-limit*
1190 *case-table-limit*))
1196 (defmacro mlookup (key info default &optional eq-p type)
1197 (unless (or (eq eq-p t) (null eq-p))
1198 (bug "Invalid eq-p argument: ~S" eq-p))
1202 (declare (optimize (inhibit-warnings 3)))
1203 (,(if eq-p 'eq 'eql) ,key (car ,info)))
1207 `(dolist (e ,info ,default)
1209 (declare (optimize (inhibit-warnings 3)))
1210 (,(if eq-p 'eq 'eql) (car e) ,key))
1213 `(gethash ,key ,info ,default))))
1215 (defun net-test-converter (form)
1217 (default-test-converter form)
1219 ((invoke-effective-method-function invoke-fast-method-call)
1226 `(mlookup ,(cadr form)
1229 ,@(compute-mcase-parameters (cddr form))))
1230 (t (default-test-converter form)))))
1232 (defun net-code-converter (form)
1234 (default-code-converter form)
1236 ((methods unordered-methods)
1237 (let ((gensym (gensym)))
1241 (let ((mp (compute-mcase-parameters (cddr form)))
1242 (gensym (gensym)) (default (gensym)))
1243 (values `(mlookup ,(cadr form) ,gensym ,default ,@mp)
1244 (list gensym default))))
1246 (default-code-converter form)))))
1248 (defun net-constant-converter (form generic-function)
1249 (or (let ((c (methods-converter form generic-function)))
1252 (default-constant-converter form)
1255 (let* ((mp (compute-mcase-parameters (cddr form)))
1256 (list (mapcar (lambda (clause)
1257 (let ((key (car clause))
1258 (meth (cadr clause)))
1259 (cons (if (consp key) (car key) key)
1261 meth generic-function))))
1263 (default (car (last list))))
1264 (list (list* :mcase mp (nbutlast list))
1267 (default-constant-converter form))))))
1269 (defun methods-converter (form generic-function)
1270 (cond ((and (consp form) (eq (car form) 'methods))
1272 (get-effective-method-function1 generic-function (cadr form))))
1273 ((and (consp form) (eq (car form) 'unordered-methods))
1274 (default-secondary-dispatch-function generic-function))))
1276 (defun convert-methods (constant method-alist wrappers)
1277 (if (and (consp constant)
1278 (eq (car constant) '.methods.))
1279 (funcall (cdr constant) method-alist wrappers)
1282 (defun convert-table (constant method-alist wrappers)
1283 (cond ((and (consp constant)
1284 (eq (car constant) :mcase))
1285 (let ((alist (mapcar (lambda (k+m)
1287 (convert-methods (cdr k+m)
1291 (mp (cadr constant)))
1298 (let ((table (make-hash-table :test (if (car mp) 'eq 'eql))))
1300 (setf (gethash (car k+m) table) (cdr k+m)))
1303 (defun compute-secondary-dispatch-function1 (generic-function net
1304 &optional function-p)
1306 ((and (eq (car net) 'methods) (not function-p))
1307 (get-effective-method-function1 generic-function (cadr net)))
1309 (let* ((name (generic-function-name generic-function))
1310 (arg-info (gf-arg-info generic-function))
1311 (metatypes (arg-info-metatypes arg-info))
1312 (applyp (arg-info-applyp arg-info))
1313 (fmc-arg-info (cons (length metatypes) applyp))
1314 (arglist (if function-p
1315 (make-dfun-lambda-list metatypes applyp)
1316 (make-fast-method-call-lambda-list metatypes applyp))))
1317 (multiple-value-bind (cfunction constants)
1318 (get-fun1 `(,(if function-p
1322 ,@(unless function-p
1323 `((declare (ignore .pv-cell.
1324 .next-method-call.))))
1325 (locally (declare #.*optimize-speed*)
1327 ,(make-emf-call metatypes applyp 'emf))))
1328 #'net-test-converter
1329 #'net-code-converter
1331 (net-constant-converter form generic-function)))
1332 (lambda (method-alist wrappers)
1333 (let* ((alist (list nil))
1335 (dolist (constant constants)
1336 (let* ((a (or (dolist (a alist nil)
1337 (when (eq (car a) constant)
1341 constant method-alist wrappers)
1343 constant method-alist wrappers)))))
1345 (setf (cdr alist-tail) new)
1346 (setf alist-tail new)))
1347 (let ((function (apply cfunction (mapcar #'cdr (cdr alist)))))
1350 (make-fast-method-call
1351 :function (set-fun-name function `(sdfun-method ,name))
1352 :arg-info fmc-arg-info))))))))))
1354 (defvar *show-make-unordered-methods-emf-calls* nil)
1356 (defun make-unordered-methods-emf (generic-function methods)
1357 (when *show-make-unordered-methods-emf-calls*
1358 (format t "~&make-unordered-methods-emf ~S~%"
1359 (generic-function-name generic-function)))
1360 (lambda (&rest args)
1361 (let* ((types (types-from-args generic-function args 'eql))
1362 (smethods (sort-applicable-methods generic-function
1365 (emf (get-effective-method-function generic-function smethods)))
1366 (invoke-emf emf args))))
1368 ;;; The value returned by compute-discriminating-function is a function
1369 ;;; object. It is called a discriminating function because it is called
1370 ;;; when the generic function is called and its role is to discriminate
1371 ;;; on the arguments to the generic function and then call appropriate
1372 ;;; method functions.
1374 ;;; A discriminating function can only be called when it is installed as
1375 ;;; the funcallable instance function of the generic function for which
1376 ;;; it was computed.
1378 ;;; More precisely, if compute-discriminating-function is called with
1379 ;;; an argument <gf1>, and returns a result <df1>, that result must
1380 ;;; not be passed to apply or funcall directly. Rather, <df1> must be
1381 ;;; stored as the funcallable instance function of the same generic
1382 ;;; function <gf1> (using SET-FUNCALLABLE-INSTANCE-FUNCTION). Then the
1383 ;;; generic function can be passed to funcall or apply.
1385 ;;; An important exception is that methods on this generic function are
1386 ;;; permitted to return a function which itself ends up calling the value
1387 ;;; returned by a more specific method. This kind of `encapsulation' of
1388 ;;; discriminating function is critical to many uses of the MOP.
1390 ;;; As an example, the following canonical case is legal:
1392 ;;; (defmethod compute-discriminating-function ((gf my-generic-function))
1393 ;;; (let ((std (call-next-method)))
1395 ;;; (print (list 'call-to-gf gf arg))
1396 ;;; (funcall std arg))))
1398 ;;; Because many discriminating functions would like to use a dynamic
1399 ;;; strategy in which the precise discriminating function changes with
1400 ;;; time it is important to specify how a discriminating function is
1401 ;;; permitted itself to change the funcallable instance function of the
1402 ;;; generic function.
1404 ;;; Discriminating functions may set the funcallable instance function
1405 ;;; of the generic function, but the new value must be generated by making
1406 ;;; a call to COMPUTE-DISCRIMINATING-FUNCTION. This is to ensure that any
1407 ;;; more specific methods which may have encapsulated the discriminating
1408 ;;; function will get a chance to encapsulate the new, inner discriminating
1411 ;;; This implies that if a discriminating function wants to modify itself
1412 ;;; it should first store some information in the generic function proper,
1413 ;;; and then call compute-discriminating-function. The appropriate method
1414 ;;; on compute-discriminating-function will see the information stored in
1415 ;;; the generic function and generate a discriminating function accordingly.
1417 ;;; The following is an example of a discriminating function which modifies
1418 ;;; itself in accordance with this protocol:
1420 ;;; (defmethod compute-discriminating-function ((gf my-generic-function))
1422 ;;; (cond (<some condition>
1423 ;;; <store some info in the generic function>
1424 ;;; (set-funcallable-instance-function
1426 ;;; (compute-discriminating-function gf))
1427 ;;; (funcall gf arg))
1429 ;;; <call-a-method-of-gf>))))
1431 ;;; Whereas this code would not be legal:
1433 ;;; (defmethod compute-discriminating-function ((gf my-generic-function))
1435 ;;; (cond (<some condition>
1436 ;;; (set-funcallable-instance-function
1438 ;;; (lambda (a) ..))
1439 ;;; (funcall gf arg))
1441 ;;; <call-a-method-of-gf>))))
1443 ;;; NOTE: All the examples above assume that all instances of the class
1444 ;;; my-generic-function accept only one argument.
1446 (defun slot-value-using-class-dfun (class object slotd)
1447 (declare (ignore class))
1448 (function-funcall (slot-definition-reader-function slotd) object))
1450 (defun setf-slot-value-using-class-dfun (new-value class object slotd)
1451 (declare (ignore class))
1452 (function-funcall (slot-definition-writer-function slotd) new-value object))
1454 (defun slot-boundp-using-class-dfun (class object slotd)
1455 (declare (ignore class))
1456 (function-funcall (slot-definition-boundp-function slotd) object))
1458 (defmethod compute-discriminating-function ((gf standard-generic-function))
1459 (with-slots (dfun-state arg-info) gf
1460 (typecase dfun-state
1461 (null (let ((name (generic-function-name gf)))
1462 (when (eq name 'compute-applicable-methods)
1463 (update-all-c-a-m-gf-info gf))
1464 (cond ((eq name 'slot-value-using-class)
1465 (update-slot-value-gf-info gf 'reader)
1466 #'slot-value-using-class-dfun)
1467 ((equal name '(setf slot-value-using-class))
1468 (update-slot-value-gf-info gf 'writer)
1469 #'setf-slot-value-using-class-dfun)
1470 ((eq name 'slot-boundp-using-class)
1471 (update-slot-value-gf-info gf 'boundp)
1472 #'slot-boundp-using-class-dfun)
1473 ((gf-precompute-dfun-and-emf-p arg-info)
1474 (make-final-dfun gf))
1476 (make-initial-dfun gf)))))
1477 (function dfun-state)
1478 (cons (car dfun-state)))))
1480 (defmethod update-gf-dfun ((class std-class) gf)
1481 (let ((*new-class* class)
1482 #|| (name (generic-function-name gf)) ||#
1483 (arg-info (gf-arg-info gf)))
1485 ((eq name 'slot-value-using-class)
1486 (update-slot-value-gf-info gf 'reader))
1487 ((equal name '(setf slot-value-using-class))
1488 (update-slot-value-gf-info gf 'writer))
1489 ((eq name 'slot-boundp-using-class)
1490 (update-slot-value-gf-info gf 'boundp))
1492 ((gf-precompute-dfun-and-emf-p arg-info)
1493 (multiple-value-bind (dfun cache info)
1494 (make-final-dfun-internal gf)
1495 (set-dfun gf dfun cache info) ; lest the cache be freed twice
1496 (update-dfun gf dfun cache info))))))
1498 (defmethod function-keywords ((method standard-method))
1499 (multiple-value-bind (nreq nopt keysp restp allow-other-keys-p keywords)
1500 (analyze-lambda-list (if (consp method)
1501 (early-method-lambda-list method)
1502 (method-lambda-list method)))
1503 (declare (ignore nreq nopt keysp restp))
1504 (values keywords allow-other-keys-p)))
1506 (defun method-ll->generic-function-ll (ll)
1507 (multiple-value-bind
1508 (nreq nopt keysp restp allow-other-keys-p keywords keyword-parameters)
1509 (analyze-lambda-list ll)
1510 (declare (ignore nreq nopt keysp restp allow-other-keys-p keywords))
1511 (remove-if (lambda (s)
1512 (or (memq s keyword-parameters)
1513 (eq s '&allow-other-keys)))
1516 ;;; This is based on the rules of method lambda list congruency defined in
1517 ;;; the spec. The lambda list it constructs is the pretty union of the
1518 ;;; lambda lists of all the methods. It doesn't take method applicability
1519 ;;; into account at all yet.
1520 (defmethod generic-function-pretty-arglist
1521 ((generic-function standard-generic-function))
1522 (let ((methods (generic-function-methods generic-function)))
1525 ;; arglist is constructed from the GF's methods - maybe with
1526 ;; keys and rest stuff added
1527 (multiple-value-bind (required optional rest key allow-other-keys)
1528 (method-pretty-arglist (car methods))
1529 (dolist (m (cdr methods))
1530 (multiple-value-bind (method-key-keywords
1531 method-allow-other-keys
1533 (function-keywords m)
1534 ;; we've modified function-keywords to return what we want as
1535 ;; the third value, no other change here.
1536 (declare (ignore method-key-keywords))
1537 (setq key (union key method-key))
1538 (setq allow-other-keys (or allow-other-keys
1539 method-allow-other-keys))))
1540 (when allow-other-keys
1541 (setq arglist '(&allow-other-keys)))
1543 (setq arglist (nconc (list '&key) key arglist)))
1545 (setq arglist (nconc (list '&rest rest) arglist)))
1547 (setq arglist (nconc (list '&optional) optional arglist)))
1548 (nconc required arglist)))
1549 ;; otherwise we take the lambda-list from the GF directly, with no
1550 ;; other 'keys' added ...
1551 (let ((lambda-list (generic-function-lambda-list generic-function)))
1554 (defmethod method-pretty-arglist ((method standard-method))
1559 (allow-other-keys nil)
1561 (arglist (method-lambda-list method)))
1562 (dolist (arg arglist)
1563 (cond ((eq arg '&optional) (setq state 'optional))
1564 ((eq arg '&rest) (setq state 'rest))
1565 ((eq arg '&key) (setq state 'key))
1566 ((eq arg '&allow-other-keys) (setq allow-other-keys t))
1567 ((memq arg lambda-list-keywords))
1570 (required (push arg required))
1571 (optional (push arg optional))
1572 (key (push arg key))
1573 (rest (setq rest arg))))))
1574 (values (nreverse required)