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