1.0.43.27: DESCRIBE optimization policy qualities for symbols
[sbcl.git] / src / code / describe.lisp
1 ;;;; the DESCRIBE system
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 the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
11
12 ;;; SB-IMPL, not SB!IMPL, since we're built in warm load.
13 (in-package "SB-IMPL")
14
15 ;;;; Utils, move elsewhere.
16
17 (defun class-name-or-class (class)
18   (let ((name (class-name class)))
19     (if (eq class (find-class name nil))
20         name
21         class)))
22
23 (defun fun-name (x)
24   (if (typep x 'generic-function)
25       (sb-pcl:generic-function-name x)
26       (%fun-name x)))
27
28 ;;; Prints X on a single line, limiting output length by *PRINT-RIGHT-MARGIN*
29 ;;; -- good for printing object parts, etc.
30 (defun prin1-to-line (x &key (columns 1) (reserve 0))
31   (let* ((line (write-to-string x :escape t :readably nil :lines 2 :circle t))
32          (p (position #\newline line))
33          (limit (truncate (- *print-right-margin* reserve) columns)))
34     (flet ((trunc (&optional end)
35              (let ((line-end (- limit 2)))
36                (with-output-to-string (s)
37                  (write-string line s :end (if end
38                                                (min end line-end)
39                                                line-end))
40                  (write-string ".." s)))))
41       (cond (p
42              (trunc p))
43             ((> (length line) limit)
44              (trunc))
45             (t
46              line)))))
47
48 (defun describe (object &optional (stream-designator *standard-output*))
49   #+sb-doc
50   "Print a description of OBJECT to STREAM-DESIGNATOR."
51   (let ((stream (out-synonym-of stream-designator))
52         (*print-right-margin* (or *print-right-margin* 72)))
53     ;; Until sbcl-0.8.0.x, we did
54     ;;   (FRESH-LINE STREAM)
55     ;;   (PPRINT-LOGICAL-BLOCK (STREAM NIL)
56     ;;     ...
57     ;; here. However, ANSI's specification of DEFUN DESCRIBE,
58     ;;   DESCRIBE exists as an interface primarily to manage argument
59     ;;   defaulting (including conversion of arguments T and NIL into
60     ;;   stream objects) and to inhibit any return values from
61     ;;   DESCRIBE-OBJECT.
62     ;; doesn't mention either FRESH-LINEing or PPRINT-LOGICAL-BLOCKing,
63     ;; and the example of typical DESCRIBE-OBJECT behavior in ANSI's
64     ;; specification of DESCRIBE-OBJECT will work poorly if we do them
65     ;; here. (The example method for DESCRIBE-OBJECT does its own
66     ;; FRESH-LINEing, which is a physical directive which works poorly
67     ;; inside a pretty-printer logical block.)
68     (describe-object object stream)
69     ;; We don't TERPRI here either (any more since sbcl-0.8.0.x), because
70     ;; again ANSI's specification of DESCRIBE doesn't mention it and
71     ;; ANSI's example of DESCRIBE-OBJECT does its own final TERPRI.
72     (values)))
73 \f
74 ;;;; DESCRIBE-OBJECT
75 ;;;;
76 ;;;; Style guide:
77 ;;;;
78 ;;;; * Each interesting class has a primary method of its own.
79 ;;;;
80 ;;;; * Output looks like
81 ;;;;
82 ;;;;    object-self-string
83 ;;;;      [object-type-string]
84 ;;;;
85 ;;;;    Block1:
86 ;;;;      Sublabel1: text
87 ;;;;      Sublabel2: text
88 ;;;;
89 ;;;;    Block2:
90 ;;;;      ...
91 ;;;;
92 ;;;; * The newline policy that gets the whitespace right is for
93 ;;;;   each block to both start and end with a newline.
94
95 (defgeneric object-self-string (x))
96
97 (defmethod object-self-string (x)
98   (prin1-to-line x))
99
100 (defmethod object-self-string ((x symbol))
101   (let ((*package* (find-package :keyword)))
102     (prin1-to-string x)))
103
104 (defgeneric object-type-string (x))
105
106 (defmethod object-type-string (x)
107   (let ((type (class-name-or-class (class-of x))))
108     (if (symbolp type)
109         (string-downcase type)
110         (prin1-to-string type))))
111
112 (defmethod object-type-string ((x cons))
113   (if (listp (cdr x)) "list" "cons"))
114
115 (defmethod object-type-string ((x hash-table))
116   "hash-table")
117
118 (defmethod object-type-string ((x condition))
119   "condition")
120
121 (defmethod object-type-string ((x structure-object))
122   "structure-object")
123
124 (defmethod object-type-string ((x standard-object))
125   "standard-object")
126
127 (defmethod object-type-string ((x function))
128   (typecase x
129     (simple-fun "compiled function")
130     (closure "compiled closure")
131     #+sb-eval
132     (sb-eval:interpreted-function
133      "interpreted function")
134     (generic-function
135      "generic-function")
136     (t
137      "funcallable-instance")))
138
139 (defmethod object-type-string ((x stream))
140   "stream")
141
142 (defmethod object-type-string ((x sb-gray:fundamental-stream))
143   "gray stream")
144
145 (defmethod object-type-string ((x package))
146   "package")
147
148 (defmethod object-type-string ((x array))
149   (cond ((or (stringp x) (bit-vector-p x))
150          (format nil "~@[simple-~*~]~A"
151                  (typep x 'simple-array)
152                  (typecase x
153                    (base-string "base-string")
154                    (string "string")
155                    (t "bit-vector"))))
156         (t
157          (if (simple-vector-p x)
158              "simple-vector"
159              (format nil "~@[simple ~*~]~@[specialized ~*~]~:[array~;vector~]"
160                      (typep x 'simple-array)
161                      (neq t (array-element-type x))
162                      (vectorp x))))))
163
164 (defmethod object-type-string ((x character))
165   (typecase x
166     (standard-char "standard-char")
167     (base-char "base-char")
168     (t "character")))
169
170 (defun print-standard-describe-header (x stream)
171   (format stream "~&~A~%  [~A]~%"
172           (object-self-string x)
173           (object-type-string x)))
174
175 (defgeneric describe-object (x stream))
176
177 ;;; Catch-all.
178
179 (defmethod describe-object ((x t) s)
180   (print-standard-describe-header x s))
181
182 (defmethod describe-object ((x cons) s)
183   (print-standard-describe-header x s)
184   (describe-function x nil s))
185
186 (defmethod describe-object ((x function) s)
187   (print-standard-describe-header x s)
188   (describe-function nil x s))
189
190 (defmethod describe-object ((x class) s)
191   (print-standard-describe-header x s)
192   (describe-class nil x s)
193   (describe-instance x s))
194
195 (defmethod describe-object ((x sb-pcl::slot-object) s)
196   (print-standard-describe-header x s)
197   (describe-instance x s))
198
199 (defmethod describe-object ((x character) s)
200   (print-standard-describe-header x s)
201   (format s "~%:_Char-code: ~S" (char-code x))
202   (format s "~%:_Char-name: ~A~%_" (char-name x)))
203
204 (defmethod describe-object ((x array) s)
205   (print-standard-describe-header x s)
206   (format s "~%Element-type: ~S" (array-element-type x))
207   (if (vectorp x)
208       (if (array-has-fill-pointer-p x)
209           (format s "~%Fill-pointer: ~S~%Size: ~S"
210                   (fill-pointer x)
211                   (array-total-size x))
212           (format s "~%Length: ~S" (length x)))
213       (format s "~%Dimensions: ~S" (array-dimensions x)))
214   (let ((*print-array* nil))
215     (unless (typep x 'simple-array)
216       (format s "~%Adjustable: ~A" (if (adjustable-array-p x) "yes" "no"))
217       (multiple-value-bind (to offset) (array-displacement x)
218         (if (format s "~%Displaced-to: ~A~%Displaced-offset: ~S"
219                     (prin1-to-line to)
220                     offset)
221             (format s "~%Displaced: no"))))
222     (when (and (not (array-displacement x)) (array-header-p x))
223       (format s "~%Storage vector: ~A"
224               (prin1-to-line (array-storage-vector x))))
225     (terpri s)))
226
227 (defmethod describe-object ((x hash-table) s)
228   (print-standard-describe-header x s)
229   ;; Don't print things which are already apparent from the printed
230   ;; representation -- COUNT, TEST, and WEAKNESS
231   (format s "~%Occupancy: ~,1F" (float (/ (hash-table-count x)
232                                           (hash-table-size x))))
233   (format s "~%Rehash-threshold: ~S" (hash-table-rehash-threshold x))
234   (format s "~%Rehash-size: ~S" (hash-table-rehash-size x))
235   (format s "~%Size: ~S" (hash-table-size x))
236   (format s "~%Synchronized: ~A" (if (hash-table-synchronized-p x) "yes" "no"))
237   (terpri s))
238
239 (defmethod describe-object ((symbol symbol) stream)
240   (print-standard-describe-header symbol stream)
241   ;; Describe the value cell.
242   (let* ((kind (info :variable :kind symbol))
243          (wot (ecase kind
244                 (:special "a special variable")
245                 (:macro "a symbol macro")
246                 (:constant "a constant variable")
247                 (:global "a global variable")
248                 (:unknown "an undefined variable")
249                 (:alien "an alien variable"))))
250     (when (or (not (eq :unknown kind)) (boundp symbol))
251       (pprint-logical-block (stream nil)
252         (format stream "~%~A names ~A:" symbol wot)
253         (pprint-indent :block 2 stream)
254         (when (eq (info :variable :where-from symbol) :declared)
255           (format stream "~@:_Declared type: ~S"
256                   (type-specifier (info :variable :type symbol))))
257         (cond
258           ((eq kind :alien)
259            (let ((info (info :variable :alien-info symbol)))
260              (format stream "~@:_Value: ~S" (eval symbol))
261              (format stream "~@:_Type: ~S"
262                      (sb-alien-internals:unparse-alien-type
263                       (sb-alien::heap-alien-info-type info)))
264              (format stream "~@:_Address: #x~8,'0X"
265                      (sap-int (eval (sb-alien::heap-alien-info-sap-form info))))))
266           ((eq kind :macro)
267            (let ((expansion (info :variable :macro-expansion symbol)))
268              (format stream "~@:_Expansion: ~S" expansion)))
269           ((boundp symbol)
270            (format stream "~:@_Value: ~S" (symbol-value symbol)))
271           ((not (eq kind :unknown))
272            (format stream "~:@_Currently unbound.")))
273         (describe-documentation symbol 'variable stream)
274         (terpri stream))))
275
276   ;; TODO: We could grovel over all packages looking for and
277   ;; reporting other phenomena, e.g. IMPORT and SHADOW, or
278   ;; availability in some package even after (SYMBOL-PACKAGE SYMBOL) has
279   ;; been set to NIL.
280   ;;
281   ;; TODO: It might also be nice to describe (find-package symbol)
282   ;; if one exists. Maybe not all the exports, etc, but the package
283   ;; documentation.
284   (describe-function symbol nil stream)
285   (describe-class symbol nil stream)
286
287   ;; Type specifier
288   (let* ((kind (info :type :kind symbol))
289          (fun (case kind
290                 (:defined
291                  (or (info :type :expander symbol) t))
292                 (:primitive
293                  (or (info :type :translator symbol) t)))))
294     (when fun
295       (pprint-newline :mandatory stream)
296       (pprint-logical-block (stream nil)
297         (pprint-indent :block 2 stream)
298         (format stream "~A names a ~@[primitive~* ~]type-specifier:"
299                 symbol
300                 (eq kind :primitive))
301         (describe-documentation symbol 'type stream (eq t fun))
302         (unless (eq t fun)
303           (describe-lambda-list (if (eq :primitive kind)
304                                     (%fun-lambda-list fun)
305                                     (info :type :lambda-list symbol))
306                                 stream)
307           (when (eq (%fun-fun fun) (%fun-fun (constant-type-expander t)))
308             (format stream "~@:_Expansion: ~S" (funcall fun (list symbol))))))
309       (terpri stream)))
310
311   (when (or (member symbol sb-c::*policy-qualities*)
312             (assoc symbol sb-c::*policy-dependent-qualities*))
313     (pprint-logical-block (stream nil)
314       (pprint-newline :mandatory stream)
315       (pprint-indent :block 2 stream)
316       (format stream "~A names a~:[ dependent~;n~] optimization policy quality:"
317               symbol
318               (member symbol sb-c::*policy-qualities*))
319       (describe-documentation symbol 'optimize stream t))
320     (terpri stream))
321
322   ;; Print out properties.
323   (let ((plist (symbol-plist symbol)))
324     (when plist
325       (pprint-logical-block (stream nil)
326         (format stream "~%Symbol-plist:")
327         (pprint-indent :block 2 stream)
328         (sb-pcl::doplist (key value) plist
329           (format stream "~@:_~A -> ~A"
330                   (prin1-to-line key :columns 2 :reserve 5)
331                   (prin1-to-line value :columns 2 :reserve 5))))
332       (terpri stream))))
333
334 (defmethod describe-object ((package package) stream)
335   (print-standard-describe-header package stream)
336   (pprint-logical-block (stream nil)
337     (describe-documentation package t stream)
338     (flet ((humanize (list)
339              (sort (mapcar (lambda (x)
340                              (if (packagep x)
341                                  (package-name x)
342                                  x))
343                            list)
344                    #'string<))
345            (out (label list)
346              (describe-stuff label list stream :escape nil)))
347       (let ((implemented (humanize (package-implemented-by-list package)))
348             (implements (humanize (package-implements-list package)))
349             (nicks (humanize (package-nicknames package)))
350             (uses (humanize (package-use-list package)))
351             (used (humanize (package-used-by-list package)))
352             (shadows (humanize (package-shadowing-symbols package)))
353             (this (list (package-name package)))
354             (exports nil))
355         (do-external-symbols (ext package)
356           (push ext exports))
357         (setf exports (humanize exports))
358         (when (package-locked-p package)
359           (format stream "~@:_Locked."))
360         (when (set-difference implemented this :test #'string=)
361           (out "Implemented-by-list" implemented))
362         (when (set-difference implements this :test #'string=)
363           (out "Implements-list" implements))
364         (out "Nicknames" nicks)
365         (out "Use-list" uses)
366         (out "Used-by-list" used)
367         (out "Shadows" shadows)
368         (out "Exports" exports)
369         (format stream "~@:_~S internal symbols."
370                 (package-internal-symbol-count package))))
371     (terpri stream)))
372 \f
373 ;;;; Helpers to deal with shared functionality
374
375 (defun describe-class (name class stream)
376   (let* ((by-name (not class))
377          (name (if class (class-name class) name))
378          (class (if class class (find-class name nil))))
379     (when class
380       (let ((metaclass-name (class-name (class-of class))))
381         (pprint-logical-block (stream nil)
382           (when by-name
383             (format stream "~%~A names the ~(~A~) ~S:"
384                     name
385                     metaclass-name
386                     class)
387             (pprint-indent :block 2 stream))
388           (describe-documentation class t stream)
389           (when (sb-mop:class-finalized-p class)
390             (describe-stuff "Class precedence-list"
391                             (mapcar #'class-name-or-class (sb-mop:class-precedence-list class))
392                             stream))
393           (describe-stuff "Direct superclasses"
394                           (mapcar #'class-name-or-class (sb-mop:class-direct-superclasses class))
395                           stream)
396           (let ((subs (mapcar #'class-name-or-class (sb-mop:class-direct-subclasses class))))
397             (if subs
398                 (describe-stuff "Direct subclasses" subs stream)
399                 (format stream "~@:_No subclasses.")))
400           (unless (sb-mop:class-finalized-p class)
401             (format stream "~@:_Not yet finalized."))
402           (if (eq 'structure-class metaclass-name)
403               (let* ((dd (find-defstruct-description name))
404                      (slots (dd-slots dd)))
405                 (if slots
406                     (format stream "~@:_Slots:~:{~@:_  ~S~
407                                     ~@:_    Type: ~A ~@[~A~]~
408                                     ~@:_    Initform: ~S~}"
409                             (mapcar (lambda (dsd)
410                                       (list
411                                        (dsd-name dsd)
412                                        (dsd-type dsd)
413                                        (unless (eq t (dsd-raw-type dsd))
414                                          "(unboxed)")
415                                        (dsd-default dsd)))
416                                     slots))
417                     (format stream "~@:_No slots.")))
418               (let ((slots (sb-mop:class-direct-slots class)))
419                 (if slots
420                     (format stream "~@:_Direct slots:~:{~@:_  ~S~
421                                     ~@[~@:_    Type: ~S~]~
422                                     ~@[~@:_    Allocation: ~S~]~
423                                     ~@[~@:_    Initargs: ~{~S~^, ~}~]~
424                                     ~@[~@:_    Initform: ~S~]~
425                                     ~@[~@:_    Readers: ~{~S~^, ~}~]~
426                                     ~@[~@:_    Writers: ~{~S~^, ~}~]~
427                                     ~@[~@:_    Documentation:~@:_     ~@<~@;~A~:>~]~}"
428                             (mapcar (lambda (slotd)
429                                       (list (sb-mop:slot-definition-name slotd)
430                                             (let ((type (sb-mop:slot-definition-type slotd)))
431                                               (unless (eq t type) type))
432                                             (let ((alloc (sb-mop:slot-definition-allocation slotd)))
433                                               (unless (eq :instance alloc) alloc))
434                                             (sb-mop:slot-definition-initargs slotd)
435                                             (sb-mop:slot-definition-initform slotd)
436                                             (sb-mop:slot-definition-readers slotd)
437                                             (sb-mop:slot-definition-writers slotd)
438                                             ;; FIXME: does this get the prefix right?
439                                             (quiet-doc slotd t)))
440                                     slots))
441                     (format stream "~@:_No direct slots."))))
442           (pprint-newline :mandatory stream))))))
443
444 (defun describe-instance (object stream)
445   (let* ((class (class-of object))
446          (slotds (sb-mop:class-slots class))
447          (max-slot-name-length 0)
448          (plist nil))
449
450     ;; Figure out a good width for the slot-name column.
451     (flet ((adjust-slot-name-length (name)
452              (setf max-slot-name-length
453                    (max max-slot-name-length (length (symbol-name name))))))
454       (dolist (slotd slotds)
455         (adjust-slot-name-length (sb-mop:slot-definition-name slotd))
456         (push slotd (getf plist (sb-mop:slot-definition-allocation slotd))))
457       (setf max-slot-name-length  (min (+ max-slot-name-length 3) 30)))
458
459     ;; Now that we know the width, we can print.
460     (flet ((describe-slot (name value)
461              (format stream "~%  ~A~VT = ~A" name max-slot-name-length
462                      (prin1-to-line value))))
463       (sb-pcl::doplist (allocation slots) plist
464         (format stream "~%Slots with ~S allocation:" allocation)
465         (dolist (slotd (nreverse slots))
466           (describe-slot
467            (sb-mop:slot-definition-name slotd)
468            (sb-pcl::slot-value-or-default object (sb-mop:slot-definition-name slotd))))))
469     (unless slotds
470       (format stream "~@:_No slots."))
471     (terpri stream)))
472
473 (defun quiet-doc (object type)
474   (handler-bind ((warning #'muffle-warning))
475     (documentation object type)))
476
477 (defun describe-documentation (object type stream &optional undoc newline)
478   (let ((doc (quiet-doc object type)))
479     (cond (doc
480            (format stream "~@:_Documentation:~@:_")
481            (pprint-logical-block (stream nil :per-line-prefix "  ")
482              (princ doc stream)))
483           (undoc
484            (format stream "~@:_(undocumented)")))
485     (when newline
486       (pprint-newline :mandatory stream))))
487
488 (defun describe-stuff (label list stream &key (escape t))
489   (when list
490     (if escape
491         (format stream "~@:_~A:~@<~;~{ ~S~^,~:_~}~;~:>" label list)
492         (format stream "~@:_~A:~@<~;~{ ~A~^,~:_~}~;~:>" label list))))
493
494 (defun describe-lambda-list (lambda-list stream)
495   (format stream "~@:_Lambda-list: ~:A" lambda-list))
496
497 (defun describe-function-source (function stream)
498   (if (compiled-function-p function)
499       (let* ((code (fun-code-header (%fun-fun function)))
500              (info (sb-kernel:%code-debug-info code)))
501         (when info
502           (let ((source (sb-c::debug-info-source info)))
503             (when source
504               (let ((namestring (sb-c::debug-source-namestring source)))
505                 ;; This used to also report the times the source was created
506                 ;; and compiled, but that seems more like noise than useful
507                 ;; information -- but FWIW that are to be had as
508                 ;; SB-C::DEBUG-SOUCE-CREATED/COMPILED.
509                 (cond (namestring
510                        (format stream "~@:_Source file: ~A" namestring))
511                       ((sb-di:debug-source-form source)
512                        (format stream "~@:_Source form:~@:_  ~S"
513                                (sb-di:debug-source-form source)))
514                       (t (bug "Don't know how to use a DEBUG-SOURCE without ~
515                                a namestring or a form."))))))))
516       #+sb-eval
517       (let ((source (sb-eval:interpreted-function-source-location function)))
518         (when source
519           (let ((namestring (sb-c:definition-source-location-namestring source)))
520             (when namestring
521               (format stream "~@:_Source file: ~A" namestring)))))))
522
523 (defun describe-function (name function stream)
524   (let ((name (if function (fun-name function) name)))
525     (if (not (or function (and (legal-fun-name-p name) (fboundp name))))
526         ;; Not defined, but possibly the type is declared, or we have
527         ;; compiled calls to it.
528         (when (legal-fun-name-p name)
529           (multiple-value-bind (from sure) (info :function :where-from name)
530             (when (or (eq :declared from) (and sure (eq :assumed from)))
531               (pprint-logical-block (stream nil)
532                 (format stream "~%~A names an undefined function" name)
533                 (pprint-indent :block 2 stream)
534                 (format stream "~@:_~:(~A~) type: ~S"
535                         from
536                         (type-specifier (info :function :type name)))))))
537         ;; Defined.
538         (multiple-value-bind (fun what lambda-list ftype from inline
539                                   methods)
540             (cond ((and (not function) (symbolp name) (special-operator-p name))
541                    (let ((fun (symbol-function name)))
542                      (values fun "a special operator" (%fun-lambda-list fun))))
543                   ((and (not function) (symbolp name) (macro-function name))
544                    (let ((fun (macro-function name)))
545                      (values fun "a macro" (%fun-lambda-list fun))))
546                   (t
547                    (let ((fun (or function (fdefinition name))))
548                      (multiple-value-bind (ftype from)
549                          (if function
550                              (values (%fun-type function) "Derived")
551                              (let ((ctype (info :function :type name)))
552                                (values (when ctype (type-specifier ctype))
553                                        (when ctype
554                                          ;; Ensure lazy pickup of information
555                                          ;; from methods.
556                                          (sb-c::maybe-update-info-for-gf name)
557                                          (ecase (info :function :where-from name)
558                                            (:declared "Declared")
559                                            ;; This is hopefully clearer to users
560                                            ((:defined-method :defined) "Derived"))))))
561                        (if (typep fun 'generic-function)
562                            (values fun
563                                    "a generic function"
564                                    (sb-mop:generic-function-lambda-list fun)
565                                    ftype
566                                    from
567                                    nil
568                                    (or (sb-mop:generic-function-methods fun)
569                                        :none))
570                            (values fun
571                                    (if (compiled-function-p fun)
572                                        "a compiled function"
573                                        "an interpreted function")
574                                    (%fun-lambda-list fun)
575                                    ftype
576                                    from
577                                    (unless function
578                                      (cons
579                                       (info :function :inlinep name)
580                                       (info :function :inline-expansion-designator name)))))))))
581           (pprint-logical-block (stream nil)
582             (unless function
583               (format stream "~%~A names ~A:" name what)
584               (pprint-indent :block 2 stream))
585             (describe-lambda-list lambda-list stream)
586             (when (and ftype from)
587               (format stream "~@:_~A type: ~S" from ftype))
588             (describe-documentation name 'function stream)
589             (when (car inline)
590               (format stream "~@:_Inline proclamation: ~A (~:[no ~;~]inline expansion available)"
591                       (car inline)
592                       (cdr inline)))
593             (when methods
594               (format stream "~@:_Method-combination: ~S"
595                       (sb-pcl::method-combination-type-name
596                        (sb-pcl:generic-function-method-combination fun)))
597               (cond ((eq :none methods)
598                      (format stream "~@:_No methods."))
599                     (t
600                      (pprint-newline :mandatory stream)
601                      (pprint-logical-block (stream nil)
602                        (format stream "Methods:")
603                        (dolist (method methods)
604                          (pprint-indent :block 2 stream)
605                          (format stream "~@:_(~A ~{~S ~}~:S)"
606                                  name
607                                  (method-qualifiers method)
608                                  (sb-pcl::unparse-specializers fun (sb-mop:method-specializers method)))
609                          (pprint-indent :block 4 stream)
610                          (describe-documentation method t stream nil))))))
611             (describe-function-source fun stream)
612             (terpri stream)))))
613   (unless function
614     (awhen (and (legal-fun-name-p name) (compiler-macro-function name))
615       (pprint-logical-block (stream nil)
616         (format stream "~@:_~A has a compiler-macro:" name)
617         (pprint-indent :block 2 stream)
618         (describe-documentation it t stream)
619         (describe-function-source it stream))
620       (terpri stream))
621     (when (and (consp name) (eq 'setf (car name)) (not (cddr name)))
622       (let* ((name2 (second name))
623              (inverse (info :setf :inverse name2))
624              (expander (info :setf :expander name2)))
625         (cond (inverse
626                (pprint-logical-block (stream nil)
627                  (format stream "~&~A has setf-expansion: ~S"
628                          name inverse)
629                  (pprint-indent :block 2 stream)
630                  (describe-documentation name2 'setf stream))
631                (terpri stream))
632               (expander
633                (pprint-logical-block (stream nil)
634                  (format stream "~&~A has a complex setf-expansion:"
635                          name)
636                  (pprint-indent :block 2 stream)
637                  (describe-documentation name2 'setf stream t))
638                (terpri stream)))))
639     (when (symbolp name)
640       (describe-function `(setf ,name) nil stream))))