cleanup DESCRIBE of symbols naming type specifiers a bit
[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         (when (info :variable :always-bound symbol)
258           (format stream "~@:_Declared always-bound."))
259         (cond
260           ((eq kind :alien)
261            (let ((info (info :variable :alien-info symbol)))
262              (format stream "~@:_Value: ~S" (eval symbol))
263              (format stream "~@:_Type: ~S"
264                      (sb-alien-internals:unparse-alien-type
265                       (sb-alien::heap-alien-info-type info)))
266              (format stream "~@:_Address: #x~8,'0X"
267                      (sap-int (eval (sb-alien::heap-alien-info-sap-form info))))))
268           ((eq kind :macro)
269            (let ((expansion (info :variable :macro-expansion symbol)))
270              (format stream "~@:_Expansion: ~S" expansion)))
271           ((boundp symbol)
272            (format stream "~:@_Value: ~S" (symbol-value symbol)))
273           ((not (eq kind :unknown))
274            (format stream "~:@_Currently unbound.")))
275         (describe-documentation symbol 'variable stream)
276         (terpri stream))))
277
278   ;; TODO: We could grovel over all packages looking for and
279   ;; reporting other phenomena, e.g. IMPORT and SHADOW, or
280   ;; availability in some package even after (SYMBOL-PACKAGE SYMBOL) has
281   ;; been set to NIL.
282   ;;
283   ;; TODO: It might also be nice to describe (find-package symbol)
284   ;; if one exists. Maybe not all the exports, etc, but the package
285   ;; documentation.
286   (describe-function symbol nil stream)
287   (describe-class symbol nil stream)
288
289   ;; Type specifier
290   (let* ((kind (info :type :kind symbol))
291          (fun (case kind
292                 (:defined
293                  (or (info :type :expander symbol) t))
294                 (:primitive
295                  (or (info :type :translator symbol) t)))))
296     (when fun
297       (pprint-newline :mandatory stream)
298       (pprint-logical-block (stream nil)
299         (format stream "~@:_~A names a ~@[primitive~* ~]type-specifier:"
300                 symbol
301                 (eq kind :primitive))
302         (pprint-indent :block 2 stream)
303         (describe-documentation symbol 'type stream (eq t fun))
304         (unless (eq t fun)
305           (describe-lambda-list (if (eq :primitive kind)
306                                     (%fun-lambda-list fun)
307                                     (info :type :lambda-list symbol))
308                                 stream)
309           (when (eq (%fun-fun fun) (%fun-fun (constant-type-expander t)))
310             (format stream "~@:_Expansion: ~S" (funcall fun (list symbol))))))
311       (terpri stream)))
312
313   (when (or (member symbol sb-c::*policy-qualities*)
314             (assoc symbol sb-c::*policy-dependent-qualities*))
315     (pprint-logical-block (stream nil)
316       (pprint-newline :mandatory stream)
317       (pprint-indent :block 2 stream)
318       (format stream "~A names a~:[ dependent~;n~] optimization policy quality:"
319               symbol
320               (member symbol sb-c::*policy-qualities*))
321       (describe-documentation symbol 'optimize stream t))
322     (terpri stream))
323
324   ;; Print out properties.
325   (let ((plist (symbol-plist symbol)))
326     (when plist
327       (pprint-logical-block (stream nil)
328         (format stream "~%Symbol-plist:")
329         (pprint-indent :block 2 stream)
330         (sb-pcl::doplist (key value) plist
331           (format stream "~@:_~A -> ~A"
332                   (prin1-to-line key :columns 2 :reserve 5)
333                   (prin1-to-line value :columns 2 :reserve 5))))
334       (terpri stream))))
335
336 (defmethod describe-object ((package package) stream)
337   (print-standard-describe-header package stream)
338   (pprint-logical-block (stream nil)
339     (describe-documentation package t stream)
340     (flet ((humanize (list)
341              (sort (mapcar (lambda (x)
342                              (if (packagep x)
343                                  (package-name x)
344                                  x))
345                            list)
346                    #'string<))
347            (out (label list)
348              (describe-stuff label list stream :escape nil)))
349       (let ((implemented (humanize (package-implemented-by-list package)))
350             (implements (humanize (package-implements-list package)))
351             (nicks (humanize (package-nicknames package)))
352             (uses (humanize (package-use-list package)))
353             (used (humanize (package-used-by-list package)))
354             (shadows (humanize (package-shadowing-symbols package)))
355             (this (list (package-name package)))
356             (exports nil))
357         (do-external-symbols (ext package)
358           (push ext exports))
359         (setf exports (humanize exports))
360         (when (package-locked-p package)
361           (format stream "~@:_Locked."))
362         (when (set-difference implemented this :test #'string=)
363           (out "Implemented-by-list" implemented))
364         (when (set-difference implements this :test #'string=)
365           (out "Implements-list" implements))
366         (out "Nicknames" nicks)
367         (out "Use-list" uses)
368         (out "Used-by-list" used)
369         (out "Shadows" shadows)
370         (out "Exports" exports)
371         (format stream "~@:_~S internal symbols."
372                 (package-internal-symbol-count package))))
373     (terpri stream)))
374 \f
375 ;;;; Helpers to deal with shared functionality
376
377 (defun describe-class (name class stream)
378   (let* ((by-name (not class))
379          (name (if class (class-name class) name))
380          (class (if class class (find-class name nil))))
381     (when class
382       (let ((metaclass-name (class-name (class-of class))))
383         (pprint-logical-block (stream nil)
384           (when by-name
385             (format stream "~@:_~A names the ~(~A~) ~S:"
386                     name
387                     metaclass-name
388                     class)
389             (pprint-indent :block 2 stream))
390           (describe-documentation class t stream)
391           (when (sb-mop:class-finalized-p class)
392             (describe-stuff "Class precedence-list"
393                             (mapcar #'class-name-or-class (sb-mop:class-precedence-list class))
394                             stream))
395           (describe-stuff "Direct superclasses"
396                           (mapcar #'class-name-or-class (sb-mop:class-direct-superclasses class))
397                           stream)
398           (let ((subs (mapcar #'class-name-or-class (sb-mop:class-direct-subclasses class))))
399             (if subs
400                 (describe-stuff "Direct subclasses" subs stream)
401                 (format stream "~@:_No subclasses.")))
402           (unless (sb-mop:class-finalized-p class)
403             (format stream "~@:_Not yet finalized."))
404           (if (eq 'structure-class metaclass-name)
405               (let* ((dd (find-defstruct-description name))
406                      (slots (dd-slots dd)))
407                 (if slots
408                     (format stream "~@:_Slots:~:{~@:_  ~S~
409                                     ~@:_    Type: ~A ~@[~A~]~
410                                     ~@:_    Initform: ~S~}"
411                             (mapcar (lambda (dsd)
412                                       (list
413                                        (dsd-name dsd)
414                                        (dsd-type dsd)
415                                        (unless (eq t (dsd-raw-type dsd))
416                                          "(unboxed)")
417                                        (dsd-default dsd)))
418                                     slots))
419                     (format stream "~@:_No slots.")))
420               (let ((slots (sb-mop:class-direct-slots class)))
421                 (if slots
422                     (format stream "~@:_Direct slots:~:{~@:_  ~S~
423                                     ~@[~@:_    Type: ~S~]~
424                                     ~@[~@:_    Allocation: ~S~]~
425                                     ~@[~@:_    Initargs: ~{~S~^, ~}~]~
426                                     ~@[~@:_    Initform: ~S~]~
427                                     ~@[~@:_    Readers: ~{~S~^, ~}~]~
428                                     ~@[~@:_    Writers: ~{~S~^, ~}~]~
429                                     ~@[~@:_    Documentation:~@:_     ~@<~@;~A~:>~]~}"
430                             (mapcar (lambda (slotd)
431                                       (list (sb-mop:slot-definition-name slotd)
432                                             (let ((type (sb-mop:slot-definition-type slotd)))
433                                               (unless (eq t type) type))
434                                             (let ((alloc (sb-mop:slot-definition-allocation slotd)))
435                                               (unless (eq :instance alloc) alloc))
436                                             (sb-mop:slot-definition-initargs slotd)
437                                             (sb-mop:slot-definition-initform slotd)
438                                             (sb-mop:slot-definition-readers slotd)
439                                             (sb-mop:slot-definition-writers slotd)
440                                             ;; FIXME: does this get the prefix right?
441                                             (quiet-doc slotd t)))
442                                     slots))
443                     (format stream "~@:_No direct slots."))))
444           (pprint-indent :block 0 stream)
445           (pprint-newline :mandatory stream))))))
446
447 (defun describe-instance (object stream)
448   (let* ((class (class-of object))
449          (slotds (sb-mop:class-slots class))
450          (max-slot-name-length 0)
451          (plist nil))
452
453     ;; Figure out a good width for the slot-name column.
454     (flet ((adjust-slot-name-length (name)
455              (setf max-slot-name-length
456                    (max max-slot-name-length (length (symbol-name name))))))
457       (dolist (slotd slotds)
458         (adjust-slot-name-length (sb-mop:slot-definition-name slotd))
459         (push slotd (getf plist (sb-mop:slot-definition-allocation slotd))))
460       (setf max-slot-name-length  (min (+ max-slot-name-length 3) 30)))
461
462     ;; Now that we know the width, we can print.
463     (flet ((describe-slot (name value)
464              (format stream "~%  ~A~VT = ~A" name max-slot-name-length
465                      (prin1-to-line value))))
466       (sb-pcl::doplist (allocation slots) plist
467         (format stream "~%Slots with ~S allocation:" allocation)
468         (dolist (slotd (nreverse slots))
469           (describe-slot
470            (sb-mop:slot-definition-name slotd)
471            (sb-pcl::slot-value-or-default object (sb-mop:slot-definition-name slotd))))))
472     (unless slotds
473       (format stream "~@:_No slots."))
474     (terpri stream)))
475
476 (defun quiet-doc (object type)
477   (handler-bind ((warning #'muffle-warning))
478     (documentation object type)))
479
480 (defun describe-documentation (object type stream &optional undoc newline)
481   (let ((doc (quiet-doc object type)))
482     (cond (doc
483            (format stream "~@:_Documentation:~@:_")
484            (pprint-logical-block (stream nil :per-line-prefix "  ")
485              (princ doc stream)))
486           (undoc
487            (format stream "~@:_(undocumented)")))
488     (when newline
489       (pprint-newline :mandatory stream))))
490
491 (defun describe-stuff (label list stream &key (escape t))
492   (when list
493     (if escape
494         (format stream "~@:_~A:~@<~;~{ ~S~^,~:_~}~;~:>" label list)
495         (format stream "~@:_~A:~@<~;~{ ~A~^,~:_~}~;~:>" label list))))
496
497 (defun describe-lambda-list (lambda-list stream)
498   (format stream "~@:_Lambda-list: ~:A" lambda-list))
499
500 (defun describe-function-source (function stream)
501   (if (compiled-function-p function)
502       (let* ((code (fun-code-header (%fun-fun function)))
503              (info (sb-kernel:%code-debug-info code)))
504         (when info
505           (let ((source (sb-c::debug-info-source info)))
506             (when source
507               (let ((namestring (sb-c::debug-source-namestring source)))
508                 ;; This used to also report the times the source was created
509                 ;; and compiled, but that seems more like noise than useful
510                 ;; information -- but FWIW that are to be had as
511                 ;; SB-C::DEBUG-SOUCE-CREATED/COMPILED.
512                 (cond (namestring
513                        (format stream "~@:_Source file: ~A" namestring))
514                       ((sb-di:debug-source-form source)
515                        (format stream "~@:_Source form:~@:_  ~S"
516                                (sb-di:debug-source-form source)))))))))
517       #+sb-eval
518       (let ((source (sb-eval:interpreted-function-source-location function)))
519         (when source
520           (let ((namestring (sb-c:definition-source-location-namestring source)))
521             (when namestring
522               (format stream "~@:_Source file: ~A" namestring)))))))
523
524 (defun describe-function (name function stream)
525   (let ((name (if function (fun-name function) name)))
526     (if (not (or function (and (legal-fun-name-p name) (fboundp name))))
527         ;; Not defined, but possibly the type is declared, or we have
528         ;; compiled calls to it.
529         (when (legal-fun-name-p name)
530           (multiple-value-bind (from sure) (info :function :where-from name)
531             (when (or (eq :declared from) (and sure (eq :assumed from)))
532               (pprint-logical-block (stream nil)
533                 (format stream "~%~A names an undefined function" name)
534                 (pprint-indent :block 2 stream)
535                 (format stream "~@:_~:(~A~) type: ~S"
536                         from
537                         (type-specifier (info :function :type name)))))))
538         ;; Defined.
539         (multiple-value-bind (fun what lambda-list ftype from inline
540                                   methods)
541             (cond ((and (not function) (symbolp name) (special-operator-p name))
542                    (let ((fun (symbol-function name)))
543                      (values fun "a special operator" (%fun-lambda-list fun))))
544                   ((and (not function) (symbolp name) (macro-function name))
545                    (let ((fun (macro-function name)))
546                      (values fun "a macro" (%fun-lambda-list fun))))
547                   (t
548                    (let ((fun (or function (fdefinition name))))
549                      (multiple-value-bind (ftype from)
550                          (if function
551                              (values (%fun-type function) "Derived")
552                              (let ((ctype (info :function :type name)))
553                                (values (when ctype (type-specifier ctype))
554                                        (when ctype
555                                          ;; Ensure lazy pickup of information
556                                          ;; from methods.
557                                          (sb-c::maybe-update-info-for-gf name)
558                                          (ecase (info :function :where-from name)
559                                            (:declared "Declared")
560                                            ;; This is hopefully clearer to users
561                                            ((:defined-method :defined) "Derived"))))))
562                        (if (typep fun 'generic-function)
563                            (values fun
564                                    "a generic function"
565                                    (sb-mop:generic-function-lambda-list fun)
566                                    ftype
567                                    from
568                                    nil
569                                    (or (sb-mop:generic-function-methods fun)
570                                        :none))
571                            (values fun
572                                    (if (compiled-function-p fun)
573                                        "a compiled function"
574                                        "an interpreted function")
575                                    (%fun-lambda-list fun)
576                                    ftype
577                                    from
578                                    (unless function
579                                      (cons
580                                       (info :function :inlinep name)
581                                       (info :function :inline-expansion-designator name)))))))))
582           (pprint-logical-block (stream nil)
583             (unless function
584               (format stream "~%~A names ~A:" name what)
585               (pprint-indent :block 2 stream))
586             (describe-lambda-list lambda-list stream)
587             (when (and ftype from)
588               (format stream "~@:_~A type: ~S" from ftype))
589             (describe-documentation name 'function stream)
590             (when (car inline)
591               (format stream "~@:_Inline proclamation: ~A (~:[no ~;~]inline expansion available)"
592                       (car inline)
593                       (cdr inline)))
594             (when methods
595               (format stream "~@:_Method-combination: ~S"
596                       (sb-pcl::method-combination-type-name
597                        (sb-pcl:generic-function-method-combination fun)))
598               (cond ((eq :none methods)
599                      (format stream "~@:_No methods."))
600                     (t
601                      (pprint-newline :mandatory stream)
602                      (pprint-logical-block (stream nil)
603                        (format stream "Methods:")
604                        (dolist (method methods)
605                          (pprint-indent :block 2 stream)
606                          (format stream "~@:_(~A ~{~S ~}~:S)"
607                                  name
608                                  (method-qualifiers method)
609                                  (sb-pcl::unparse-specializers fun (sb-mop:method-specializers method)))
610                          (pprint-indent :block 4 stream)
611                          (describe-documentation method t stream nil))))))
612             (describe-function-source fun stream)
613             (terpri stream)))))
614   (unless function
615     (awhen (and (legal-fun-name-p name) (compiler-macro-function name))
616       (pprint-logical-block (stream nil)
617         (format stream "~@:_~A has a compiler-macro:" name)
618         (pprint-indent :block 2 stream)
619         (describe-documentation it t stream)
620         (describe-function-source it stream))
621       (terpri stream))
622     (when (and (consp name) (eq 'setf (car name)) (not (cddr name)))
623       (let* ((name2 (second name))
624              (inverse (info :setf :inverse name2))
625              (expander (info :setf :expander name2)))
626         (cond (inverse
627                (pprint-logical-block (stream nil)
628                  (format stream "~&~A has setf-expansion: ~S"
629                          name inverse)
630                  (pprint-indent :block 2 stream)
631                  (describe-documentation name2 'setf stream))
632                (terpri stream))
633               (expander
634                (pprint-logical-block (stream nil)
635                  (format stream "~&~A has a complex setf-expansion:"
636                          name)
637                  (pprint-indent :block 2 stream)
638                  (describe-documentation name2 'setf stream t))
639                (terpri stream)))))
640     (when (symbolp name)
641       (describe-function `(setf ,name) nil stream))))