Silence some warnings with CCL-hosted build.
[sbcl.git] / src / code / describe.lisp
blob9cc69a67db7c6b9200fa9a09795b714258cabf23
1 ;;;; the DESCRIBE system
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.
12 ;;; SB-IMPL, not SB!IMPL, since we're built in warm load.
13 (in-package "SB-IMPL")
15 ;;;; Utils, move elsewhere.
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)))
23 ;;;; the ANSI interface to function names (and to other stuff too)
24 ;;; Note: this function gets called by the compiler (as of 1.0.17.x,
25 ;;; in MAYBE-INLINE-SYNTACTIC-CLOSURE), and so although ANSI says
26 ;;; we're allowed to return NIL here freely, it seems plausible that
27 ;;; small changes to the circumstances under which this function
28 ;;; returns non-NIL might have subtle consequences on the compiler.
29 ;;; So it might be desirable to have the compiler not rely on this
30 ;;; function, eventually.
31 (defun function-lambda-expression (fun)
32 #+sb-doc
33 "Return (VALUES DEFINING-LAMBDA-EXPRESSION CLOSURE-P NAME), where
34 DEFINING-LAMBDA-EXPRESSION is NIL if unknown, or a suitable argument
35 to COMPILE otherwise, CLOSURE-P is non-NIL if the function's definition
36 might have been enclosed in some non-null lexical environment, and
37 NAME is some name (for debugging only) or NIL if there is no name."
38 (declare (type function fun))
39 (etypecase fun
40 #+sb-eval
41 (sb-eval:interpreted-function
42 (let ((name (sb-eval:interpreted-function-name fun))
43 (lambda-list (sb-eval:interpreted-function-lambda-list fun))
44 (declarations (sb-eval:interpreted-function-declarations fun))
45 (body (sb-eval:interpreted-function-body fun)))
46 (values `(lambda ,lambda-list
47 ,@(when declarations `((declare ,@declarations)))
48 ,@body)
49 t name)))
50 #+sb-fasteval
51 (sb-interpreter:interpreted-function
52 (sb-interpreter:fun-lambda-expression fun))
53 (function
54 (let* ((name (%fun-name fun))
55 (fun (%simple-fun-self (%fun-fun fun)))
56 (code (sb-di::fun-code-header fun))
57 (info (sb-kernel:%code-debug-info code))
58 (source (if info (sb-c::debug-info-source info))))
59 (cond ((and source (sb-c::debug-source-form source)
60 (eq (sb-c::debug-source-function source) fun))
61 (values (sb-c::debug-source-form source) nil name))
62 ((legal-fun-name-p name)
63 (let ((exp (fun-name-inline-expansion name)))
64 (values exp (not exp) name)))
66 (values nil t name)))))))
68 ;;; Prints X on a single line, limiting output length by *PRINT-RIGHT-MARGIN*
69 ;;; -- good for printing object parts, etc.
70 (defun prin1-to-line (x &key (columns 1) (reserve 0))
71 (let* ((line (write-to-string x :escape t :readably nil :lines 2 :circle t))
72 (p (position #\newline line))
73 (limit (truncate (- *print-right-margin* reserve) columns)))
74 (flet ((trunc (&optional end)
75 (let ((line-end (- limit 2)))
76 (with-simple-output-to-string (s)
77 (write-string line s :end (if end
78 (min end line-end)
79 line-end))
80 (write-string ".." s)))))
81 (cond (p
82 (trunc p))
83 ((> (length line) limit)
84 (trunc))
86 line)))))
88 (defun describe (object &optional (stream-designator *standard-output*))
89 #+sb-doc
90 "Print a description of OBJECT to STREAM-DESIGNATOR."
91 (let ((stream (out-synonym-of stream-designator))
92 (*print-right-margin* (or *print-right-margin* 72))
93 (*print-circle* t)
94 (*suppress-print-errors*
95 (if (subtypep 'serious-condition *suppress-print-errors*)
96 *suppress-print-errors*
97 'serious-condition)))
98 ;; Until sbcl-0.8.0.x, we did
99 ;; (FRESH-LINE STREAM)
100 ;; (PPRINT-LOGICAL-BLOCK (STREAM NIL)
101 ;; ...
102 ;; here. However, ANSI's specification of DEFUN DESCRIBE,
103 ;; DESCRIBE exists as an interface primarily to manage argument
104 ;; defaulting (including conversion of arguments T and NIL into
105 ;; stream objects) and to inhibit any return values from
106 ;; DESCRIBE-OBJECT.
107 ;; doesn't mention either FRESH-LINEing or PPRINT-LOGICAL-BLOCKing,
108 ;; and the example of typical DESCRIBE-OBJECT behavior in ANSI's
109 ;; specification of DESCRIBE-OBJECT will work poorly if we do them
110 ;; here. (The example method for DESCRIBE-OBJECT does its own
111 ;; FRESH-LINEing, which is a physical directive which works poorly
112 ;; inside a pretty-printer logical block.)
113 (handler-bind ((print-not-readable #'print-unreadably))
114 (describe-object object stream))
115 ;; We don't TERPRI here either (any more since sbcl-0.8.0.x), because
116 ;; again ANSI's specification of DESCRIBE doesn't mention it and
117 ;; ANSI's example of DESCRIBE-OBJECT does its own final TERPRI.
118 (values)))
120 ;;;; DESCRIBE-OBJECT
121 ;;;;
122 ;;;; Style guide:
123 ;;;;
124 ;;;; * Each interesting class has a primary method of its own.
125 ;;;;
126 ;;;; * Output looks like
127 ;;;;
128 ;;;; object-self-string
129 ;;;; [object-type-string]
130 ;;;;
131 ;;;; Block1:
132 ;;;; Sublabel1: text
133 ;;;; Sublabel2: text
134 ;;;;
135 ;;;; Block2:
136 ;;;; ...
137 ;;;;
138 ;;;; * The newline policy that gets the whitespace right is for
139 ;;;; each block to both start and end with a newline.
141 (defgeneric object-self-string (x))
143 (defmethod object-self-string (x)
144 (prin1-to-line x))
146 (defmethod object-self-string ((x symbol))
147 (let ((*package* (find-package :keyword)))
148 (prin1-to-string x)))
150 (defgeneric object-type-string (x))
152 (defmethod object-type-string (x)
153 (let ((type (class-name-or-class (class-of x))))
154 (if (symbolp type)
155 (string-downcase type)
156 (prin1-to-string type))))
158 (defmethod object-type-string ((x cons))
159 (if (listp (cdr x)) "list" "cons"))
161 (defmethod object-type-string ((x hash-table))
162 "hash-table")
164 (defmethod object-type-string ((x condition))
165 "condition")
167 (defmethod object-type-string ((x structure-object))
168 "structure-object")
170 (defmethod object-type-string ((x standard-object))
171 "standard-object")
173 (defmethod object-type-string ((x function))
174 (typecase x
175 (simple-fun "compiled function")
176 (closure "compiled closure")
177 ((or #+sb-fasteval sb-interpreter:interpreted-function
178 #+sb-eval sb-eval:interpreted-function) "interpreted function")
179 (generic-function "generic-function")
180 (t "funcallable-instance")))
182 (defmethod object-type-string ((x stream))
183 "stream")
185 (defmethod object-type-string ((x sb-gray:fundamental-stream))
186 "gray stream")
188 (defmethod object-type-string ((x package))
189 "package")
191 (defmethod object-type-string ((x array))
192 (cond ((or (stringp x) (bit-vector-p x))
193 (format nil "~@[simple-~*~]~A"
194 (typep x 'simple-array)
195 (typecase x
196 (base-string "base-string")
197 (string "string")
198 (t "bit-vector"))))
200 (if (simple-vector-p x)
201 "simple-vector"
202 (format nil "~@[simple ~*~]~@[specialized ~*~]~:[array~;vector~]"
203 (typep x 'simple-array)
204 (neq t (array-element-type x))
205 (vectorp x))))))
207 (defmethod object-type-string ((x character))
208 (typecase x
209 (standard-char "standard-char")
210 (base-char "base-char")
211 (t "character")))
213 (defun print-standard-describe-header (x stream)
214 (format stream "~&~A~% [~A]~%"
215 (object-self-string x)
216 (object-type-string x)))
218 (defgeneric describe-object (x stream))
220 ;;; Catch-all.
222 (defmethod describe-object ((x t) s)
223 (print-standard-describe-header x s))
225 (defmethod describe-object ((x cons) s)
226 (print-standard-describe-header x s)
227 (describe-function x nil s))
229 (defmethod describe-object ((x function) s)
230 (print-standard-describe-header x s)
231 (describe-function nil x s))
233 (defmethod describe-object ((x class) s)
234 (print-standard-describe-header x s)
235 (describe-class nil x s)
236 (describe-instance x s))
238 (defmethod describe-object ((x sb-pcl::slot-object) s)
239 (print-standard-describe-header x s)
240 (describe-instance x s))
242 (defmethod describe-object ((x character) s)
243 (print-standard-describe-header x s)
244 (format s "~%Char-code: ~S" (char-code x))
245 (format s "~%Char-name: ~A" (char-name x)))
247 (defmethod describe-object ((x array) s)
248 (print-standard-describe-header x s)
249 (format s "~%Element-type: ~/sb-impl:print-type-specifier/"
250 (array-element-type x))
251 (if (vectorp x)
252 (if (array-has-fill-pointer-p x)
253 (format s "~%Fill-pointer: ~S~%Size: ~S"
254 (fill-pointer x)
255 (array-total-size x))
256 (format s "~%Length: ~S" (length x)))
257 (format s "~%Dimensions: ~S" (array-dimensions x)))
258 (let ((*print-array* nil))
259 (unless (typep x 'simple-array)
260 (format s "~%Adjustable: ~A" (if (adjustable-array-p x) "yes" "no"))
261 (multiple-value-bind (to offset) (array-displacement x)
262 (if (format s "~%Displaced-to: ~A~%Displaced-offset: ~S"
263 (prin1-to-line to)
264 offset)
265 (format s "~%Displaced: no"))))
266 (when (and (not (array-displacement x)) (array-header-p x))
267 (format s "~%Storage vector: ~A"
268 (prin1-to-line (array-storage-vector x))))
269 (terpri s)))
271 (defmethod describe-object ((x hash-table) s)
272 (print-standard-describe-header x s)
273 ;; Don't print things which are already apparent from the printed
274 ;; representation -- COUNT, TEST, and WEAKNESS
275 (format s "~%Occupancy: ~,1F" (float (/ (hash-table-count x)
276 (hash-table-size x))))
277 (format s "~%Rehash-threshold: ~S" (hash-table-rehash-threshold x))
278 (format s "~%Rehash-size: ~S" (hash-table-rehash-size x))
279 (format s "~%Size: ~S" (hash-table-size x))
280 (format s "~%Synchronized: ~A" (if (hash-table-synchronized-p x) "yes" "no"))
281 (terpri s))
283 (defmethod describe-object ((symbol symbol) stream)
284 (print-standard-describe-header symbol stream)
286 ;; Describe the value cell.
287 (describe-variable symbol stream)
289 ;; TODO: We could grovel over all packages looking for and
290 ;; reporting other phenomena, e.g. IMPORT and SHADOW, or
291 ;; availability in some package even after (SYMBOL-PACKAGE SYMBOL) has
292 ;; been set to NIL.
294 ;; TODO: It might also be nice to describe (find-package symbol)
295 ;; if one exists. Maybe not all the exports, etc, but the package
296 ;; documentation.
297 (describe-function symbol nil stream)
298 (describe-class symbol nil stream)
300 ;; Type specifier
301 (describe-type symbol stream)
303 (awhen (sb-c::policy-quality-name-p symbol)
304 (pprint-logical-block (stream nil)
305 (pprint-newline :mandatory stream)
306 (pprint-indent :block 2 stream)
307 (format stream "~A names a~:[ dependent~;n~] optimization policy quality:"
308 symbol (minusp it))
309 (describe-documentation symbol 'optimize stream t))
310 (terpri stream))
312 ;; Print out properties.
313 (let ((plist (symbol-plist symbol)))
314 (when plist
315 (pprint-logical-block (stream nil)
316 (format stream "~%Symbol-plist:")
317 (pprint-indent :block 2 stream)
318 (sb-pcl::doplist (key value) plist
319 (format stream "~@:_~A -> ~A"
320 (prin1-to-line key :columns 2 :reserve 5)
321 (prin1-to-line value :columns 2 :reserve 5))))
322 (terpri stream))))
324 (defmethod describe-object ((package package) stream)
325 (print-standard-describe-header package stream)
326 (pprint-logical-block (stream nil)
327 (describe-documentation package t stream)
328 (flet ((humanize (list)
329 (sort (mapcar (lambda (x)
330 (if (packagep x)
331 (package-name x)
333 list)
334 #'string<))
335 (out (label list)
336 (describe-stuff label list stream :escape nil)))
337 (let ((exports nil))
338 (do-external-symbols (ext package)
339 (push ext exports))
340 #+sb-package-locks
341 (let ((implemented (humanize (package-implemented-by-list package)))
342 (implements (humanize (package-implements-list package)))
343 (this (list (package-name package))))
344 (when (package-locked-p package)
345 (format stream "~@:_Locked."))
346 (when (set-difference implemented this :test #'string=)
347 (out "Implemented-by-list" implemented))
348 (when (set-difference implements this :test #'string=)
349 (out "Implements-list" implements)))
350 (out "Nicknames" (humanize (package-nicknames package)))
351 (out "Use-list" (humanize (package-use-list package)))
352 (out "Used-by-list" (humanize (package-used-by-list package)))
353 (out "Shadows" (humanize (package-shadowing-symbols package)))
354 (out "Exports" (humanize exports))
355 (format stream "~@:_~S internal symbols."
356 (package-internal-symbol-count package))))
357 (terpri stream)))
359 ;;;; Helpers to deal with shared functionality
361 (defun describe-deprecation (namespace name stream)
362 (multiple-value-bind (state since replacements)
363 (deprecated-thing-p namespace name)
364 (when state
365 (destructuring-bind (software version) since
366 (format stream "~@:_In ~A deprecation since ~@[~A ~]version ~A.~
367 ~@[ ~/sb-impl::print-deprecation-replacements/~]"
368 state software version replacements)))))
370 (defun describe-class (name class stream)
371 (binding* ((by-name (not class))
372 ((name class) (if class
373 (values (class-name class) name)
374 (values name (find-class name nil)))))
375 (when class
376 (let ((metaclass-name (class-name (class-of class))))
377 (pprint-logical-block (stream nil)
378 (when by-name
379 (format stream "~@:_~A names the ~(~A~) ~S:"
380 name metaclass-name class)
381 (pprint-indent :block 2 stream))
382 (describe-deprecation 'type name stream)
383 (describe-documentation class t stream)
384 (when (sb-mop:class-finalized-p class)
385 (describe-stuff "Class precedence-list"
386 (mapcar #'class-name-or-class (sb-mop:class-precedence-list class))
387 stream))
388 (describe-stuff "Direct superclasses"
389 (mapcar #'class-name-or-class (sb-mop:class-direct-superclasses class))
390 stream)
391 (let ((subs (mapcar #'class-name-or-class (sb-mop:class-direct-subclasses class))))
392 (if subs
393 (describe-stuff "Direct subclasses" subs stream)
394 (format stream "~@:_No subclasses.")))
395 (unless (sb-mop:class-finalized-p class)
396 (format stream "~@:_Not yet finalized."))
397 (if (eq 'structure-class metaclass-name)
398 (let* ((dd (find-defstruct-description name))
399 (slots (dd-slots dd)))
400 (if slots
401 (format stream "~@:_Slots:~:{~@:_ ~S~
402 ~@:_ Type: ~/sb-impl:print-type-specifier/ ~@[~A~]~
403 ~@:_ Initform: ~S~}"
404 (mapcar (lambda (dsd)
405 (list
406 (dsd-name dsd)
407 (dsd-type dsd)
408 (unless (eq t (dsd-raw-type dsd))
409 "(unboxed)")
410 (dsd-default dsd)))
411 slots))
412 (format stream "~@:_No slots.")))
413 (let ((slots (sb-mop:class-direct-slots class)))
414 (if slots
415 (format stream "~@:_Direct slots:~:{~@:_ ~S~
416 ~@[~@:_ Type: ~/sb-impl:print-type-specifier/~]~
417 ~@[~@:_ Allocation: ~S~]~
418 ~@[~@:_ Initargs: ~{~S~^, ~}~]~
419 ~@[~@:_ Initform: ~S~]~
420 ~@[~@:_ Readers: ~{~S~^, ~}~]~
421 ~@[~@:_ Writers: ~{~S~^, ~}~]~
422 ~@[~@:_ Documentation:~@:_ ~@<~@;~A~:>~]~}"
423 (mapcar (lambda (slotd)
424 (list (sb-mop:slot-definition-name slotd)
425 (let ((type (sb-mop:slot-definition-type slotd)))
426 (unless (eq t type) type))
427 (let ((alloc (sb-mop:slot-definition-allocation slotd)))
428 (unless (eq :instance alloc) alloc))
429 (sb-mop:slot-definition-initargs slotd)
430 (sb-mop:slot-definition-initform slotd)
431 (sb-mop:slot-definition-readers slotd)
432 (sb-mop:slot-definition-writers slotd)
433 ;; FIXME: does this get the prefix right?
434 (quiet-doc slotd t)))
435 slots))
436 (format stream "~@:_No direct slots."))))
437 (pprint-indent :block 0 stream)
438 (pprint-newline :mandatory stream))))))
440 (defun describe-instance (object stream)
441 (let* ((class (class-of object))
442 (slotds (sb-mop:class-slots class))
443 (max-slot-name-length 0)
444 (plist nil))
446 ;; Figure out a good width for the slot-name column.
447 (flet ((adjust-slot-name-length (name)
448 (setf max-slot-name-length
449 (max max-slot-name-length (length (symbol-name name))))))
450 (dolist (slotd slotds)
451 (adjust-slot-name-length (sb-mop:slot-definition-name slotd))
452 (push slotd (getf plist (sb-mop:slot-definition-allocation slotd))))
453 (setf max-slot-name-length (min (+ max-slot-name-length 3) 30)))
455 ;; Now that we know the width, we can print.
456 (flet ((describe-slot (name value)
457 (format stream "~% ~A~VT = ~A" name max-slot-name-length
458 (prin1-to-line value))))
459 (sb-pcl::doplist (allocation slots) plist
460 (format stream "~%Slots with ~S allocation:" allocation)
461 (dolist (slotd (nreverse slots))
462 (describe-slot
463 (sb-mop:slot-definition-name slotd)
464 (sb-pcl::slot-value-or-default object (sb-mop:slot-definition-name slotd))))))
465 (unless slotds
466 (format stream "~@:_No slots."))
467 (terpri stream)))
469 (defun quiet-doc (object type)
470 (handler-bind ((warning #'muffle-warning))
471 (documentation object type)))
473 (defun describe-documentation (object type stream &optional undoc newline)
474 (let ((doc (quiet-doc object type)))
475 (cond (doc
476 (format stream "~@:_Documentation:~@:_")
477 (pprint-logical-block (stream nil :per-line-prefix " ")
478 (princ doc stream)))
479 (undoc
480 (format stream "~@:_(undocumented)")))
481 (when newline
482 (pprint-newline :mandatory stream))))
484 (defun describe-stuff (label list stream &key (escape t))
485 (when list
486 (if escape
487 (format stream "~@:_~A:~@<~;~{ ~S~^,~:_~}~;~:>" label list)
488 (format stream "~@:_~A:~@<~;~{ ~A~^,~:_~}~;~:>" label list))))
490 (defun describe-variable (name stream)
491 (let* ((kind (info :variable :kind name))
492 (wot (ecase kind
493 (:special "a special variable")
494 (:macro "a symbol macro")
495 (:constant "a constant variable")
496 (:global "a global variable")
497 (:unknown "an undefined variable")
498 (:alien "an alien variable"))))
499 (when (and (eq kind :unknown) (not (boundp name)))
500 (return-from describe-variable))
501 (pprint-logical-block (stream nil)
502 (format stream "~@:_~A names ~A:" name wot)
503 (pprint-indent :block 2 stream)
504 (describe-deprecation 'variable name stream)
505 (when (eq (info :variable :where-from name) :declared)
506 (format stream "~@:_Declared type: ~/sb-impl:print-type/"
507 (info :variable :type name)))
508 (when (info :variable :always-bound name)
509 (format stream "~@:_Declared always-bound."))
510 (cond
511 ((eq kind :alien)
512 (let ((info (info :variable :alien-info name)))
513 (format stream "~@:_Value: ~S" (eval name))
514 (format stream "~@:_Type: ~S"
515 (sb-alien-internals:unparse-alien-type
516 (sb-alien::heap-alien-info-type info)))
517 (format stream "~@:_Address: #x~8,'0X"
518 (sap-int (sb-alien::heap-alien-info-sap info)))))
519 ((eq kind :macro)
520 (let ((expansion (info :variable :macro-expansion name)))
521 (format stream "~@:_Expansion: ~S" expansion)))
522 ((boundp name)
523 (format stream "~:@_Value: ~S" (symbol-value name)))
524 ((not (eq kind :unknown))
525 (format stream "~:@_Currently unbound.")))
526 (describe-documentation name 'variable stream)
527 (terpri stream))))
529 (defun describe-lambda-list (lambda-list stream)
530 (let ((*print-circle* nil)
531 (*print-level* 24)
532 (*print-length* 24))
533 (format stream "~@:_Lambda-list: ~:A" lambda-list)))
535 (defun describe-function-source (function stream)
536 (if (compiled-function-p (the function function))
537 (let* ((code (fun-code-header (%fun-fun function)))
538 (info (sb-kernel:%code-debug-info code)))
539 (when info
540 (let ((source (sb-c::debug-info-source info)))
541 (when source
542 (let ((namestring (sb-c::debug-source-namestring source)))
543 ;; This used to also report the times the source was created
544 ;; and compiled, but that seems more like noise than useful
545 ;; information -- but FWIW that are to be had as
546 ;; SB-C::DEBUG-SOUCE-CREATED/COMPILED.
547 (cond (namestring
548 (format stream "~@:_Source file: ~A" namestring))
549 ((sb-di:debug-source-form source)
550 (format stream "~@:_Source form:~@:_ ~S"
551 (sb-di:debug-source-form source)))))))))
552 (let ((source
553 (typecase function
554 #+sb-eval
555 (sb-eval:interpreted-function
556 (sb-eval:interpreted-function-source-location function))
557 #+sb-fasteval
558 (sb-interpreter:interpreted-function
559 (sb-interpreter:fun-source-location function)))))
560 (when source
561 (let ((namestring (sb-c:definition-source-location-namestring source)))
562 (when namestring
563 (format stream "~@:_Source file: ~A" namestring)))))))
565 (defun describe-function (name function stream)
566 (let ((name (if function (%fun-name function) name)))
567 (if (not (or function (and (legal-fun-name-p name) (fboundp name))))
568 ;; Not defined, but possibly the type is declared, or we have
569 ;; compiled calls to it.
570 (when (legal-fun-name-p name)
571 (multiple-value-bind (from sure) (info :function :where-from name)
572 (when (or (eq :declared from) (and sure (eq :assumed from)))
573 (pprint-logical-block (stream nil)
574 (format stream "~%~A names an undefined function" name)
575 (pprint-indent :block 2 stream)
576 (format stream "~@:_~:(~A~) type: ~/sb-impl:print-type/"
577 from (proclaimed-ftype name))))))
578 ;; Defined.
579 (multiple-value-bind (fun what lambda-list derived-type declared-type
580 inline methods)
581 (cond ((and (not function) (symbolp name) (special-operator-p name))
582 ;; The function in the symbol is irrelevant.
583 ;; Use the def-ir1-translator function for source location.
584 (let ((fun (info :function :ir1-convert name)))
585 (values fun "a special operator" (%fun-lambda-list fun))))
586 ((and (not function) (symbolp name) (macro-function name))
587 (let ((fun (macro-function name)))
588 (values fun "a macro" (%fun-lambda-list fun))))
590 (let* ((fun (or function (fdefinition name)))
591 (derived-type (and function
592 (%fun-type function)))
593 (legal-name-p (legal-fun-name-p name))
594 (ctype (and legal-name-p
595 (proclaimed-ftype name)))
596 (type (and ctype (type-specifier ctype)))
597 (from (and legal-name-p
598 (info :function :where-from name)))
599 declared-type)
600 (cond ((not type))
601 ((eq from :declared)
602 (setf declared-type type))
603 ((and (not derived-type)
604 (member from '(:defined-method :defined)))
605 (setf derived-type type)))
606 (unless derived-type
607 (setf derived-type (%fun-type fun)))
608 (if (typep fun 'standard-generic-function)
609 (values fun
610 "a generic function"
611 (sb-mop:generic-function-lambda-list fun)
612 derived-type
613 declared-type
615 (or (sb-mop:generic-function-methods fun)
616 :none))
617 (values fun
618 (if (compiled-function-p fun)
619 "a compiled function"
620 "an interpreted function")
621 (%fun-lambda-list fun)
622 derived-type
623 declared-type
624 (cons
625 (info :function :inlinep name)
626 (info :function :inline-expansion-designator
627 name)))))))
628 (pprint-logical-block (stream nil)
629 (unless function
630 (format stream "~%~A names ~A:" name what)
631 (pprint-indent :block 2 stream))
632 (describe-deprecation 'function name stream)
633 (describe-lambda-list lambda-list stream)
634 (when declared-type
635 (format stream "~@:_Declared type: ~
636 ~/sb-impl:print-type-specifier/"
637 declared-type))
638 (when (and derived-type
639 (not (equal declared-type derived-type)))
640 (format stream "~@:_Derived type: ~
641 ~/sb-impl:print-type-specifier/"
642 derived-type))
643 (describe-documentation name 'function stream)
644 (when (car inline)
645 (format stream "~@:_Inline proclamation: ~
646 ~A (~:[no ~;~]inline expansion available)"
647 (car inline)
648 (cdr inline)))
649 (awhen (info :function :info name)
650 (awhen (sb-c::decode-ir1-attributes (sb-c::fun-info-attributes it))
651 (format stream "~@:_Known attributes: ~(~{~A~^, ~}~)" it)))
652 (when methods
653 (format stream "~@:_Method-combination: ~S"
654 (sb-pcl::method-combination-type-name
655 (sb-pcl:generic-function-method-combination fun)))
656 (cond ((eq :none methods)
657 (format stream "~@:_No methods."))
659 (pprint-newline :mandatory stream)
660 (pprint-logical-block (stream nil)
661 (format stream "Methods:")
662 (dolist (method methods)
663 (pprint-indent :block 2 stream)
664 (format stream "~@:_(~A ~{~S ~}~:S)"
665 name
666 (method-qualifiers method)
667 (sb-pcl::unparse-specializers
668 fun (sb-mop:method-specializers method)))
669 (pprint-indent :block 4 stream)
670 (describe-documentation method t stream nil))))))
671 (describe-function-source fun stream)
672 (terpri stream)))))
673 (unless function
674 (awhen (and (legal-fun-name-p name) (compiler-macro-function name))
675 (pprint-logical-block (stream nil)
676 (format stream "~@:_~A has a compiler-macro:" name)
677 (pprint-indent :block 2 stream)
678 (describe-documentation it t stream)
679 (describe-function-source it stream))
680 (terpri stream))
681 (when (and (consp name) (eq 'setf (car name)) (not (cddr name)))
682 (let* ((name2 (second name))
683 (expander (info :setf :expander name2)))
684 (cond ((typep expander '(and symbol (not null)))
685 (pprint-logical-block (stream nil)
686 (format stream "~&~A has setf-expansion: ~S"
687 name expander)
688 (pprint-indent :block 2 stream)
689 (describe-documentation name2 'setf stream))
690 (terpri stream))
691 (expander
692 (when (listp expander)
693 (setq expander (cdr expander)))
694 (pprint-logical-block (stream nil)
695 (format stream "~&~A has a complex setf-expansion:"
696 name)
697 (pprint-indent :block 2 stream)
698 (describe-lambda-list (%fun-lambda-list expander) stream)
699 (describe-documentation name2 'setf stream t)
700 (describe-function-source expander stream))
701 (terpri stream)))))
702 (when (symbolp name)
703 (describe-function `(setf ,name) nil stream))))
705 (defun describe-type (name stream)
706 (let* ((kind (info :type :kind name))
707 (fun (and kind (info :type :expander name)))
708 (fun (if (listp fun) (car fun) fun)))
709 (when fun
710 (pprint-newline :mandatory stream)
711 (pprint-logical-block (stream nil)
712 (format stream "~@:_~A names a ~@[primitive~* ~]type-specifier:"
713 name (eq kind :primitive))
714 (pprint-indent :block 2 stream)
715 (describe-deprecation 'type name stream)
716 (describe-documentation name 'type stream (eq t fun))
717 (when (functionp fun)
718 (describe-lambda-list (%fun-lambda-list fun) stream)
719 (multiple-value-bind (expansion ok)
720 (handler-case (typexpand-1 name)
721 (error () (values nil nil)))
722 (when ok
723 (format stream "~@:_Expansion: ~S" expansion)))))
724 (terpri stream))))