0.9.2.18: various error &co reporting improvements and build tweaks
[sbcl.git] / src / code / condition.lisp
1 ;;;; stuff originally from CMU CL's error.lisp which can or should
2 ;;;; come late (mostly related to the CONDITION class itself)
3 ;;;;
4
5 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; more information.
7 ;;;;
8 ;;;; This software is derived from the CMU CL system, which was
9 ;;;; written at Carnegie Mellon University and released into the
10 ;;;; public domain. The software is in the public domain and is
11 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
12 ;;;; files for more information.
13
14 (in-package "SB!KERNEL")
15 \f
16 ;;;; miscellaneous support utilities
17
18 ;;; Signalling an error when trying to print an error condition is
19 ;;; generally a PITA, so whatever the failure encountered when
20 ;;; wondering about FILE-POSITION within a condition printer, 'tis
21 ;;; better silently to give up than to try to complain. 
22 (defun file-position-or-nil-for-error (stream &optional (pos nil posp))
23   ;; Arguably FILE-POSITION shouldn't be signalling errors at all; but
24   ;; "NIL if this cannot be determined" in the ANSI spec doesn't seem
25   ;; absolutely unambiguously to prohibit errors when, e.g., STREAM
26   ;; has been closed so that FILE-POSITION is a nonsense question. So
27   ;; my (WHN) impression is that the conservative approach is to
28   ;; IGNORE-ERRORS. (I encountered this failure from within a homebrew
29   ;; defsystemish operation where the ERROR-STREAM had been CL:CLOSEd,
30   ;; I think by nonlocally exiting through a WITH-OPEN-FILE, by the
31   ;; time an error was reported.)
32   (if posp
33       (ignore-errors (file-position stream pos))
34       (ignore-errors (file-position stream))))
35 \f
36 ;;;; the CONDITION class
37
38 (/show0 "condition.lisp 20")
39
40 (eval-when (:compile-toplevel :load-toplevel :execute)
41
42 (/show0 "condition.lisp 24")
43
44 (def!struct (condition-classoid (:include slot-classoid)
45                                 (:constructor make-condition-classoid))
46   ;; list of CONDITION-SLOT structures for the direct slots of this
47   ;; class
48   (slots nil :type list)
49   ;; list of CONDITION-SLOT structures for all of the effective class
50   ;; slots of this class
51   (class-slots nil :type list)
52   ;; report function or NIL
53   (report nil :type (or function null))
54   ;; list of alternating initargs and initforms
55   (default-initargs () :type list)
56   ;; class precedence list as a list of CLASS objects, with all
57   ;; non-CONDITION classes removed
58   (cpl () :type list)
59   ;; a list of all the effective instance allocation slots of this
60   ;; class that have a non-constant initform or default-initarg.
61   ;; Values for these slots must be computed in the dynamic
62   ;; environment of MAKE-CONDITION.
63   (hairy-slots nil :type list))
64
65 (/show0 "condition.lisp 49")
66
67 ) ; EVAL-WHEN
68
69 (!defstruct-with-alternate-metaclass condition
70   :slot-names (actual-initargs assigned-slots)
71   :boa-constructor %make-condition-object
72   :superclass-name instance
73   :metaclass-name condition-classoid
74   :metaclass-constructor make-condition-classoid
75   :dd-type structure)
76
77 (defun make-condition-object (actual-initargs)
78   (%make-condition-object actual-initargs nil))
79
80 (defstruct (condition-slot (:copier nil))
81   (name (missing-arg) :type symbol)
82   ;; list of all applicable initargs
83   (initargs (missing-arg) :type list)
84   ;; names of reader and writer functions
85   (readers (missing-arg) :type list)
86   (writers (missing-arg) :type list)
87   ;; true if :INITFORM was specified
88   (initform-p (missing-arg) :type (member t nil))
89   ;; If this is a function, call it with no args. Otherwise, it's the
90   ;; actual value.
91   (initform (missing-arg) :type t)
92   ;; allocation of this slot, or NIL until defaulted
93   (allocation nil :type (member :instance :class nil))
94   ;; If ALLOCATION is :CLASS, this is a cons whose car holds the value.
95   (cell nil :type (or cons null))
96   ;; slot documentation
97   (documentation nil :type (or string null)))
98
99 ;;; KLUDGE: It's not clear to me why CONDITION-CLASS has itself listed
100 ;;; in its CPL, while other classes derived from CONDITION-CLASS don't
101 ;;; have themselves listed in their CPLs. This behavior is inherited
102 ;;; from CMU CL, and didn't seem to be explained there, and I haven't
103 ;;; figured out whether it's right. -- WHN 19990612
104 (eval-when (:compile-toplevel :load-toplevel :execute)
105   (/show0 "condition.lisp 103")
106   (let ((condition-class (locally
107                            ;; KLUDGE: There's a DEFTRANSFORM
108                            ;; FIND-CLASSOID for constant class names
109                            ;; which creates fast but
110                            ;; non-cold-loadable, non-compact code. In
111                            ;; this context, we'd rather have compact,
112                            ;; cold-loadable code. -- WHN 19990928
113                            (declare (notinline find-classoid))
114                            (find-classoid 'condition))))
115     (setf (condition-classoid-cpl condition-class)
116           (list condition-class)))
117   (/show0 "condition.lisp 103"))
118
119 (setf (condition-classoid-report (locally
120                                    ;; KLUDGE: There's a DEFTRANSFORM
121                                    ;; FIND-CLASSOID for constant class
122                                    ;; names which creates fast but
123                                    ;; non-cold-loadable, non-compact
124                                    ;; code. In this context, we'd
125                                    ;; rather have compact,
126                                    ;; cold-loadable code. -- WHN
127                                    ;; 19990928
128                                    (declare (notinline find-classoid))
129                                    (find-classoid 'condition)))
130       (lambda (cond stream)
131         (format stream "Condition ~S was signalled." (type-of cond))))
132
133 (eval-when (:compile-toplevel :load-toplevel :execute)
134
135 (defun find-condition-layout (name parent-types)
136   (let* ((cpl (remove-duplicates
137                (reverse
138                 (reduce #'append
139                         (mapcar (lambda (x)
140                                   (condition-classoid-cpl
141                                    (find-classoid x)))
142                                 parent-types)))))
143          (cond-layout (info :type :compiler-layout 'condition))
144          (olayout (info :type :compiler-layout name))
145          ;; FIXME: Does this do the right thing in case of multiple
146          ;; inheritance? A quick look at DEFINE-CONDITION didn't make
147          ;; it obvious what ANSI intends to be done in the case of
148          ;; multiple inheritance, so it's not actually clear what the
149          ;; right thing is..
150          (new-inherits
151           (order-layout-inherits (concatenate 'simple-vector
152                                               (layout-inherits cond-layout)
153                                               (mapcar #'classoid-layout cpl)))))
154     (if (and olayout
155              (not (mismatch (layout-inherits olayout) new-inherits)))
156         olayout
157         (make-layout :classoid (make-undefined-classoid name)
158                      :inherits new-inherits
159                      :depthoid -1
160                      :length (layout-length cond-layout)))))
161
162 ) ; EVAL-WHEN
163
164 ;;; FIXME: ANSI's definition of DEFINE-CONDITION says
165 ;;;   Condition reporting is mediated through the PRINT-OBJECT method
166 ;;;   for the condition type in question, with *PRINT-ESCAPE* always
167 ;;;   being nil. Specifying (:REPORT REPORT-NAME) in the definition of
168 ;;;   a condition type C is equivalent to:
169 ;;;     (defmethod print-object ((x c) stream)
170 ;;;       (if *print-escape* (call-next-method) (report-name x stream)))
171 ;;; The current code doesn't seem to quite match that.
172 (def!method print-object ((x condition) stream)
173   (if *print-escape*
174       (print-unreadable-object (x stream :type t :identity t))
175       ;; KLUDGE: A comment from CMU CL here said
176       ;;   7/13/98 BUG? CPL is not sorted and results here depend on order of
177       ;;   superclasses in define-condition call!
178       (dolist (class (condition-classoid-cpl (classoid-of x))
179                      (error "no REPORT? shouldn't happen!"))
180         (let ((report (condition-classoid-report class)))
181           (when report
182             (return (funcall report x stream)))))))
183 \f
184 ;;;; slots of CONDITION objects
185
186 (defvar *empty-condition-slot* '(empty))
187
188 (defun find-slot-default (class slot)
189   (let ((initargs (condition-slot-initargs slot))
190         (cpl (condition-classoid-cpl class)))
191     (dolist (class cpl)
192       (let ((default-initargs (condition-classoid-default-initargs class)))
193         (dolist (initarg initargs)
194           (let ((val (getf default-initargs initarg *empty-condition-slot*)))
195             (unless (eq val *empty-condition-slot*)
196               (return-from find-slot-default
197                            (if (functionp val)
198                                (funcall val)
199                                val)))))))
200
201     (if (condition-slot-initform-p slot)
202         (let ((initform (condition-slot-initform slot)))
203           (if (functionp initform)
204               (funcall initform)
205               initform))
206         (error "unbound condition slot: ~S" (condition-slot-name slot)))))
207
208 (defun find-condition-class-slot (condition-class slot-name)
209   (dolist (sclass
210            (condition-classoid-cpl condition-class)
211            (error "There is no slot named ~S in ~S."
212                   slot-name condition-class))
213     (dolist (slot (condition-classoid-slots sclass))
214       (when (eq (condition-slot-name slot) slot-name)
215         (return-from find-condition-class-slot slot)))))
216
217 (defun condition-writer-function (condition new-value name)
218   (dolist (cslot (condition-classoid-class-slots
219                   (layout-classoid (%instance-layout condition)))
220                  (setf (getf (condition-assigned-slots condition) name)
221                        new-value))
222     (when (eq (condition-slot-name cslot) name)
223       (return (setf (car (condition-slot-cell cslot)) new-value)))))
224
225 (defun condition-reader-function (condition name)
226   (let ((class (layout-classoid (%instance-layout condition))))
227     (dolist (cslot (condition-classoid-class-slots class))
228       (when (eq (condition-slot-name cslot) name)
229         (return-from condition-reader-function
230                      (car (condition-slot-cell cslot)))))
231     (let ((val (getf (condition-assigned-slots condition) name
232                      *empty-condition-slot*)))
233       (if (eq val *empty-condition-slot*)
234           (let ((actual-initargs (condition-actual-initargs condition))
235                 (slot (find-condition-class-slot class name)))
236             (unless slot
237               (error "missing slot ~S of ~S" name condition))
238             (do ((initargs actual-initargs (cddr initargs)))
239                 ((endp initargs)
240                  (setf (getf (condition-assigned-slots condition) name)
241                        (find-slot-default class slot)))
242               (when (member (car initargs) (condition-slot-initargs slot))
243                 (return-from condition-reader-function
244                   (setf (getf (condition-assigned-slots condition)
245                               name)
246                         (cadr initargs))))))
247           val))))
248 \f
249 ;;;; MAKE-CONDITION
250
251 (defun make-condition (thing &rest args)
252   #!+sb-doc
253   "Make an instance of a condition object using the specified initargs."
254   ;; Note: ANSI specifies no exceptional situations in this function.
255   ;; signalling simple-type-error would not be wrong.
256   (let* ((thing (or (and (symbolp thing) (find-classoid thing nil))
257                     thing))
258          (class (typecase thing
259                   (condition-classoid thing)
260                   (classoid
261                    (error 'simple-type-error
262                           :datum thing
263                           :expected-type 'condition-class
264                           :format-control "~S is not a condition class."
265                           :format-arguments (list thing)))
266                   (t
267                    (error 'simple-type-error
268                           :datum thing
269                           :expected-type 'condition-class
270                           :format-control "bad thing for class argument:~%  ~S"
271                           :format-arguments (list thing)))))
272          (res (make-condition-object args)))
273     (setf (%instance-layout res) (classoid-layout class))
274     ;; Set any class slots with initargs present in this call.
275     (dolist (cslot (condition-classoid-class-slots class))
276       (dolist (initarg (condition-slot-initargs cslot))
277         (let ((val (getf args initarg *empty-condition-slot*)))
278           (unless (eq val *empty-condition-slot*)
279             (setf (car (condition-slot-cell cslot)) val)))))
280     ;; Default any slots with non-constant defaults now.
281     (dolist (hslot (condition-classoid-hairy-slots class))
282       (when (dolist (initarg (condition-slot-initargs hslot) t)
283               (unless (eq (getf args initarg *empty-condition-slot*)
284                           *empty-condition-slot*)
285                 (return nil)))
286         (setf (getf (condition-assigned-slots res) (condition-slot-name hslot))
287               (find-slot-default class hslot))))
288     res))
289 \f
290 ;;;; DEFINE-CONDITION
291
292 (eval-when (:compile-toplevel :load-toplevel :execute)
293 (defun %compiler-define-condition (name direct-supers layout
294                                    all-readers all-writers)
295   (with-single-package-locked-error 
296       (:symbol name "defining ~A as a condition")
297     (sb!xc:proclaim `(ftype (function (t) t) ,@all-readers))
298     (sb!xc:proclaim `(ftype (function (t t) t) ,@all-writers))
299     (multiple-value-bind (class old-layout)
300         (insured-find-classoid name
301                                #'condition-classoid-p
302                                #'make-condition-classoid)
303       (setf (layout-classoid layout) class)
304       (setf (classoid-direct-superclasses class)
305             (mapcar #'find-classoid direct-supers))
306       (cond ((not old-layout)
307              (register-layout layout))
308             ((not *type-system-initialized*)
309              (setf (layout-classoid old-layout) class)
310              (setq layout old-layout)
311              (unless (eq (classoid-layout class) layout)
312                (register-layout layout)))
313             ((redefine-layout-warning "current"
314                                       old-layout
315                                       "new"
316                                       (layout-length layout)
317                                       (layout-inherits layout)
318                                       (layout-depthoid layout)
319                                       (layout-n-untagged-slots layout))
320              (register-layout layout :invalidate t))
321             ((not (classoid-layout class))
322              (register-layout layout)))
323       
324       (setf (layout-info layout)
325             (locally
326                 ;; KLUDGE: There's a FIND-CLASS DEFTRANSFORM for constant class
327                 ;; names which creates fast but non-cold-loadable, non-compact
328                 ;; code. In this context, we'd rather have compact, cold-loadable
329                 ;; code. -- WHN 19990928
330                 (declare (notinline find-classoid))
331               (layout-info (classoid-layout (find-classoid 'condition)))))
332       
333       (setf (find-classoid name) class)
334       
335       ;; Initialize CPL slot.
336       (setf (condition-classoid-cpl class)
337             (remove-if-not #'condition-classoid-p 
338                            (std-compute-class-precedence-list class)))))
339   (values))
340 ) ; EVAL-WHEN
341
342 ;;; Compute the effective slots of CLASS, copying inherited slots and
343 ;;; destructively modifying direct slots.
344 ;;;
345 ;;; FIXME: It'd be nice to explain why it's OK to destructively modify
346 ;;; direct slots. Presumably it follows from the semantics of
347 ;;; inheritance and redefinition of conditions, but finding the cite
348 ;;; and documenting it here would be good. (Or, if this is not in fact
349 ;;; ANSI-compliant, fixing it would also be good.:-)
350 (defun compute-effective-slots (class)
351   (collect ((res (copy-list (condition-classoid-slots class))))
352     (dolist (sclass (cdr (condition-classoid-cpl class)))
353       (dolist (sslot (condition-classoid-slots sclass))
354         (let ((found (find (condition-slot-name sslot) (res)
355                            :key #'condition-slot-name)))
356           (cond (found
357                  (setf (condition-slot-initargs found)
358                        (union (condition-slot-initargs found)
359                               (condition-slot-initargs sslot)))
360                  (unless (condition-slot-initform-p found)
361                    (setf (condition-slot-initform-p found)
362                          (condition-slot-initform-p sslot))
363                    (setf (condition-slot-initform found)
364                          (condition-slot-initform sslot)))
365                  (unless (condition-slot-allocation found)
366                    (setf (condition-slot-allocation found)
367                          (condition-slot-allocation sslot))))
368                 (t
369                  (res (copy-structure sslot)))))))
370     (res)))
371
372 ;;; Early definitions of slot accessor creators.
373 ;;;
374 ;;; Slot accessors must be generic functions, but ANSI does not seem
375 ;;; to specify any of them, and we cannot support it before end of
376 ;;; warm init. So we use ordinary functions inside SBCL, and switch to
377 ;;; GFs only at the end of building.
378 (declaim (notinline install-condition-slot-reader
379                     install-condition-slot-writer))
380 (defun install-condition-slot-reader (name condition slot-name)
381   (declare (ignore condition))
382   (setf (fdefinition name)
383         (lambda (condition)
384           (condition-reader-function condition slot-name))))
385 (defun install-condition-slot-writer (name condition slot-name)
386   (declare (ignore condition))
387   (setf (fdefinition name)
388         (lambda (new-value condition)
389           (condition-writer-function condition new-value slot-name))))
390
391 (defun %define-condition (name parent-types layout slots documentation
392                           report default-initargs all-readers all-writers)
393   (with-single-package-locked-error 
394       (:symbol name "defining ~A as a condition")
395     (%compiler-define-condition name parent-types layout all-readers all-writers)
396     (let ((class (find-classoid name)))
397       (setf (condition-classoid-slots class) slots)
398       (setf (condition-classoid-report class) report)
399       (setf (condition-classoid-default-initargs class) default-initargs)
400       (setf (fdocumentation name 'type) documentation)
401       
402       (dolist (slot slots)
403         
404         ;; Set up reader and writer functions.
405         (let ((slot-name (condition-slot-name slot)))
406           (dolist (reader (condition-slot-readers slot))
407             (install-condition-slot-reader reader name slot-name))
408           (dolist (writer (condition-slot-writers slot))
409             (install-condition-slot-writer writer name slot-name))))
410       
411       ;; Compute effective slots and set up the class and hairy slots
412       ;; (subsets of the effective slots.)
413       (let ((eslots (compute-effective-slots class))
414             (e-def-initargs
415              (reduce #'append
416                      (mapcar #'condition-classoid-default-initargs
417                            (condition-classoid-cpl class)))))
418         (dolist (slot eslots)
419           (ecase (condition-slot-allocation slot)
420             (:class
421              (unless (condition-slot-cell slot)
422                (setf (condition-slot-cell slot)
423                      (list (if (condition-slot-initform-p slot)
424                                (let ((initform (condition-slot-initform slot)))
425                                  (if (functionp initform)
426                                      (funcall initform)
427                                      initform))
428                                *empty-condition-slot*))))
429              (push slot (condition-classoid-class-slots class)))
430             ((:instance nil)
431              (setf (condition-slot-allocation slot) :instance)
432              (when (or (functionp (condition-slot-initform slot))
433                        (dolist (initarg (condition-slot-initargs slot) nil)
434                          (when (functionp (getf e-def-initargs initarg))
435                            (return t))))
436                (push slot (condition-classoid-hairy-slots class))))))))
437     name))
438
439 (defmacro define-condition (name (&rest parent-types) (&rest slot-specs)
440                                  &body options)
441   #!+sb-doc
442   "DEFINE-CONDITION Name (Parent-Type*) (Slot-Spec*) Option*
443    Define NAME as a condition type. This new type inherits slots and its
444    report function from the specified PARENT-TYPEs. A slot spec is a list of:
445      (slot-name :reader <rname> :initarg <iname> {Option Value}*
446
447    The DEFINE-CLASS slot options :ALLOCATION, :INITFORM, [slot] :DOCUMENTATION
448    and :TYPE and the overall options :DEFAULT-INITARGS and
449    [type] :DOCUMENTATION are also allowed.
450
451    The :REPORT option is peculiar to DEFINE-CONDITION. Its argument is either
452    a string or a two-argument lambda or function name. If a function, the
453    function is called with the condition and stream to report the condition.
454    If a string, the string is printed.
455
456    Condition types are classes, but (as allowed by ANSI and not as described in
457    CLtL2) are neither STANDARD-OBJECTs nor STRUCTURE-OBJECTs. WITH-SLOTS and
458    SLOT-VALUE may not be used on condition objects."
459   (let* ((parent-types (or parent-types '(condition)))
460          (layout (find-condition-layout name parent-types))
461          (documentation nil)
462          (report nil)
463          (default-initargs ()))
464     (collect ((slots)
465               (all-readers nil append)
466               (all-writers nil append))
467       (dolist (spec slot-specs)
468         (when (keywordp spec)
469           (warn "Keyword slot name indicates probable syntax error:~%  ~S"
470                 spec))
471         (let* ((spec (if (consp spec) spec (list spec)))
472                (slot-name (first spec))
473                (allocation :instance)
474                (initform-p nil)
475                documentation
476                initform)
477           (collect ((initargs)
478                     (readers)
479                     (writers))
480             (do ((options (rest spec) (cddr options)))
481                 ((null options))
482               (unless (and (consp options) (consp (cdr options)))
483                 (error "malformed condition slot spec:~%  ~S." spec))
484               (let ((arg (second options)))
485                 (case (first options)
486                   (:reader (readers arg))
487                   (:writer (writers arg))
488                   (:accessor
489                    (readers arg)
490                    (writers `(setf ,arg)))
491                   (:initform
492                    (when initform-p
493                      (error "more than one :INITFORM in ~S" spec))
494                    (setq initform-p t)
495                    (setq initform arg))
496                   (:initarg (initargs arg))
497                   (:allocation
498                    (setq allocation arg))
499                   (:documentation
500                    (when documentation
501                      (error "more than one :DOCUMENTATION in ~S" spec))
502                    (unless (stringp arg)
503                      (error "slot :DOCUMENTATION argument is not a string: ~S"
504                             arg))
505                    (setq documentation arg))
506                   (:type)
507                   (t
508                    (error "unknown slot option:~%  ~S" (first options))))))
509
510             (all-readers (readers))
511             (all-writers (writers))
512             (slots `(make-condition-slot
513                      :name ',slot-name
514                      :initargs ',(initargs)
515                      :readers ',(readers)
516                      :writers ',(writers)
517                      :initform-p ',initform-p
518                      :documentation ',documentation
519                      :initform
520                      ,(if (constantp initform)
521                           `',(eval initform)
522                           `#'(lambda () ,initform)))))))
523
524       (dolist (option options)
525         (unless (consp option)
526           (error "bad option:~%  ~S" option))
527         (case (first option)
528           (:documentation (setq documentation (second option)))
529           (:report
530            (let ((arg (second option)))
531              (setq report
532                    (if (stringp arg)
533                        `#'(lambda (condition stream)
534                           (declare (ignore condition))
535                           (write-string ,arg stream))
536                        `#'(lambda (condition stream)
537                           (funcall #',arg condition stream))))))
538           (:default-initargs
539            (do ((initargs (rest option) (cddr initargs)))
540                ((endp initargs))
541              (let ((val (second initargs)))
542                (setq default-initargs
543                      (list* `',(first initargs)
544                             (if (constantp val)
545                                 `',(eval val)
546                                 `#'(lambda () ,val))
547                             default-initargs)))))
548           (t
549            (error "unknown option: ~S" (first option)))))
550
551       `(progn
552          (eval-when (:compile-toplevel)
553            (%compiler-define-condition ',name ',parent-types ',layout
554                                        ',(all-readers) ',(all-writers)))
555          (eval-when (:load-toplevel :execute)
556            (%define-condition ',name
557                               ',parent-types
558                               ',layout
559                               (list ,@(slots))
560                               ,documentation
561                               ,report
562                               (list ,@default-initargs)
563                               ',(all-readers)
564                               ',(all-writers)))))))
565 \f
566 ;;;; DESCRIBE on CONDITIONs
567
568 ;;; a function to be used as the guts of DESCRIBE-OBJECT (CONDITION T)
569 ;;; eventually (once we get CLOS up and running so that we can define
570 ;;; methods)
571 (defun describe-condition (condition stream)
572   (format stream
573           "~&~@<~S ~_is a ~S. ~_Its slot values are ~_~S.~:>~%"
574           condition
575           (type-of condition)
576           (concatenate 'list
577                        (condition-actual-initargs condition)
578                        (condition-assigned-slots condition))))
579 \f
580 ;;;; various CONDITIONs specified by ANSI
581
582 (define-condition serious-condition (condition) ())
583
584 (define-condition error (serious-condition) ())
585
586 (define-condition warning (condition) ())
587 (define-condition style-warning (warning) ())
588
589 (defun simple-condition-printer (condition stream)
590   (apply #'format
591          stream
592          (simple-condition-format-control condition)
593          (simple-condition-format-arguments condition)))
594
595 (define-condition simple-condition ()
596   ((format-control :reader simple-condition-format-control
597                    :initarg :format-control
598                    :type format-control)
599    (format-arguments :reader simple-condition-format-arguments
600                      :initarg :format-arguments
601                      :initform '()
602                      :type list))
603   (:report simple-condition-printer))
604
605 (define-condition simple-warning (simple-condition warning) ())
606
607 (define-condition simple-error (simple-condition error) ())
608
609 ;;; not specified by ANSI, but too useful not to have around.
610 (define-condition simple-style-warning (simple-condition style-warning) ())
611
612 (define-condition storage-condition (serious-condition) ())
613
614 (define-condition type-error (error)
615   ((datum :reader type-error-datum :initarg :datum)
616    (expected-type :reader type-error-expected-type :initarg :expected-type))
617   (:report
618    (lambda (condition stream)
619      (format stream
620              "~@<The value ~2I~:_~S ~I~_is not of type ~2I~_~S.~:>"
621              (type-error-datum condition)
622              (type-error-expected-type condition)))))
623
624 (define-condition simple-type-error (simple-condition type-error) ())
625
626 (define-condition program-error (error) ())
627 (define-condition parse-error   (error) ())
628 (define-condition control-error (error) ())
629 (define-condition stream-error  (error)
630   ((stream :reader stream-error-stream :initarg :stream)))
631
632 (define-condition end-of-file (stream-error) ()
633   (:report
634    (lambda (condition stream)
635      (format stream
636              "end of file on ~S"
637              (stream-error-stream condition)))))
638
639 (define-condition file-error (error)
640   ((pathname :reader file-error-pathname :initarg :pathname))
641   (:report
642    (lambda (condition stream)
643      (format stream "error on file ~S" (file-error-pathname condition)))))
644
645 (define-condition package-error (error)
646   ((package :reader package-error-package :initarg :package)))
647
648 (define-condition cell-error (error)
649   ((name :reader cell-error-name :initarg :name)))
650
651 (def!method print-object ((condition cell-error) stream)
652   (if *print-escape*
653       (print-unreadable-object (condition stream :type t :identity t)
654         (princ (cell-error-name condition) stream))
655       (call-next-method)))
656
657 (define-condition unbound-variable (cell-error) ()
658   (:report
659    (lambda (condition stream)
660      (format stream
661              "The variable ~S is unbound."
662              (cell-error-name condition)))))
663
664 (define-condition undefined-function (cell-error) ()
665   (:report
666    (lambda (condition stream)
667      (format stream
668              "The function ~S is undefined."
669              (cell-error-name condition)))))
670
671 (define-condition special-form-function (undefined-function) ()
672   (:report
673    (lambda (condition stream)
674      (format stream
675              "Cannot FUNCALL the SYMBOL-FUNCTION of special operator ~S."
676              (cell-error-name condition)))))
677
678 (define-condition arithmetic-error (error)
679   ((operation :reader arithmetic-error-operation
680               :initarg :operation
681               :initform nil)
682    (operands :reader arithmetic-error-operands
683              :initarg :operands))
684   (:report (lambda (condition stream)
685              (format stream
686                      "arithmetic error ~S signalled"
687                      (type-of condition))
688              (when (arithmetic-error-operation condition)
689                (format stream
690                        "~%Operation was ~S, operands ~S."
691                        (arithmetic-error-operation condition)
692                        (arithmetic-error-operands condition))))))
693
694 (define-condition division-by-zero         (arithmetic-error) ())
695 (define-condition floating-point-overflow  (arithmetic-error) ())
696 (define-condition floating-point-underflow (arithmetic-error) ())
697 (define-condition floating-point-inexact   (arithmetic-error) ())
698 (define-condition floating-point-invalid-operation (arithmetic-error) ())
699
700 (define-condition print-not-readable (error)
701   ((object :reader print-not-readable-object :initarg :object))
702   (:report
703    (lambda (condition stream)
704      (let ((obj (print-not-readable-object condition))
705            (*print-array* nil))
706        (format stream "~S cannot be printed readably." obj)))))
707
708 (define-condition reader-error (parse-error stream-error)
709   ((format-control
710     :reader reader-error-format-control
711     :initarg :format-control)
712    (format-arguments
713     :reader reader-error-format-arguments
714     :initarg :format-arguments
715     :initform '()))
716   (:report
717    (lambda (condition stream)
718      (let* ((error-stream (stream-error-stream condition))
719             (pos (file-position-or-nil-for-error error-stream)))
720        (let (lineno colno)
721          (when (and pos
722                     (< pos sb!xc:array-dimension-limit)
723                     ;; KLUDGE: lseek() (which is what FILE-POSITION
724                     ;; reduces to on file-streams) is undefined on
725                     ;; "some devices", which in practice means that it
726                     ;; can claim to succeed on /dev/stdin on Darwin
727                     ;; and Solaris.  This is obviously bad news,
728                     ;; because the READ-SEQUENCE below will then
729                     ;; block, not complete, and the report will never
730                     ;; be printed.  As a workaround, we exclude
731                     ;; interactive streams from this attempt to report
732                     ;; positions.  -- CSR, 2003-08-21
733                     (not (interactive-stream-p error-stream))
734                     (file-position error-stream :start))
735            (let ((string
736                   (make-string pos
737                                :element-type (stream-element-type
738                                               error-stream))))
739              (when (= pos (read-sequence string error-stream))
740                (setq lineno (1+ (count #\Newline string))
741                      colno (- pos
742                               (or (position #\Newline string :from-end t) -1)
743                               1))))
744            (file-position-or-nil-for-error error-stream pos))
745          (format stream
746                  "READER-ERROR ~@[at ~W ~]~
747                   ~@[(line ~W~]~@[, column ~W) ~]~
748                   on ~S:~%~?"
749                  pos lineno colno error-stream
750                  (reader-error-format-control condition)
751                  (reader-error-format-arguments condition)))))))
752 \f
753 ;;;; special SBCL extension conditions
754
755 ;;; an error apparently caused by a bug in SBCL itself
756 ;;;
757 ;;; Note that we don't make any serious effort to use this condition
758 ;;; for *all* errors in SBCL itself. E.g. type errors and array
759 ;;; indexing errors can occur in functions called from SBCL code, and
760 ;;; will just end up as ordinary TYPE-ERROR or invalid index error,
761 ;;; because the signalling code has no good way to know that the
762 ;;; underlying problem is a bug in SBCL. But in the fairly common case
763 ;;; that the signalling code does know that it's found a bug in SBCL,
764 ;;; this condition is appropriate, reusing boilerplate and helping
765 ;;; users to recognize it as an SBCL bug.
766 (define-condition bug (simple-error)
767   ()
768   (:report
769    (lambda (condition stream)
770      (format stream
771              "~@<  ~? ~:@_~?~:>"
772              (simple-condition-format-control condition)
773              (simple-condition-format-arguments condition)
774              "~@<This is probably a bug in SBCL itself. (Alternatively, ~
775               SBCL might have been corrupted by bad user code, e.g. by an ~
776               undefined Lisp operation like ~S, or by stray pointers from ~
777               alien code or from unsafe Lisp code; or there might be a bug ~
778               in the OS or hardware that SBCL is running on.) If it seems to ~
779               be a bug in SBCL itself, the maintainers would like to know ~
780               about it. Bug reports are welcome on the SBCL ~
781               mailing lists, which you can find at ~
782               <http://sbcl.sourceforge.net/>.~:@>"
783              '((fmakunbound 'compile))))))
784
785 (define-condition simple-storage-condition (storage-condition simple-condition) ())
786
787 ;;; a condition for use in stubs for operations which aren't supported
788 ;;; on some platforms
789 ;;;
790 ;;; E.g. in sbcl-0.7.0.5, it might be appropriate to do something like
791 ;;;   #-(or freebsd linux)
792 ;;;   (defun load-foreign (&rest rest)
793 ;;;     (error 'unsupported-operator :name 'load-foreign))
794 ;;;   #+(or freebsd linux)
795 ;;;   (defun load-foreign ... actual definition ...)
796 ;;; By signalling a standard condition in this case, we make it
797 ;;; possible for test code to distinguish between (1) intentionally
798 ;;; unimplemented and (2) unintentionally just screwed up somehow.
799 ;;; (Before this condition was defined, test code tried to deal with 
800 ;;; this by checking for FBOUNDP, but that didn't work reliably. In
801 ;;; sbcl-0.7.0, a a package screwup left the definition of
802 ;;; LOAD-FOREIGN in the wrong package, so it was unFBOUNDP even on
803 ;;; architectures where it was supposed to be supported, and the
804 ;;; regression tests cheerfully passed because they assumed that
805 ;;; unFBOUNDPness meant they were running on an system which didn't
806 ;;; support the extension.)
807 (define-condition unsupported-operator (simple-error) ())
808
809 \f
810 ;;; (:ansi-cl :function remove)
811 ;;; (:ansi-cl :section (a b c))
812 ;;; (:ansi-cl :glossary "similar")
813 ;;;
814 ;;; (:sbcl :node "...")
815 ;;; (:sbcl :variable *ed-functions*)
816 ;;;
817 ;;; FIXME: this is not the right place for this.
818 (defun print-reference (reference stream)
819   (ecase (car reference)
820     (:amop
821      (format stream "AMOP")
822      (format stream ", ")
823      (destructuring-bind (type data) (cdr reference)
824        (ecase type
825          (:generic-function (format stream "Generic Function ~S" data))
826          (:section (format stream "Section ~{~D~^.~}" data)))))
827     (:ansi-cl
828      (format stream "The ANSI Standard")
829      (format stream ", ")
830      (destructuring-bind (type data) (cdr reference)
831        (ecase type
832          (:function (format stream "Function ~S" data))
833          (:special-operator (format stream "Special Operator ~S" data))
834          (:macro (format stream "Macro ~S" data))
835          (:section (format stream "Section ~{~D~^.~}" data))
836          (:glossary (format stream "Glossary entry for ~S" data))
837          (:issue (format stream "writeup for Issue ~A" data)))))
838     (:sbcl
839      (format stream "The SBCL Manual")
840      (format stream ", ")
841      (destructuring-bind (type data) (cdr reference)
842        (ecase type
843          (:node (format stream "Node ~S" data))
844          (:variable (format stream "Variable ~S" data))
845          (:function (format stream "Function ~S" data)))))
846     ;; FIXME: other documents (e.g. CLIM, Franz documentation :-)
847     ))
848 (define-condition reference-condition ()
849   ((references :initarg :references :reader reference-condition-references)))
850 (defvar *print-condition-references* t)
851 (def!method print-object :around ((o reference-condition) s)
852   (call-next-method)
853   (unless (or *print-escape* *print-readably*)
854     (when (and *print-condition-references*
855                (reference-condition-references o))
856       (format s "~&See also:~%")
857       (pprint-logical-block (s nil :per-line-prefix "  ")
858         (do* ((rs (reference-condition-references o) (cdr rs))
859               (r (car rs) (car rs)))
860              ((null rs))
861           (print-reference r s)
862           (unless (null (cdr rs))
863             (terpri s)))))))
864
865 (define-condition duplicate-definition (reference-condition warning)
866   ((name :initarg :name :reader duplicate-definition-name))
867   (:report (lambda (c s)
868              (format s "~@<Duplicate definition for ~S found in ~
869                         one file.~@:>"
870                      (duplicate-definition-name c))))
871   (:default-initargs :references (list '(:ansi-cl :section (3 2 2 3)))))
872
873 (define-condition package-at-variance (reference-condition simple-warning) 
874   ()
875   (:default-initargs :references (list '(:ansi-cl :macro defpackage))))
876
877 (define-condition defconstant-uneql (reference-condition error)
878   ((name :initarg :name :reader defconstant-uneql-name)
879    (old-value :initarg :old-value :reader defconstant-uneql-old-value)
880    (new-value :initarg :new-value :reader defconstant-uneql-new-value))
881   (:report
882    (lambda (condition stream)
883      (format stream
884              "~@<The constant ~S is being redefined (from ~S to ~S)~@:>"
885              (defconstant-uneql-name condition)
886              (defconstant-uneql-old-value condition)
887              (defconstant-uneql-new-value condition))))
888   (:default-initargs :references (list '(:ansi-cl :macro defconstant)
889                                        '(:sbcl :node "Idiosyncrasies"))))
890
891 (define-condition array-initial-element-mismatch 
892     (reference-condition simple-warning)
893   ()
894   (:default-initargs 
895       :references (list 
896                    '(:ansi-cl :function make-array) 
897                    '(:ansi-cl :function sb!xc:upgraded-array-element-type))))
898
899 (define-condition displaced-to-array-too-small-error
900     (reference-condition simple-error)
901   ()
902   (:default-initargs
903       :references (list '(:ansi-cl :function adjust-array))))
904
905 (define-condition type-warning (reference-condition simple-warning)
906   ()
907   (:default-initargs :references (list '(:sbcl :node "Handling of Types"))))
908
909 (define-condition local-argument-mismatch (reference-condition simple-warning)
910   ()
911   (:default-initargs :references (list '(:ansi-cl :section (3 2 2 3)))))
912
913 (define-condition format-args-mismatch (reference-condition)
914   ()
915   (:default-initargs :references (list '(:ansi-cl :section (22 3 10 2)))))
916
917 (define-condition format-too-few-args-warning 
918     (format-args-mismatch simple-warning)
919   ())
920 (define-condition format-too-many-args-warning
921     (format-args-mismatch simple-style-warning)
922   ())
923
924 (define-condition extension-failure (reference-condition simple-error)
925   ())
926
927 (define-condition structure-initarg-not-keyword
928     (reference-condition simple-style-warning)
929   ()
930   (:default-initargs :references (list '(:ansi-cl :section (2 4 8 13)))))
931
932 #!+sb-package-locks
933 (progn
934
935 (define-condition package-lock-violation (reference-condition package-error)
936   ((format-control :initform nil :initarg :format-control 
937                    :reader package-error-format-control)
938    (format-arguments :initform nil :initarg :format-arguments
939                      :reader package-error-format-arguments))
940   (:report 
941    (lambda (condition stream)
942      (let ((control (package-error-format-control condition)))
943        (if control
944            (apply #'format stream
945                   (format nil "~~@<Lock on package ~A violated when ~A.~~:@>"
946                           (package-name (package-error-package condition))
947                           control)
948                   (package-error-format-arguments condition))
949            (format stream "~@<Lock on package ~A violated.~:@>"
950                    (package-name (package-error-package condition)))))))
951   ;; no :default-initargs -- reference-stuff provided by the
952   ;; signalling form in target-package.lisp
953   #!+sb-doc
954   (:documentation
955    "Subtype of CL:PACKAGE-ERROR. A subtype of this error is signalled
956 when a package-lock is violated."))
957
958 (define-condition package-locked-error (package-lock-violation) ()
959   #!+sb-doc
960   (:documentation
961    "Subtype of SB-EXT:PACKAGE-LOCK-VIOLATION. An error of this type is
962 signalled when an operation on a package violates a package lock."))
963
964 (define-condition symbol-package-locked-error (package-lock-violation)
965   ((symbol :initarg :symbol :reader package-locked-error-symbol))
966   #!+sb-doc
967   (:documentation
968    "Subtype of SB-EXT:PACKAGE-LOCK-VIOLATION. An error of this type is
969 signalled when an operation on a symbol violates a package lock. The
970 symbol that caused the violation is accessed by the function
971 SB-EXT:PACKAGE-LOCKED-ERROR-SYMBOL."))
972
973 ) ; progn
974
975 (define-condition undefined-alien-error (error) ())
976
977 (define-condition undefined-alien-variable-error (undefined-alien-error) ()
978   (:report
979    (lambda (condition stream)
980      (declare (ignore condition))
981      (format stream "Attempt to access an undefined alien variable."))))
982
983 (define-condition undefined-alien-function-error (undefined-alien-error) ()
984   (:report
985    (lambda (condition stream)
986      (declare (ignore condition))
987      (format stream "Attempt to call an undefined alien function."))))
988
989 \f
990 ;;;; various other (not specified by ANSI) CONDITIONs
991 ;;;;
992 ;;;; These might logically belong in other files; they're here, after
993 ;;;; setup of CONDITION machinery, only because that makes it easier to
994 ;;;; get cold init to work.
995
996 ;;; OAOOM warning: see cross-condition.lisp
997 (define-condition encapsulated-condition (condition)
998   ((condition :initarg :condition :reader encapsulated-condition)))
999
1000 (define-condition values-type-error (type-error)
1001   ()
1002   (:report
1003    (lambda (condition stream)
1004      (format stream
1005              "~@<The values set ~2I~:_[~{~S~^ ~}] ~I~_is not of type ~2I~_~S.~:>"
1006              (type-error-datum condition)
1007              (type-error-expected-type condition)))))
1008
1009 ;;; KLUDGE: a condition for floating point errors when we can't or
1010 ;;; won't figure out what type they are. (In FreeBSD and OpenBSD we
1011 ;;; don't know how, at least as of sbcl-0.6.7; in Linux we probably
1012 ;;; know how but the old code was broken by the conversion to POSIX
1013 ;;; signal handling and hasn't been fixed as of sbcl-0.6.7.)
1014 ;;;
1015 ;;; FIXME: Perhaps this should also be a base class for all
1016 ;;; floating point exceptions?
1017 (define-condition floating-point-exception (arithmetic-error)
1018   ((flags :initarg :traps
1019           :initform nil
1020           :reader floating-point-exception-traps))
1021   (:report (lambda (condition stream)
1022              (format stream
1023                      "An arithmetic error ~S was signalled.~%"
1024                      (type-of condition))
1025              (let ((traps (floating-point-exception-traps condition)))
1026                (if traps
1027                    (format stream
1028                            "Trapping conditions are: ~%~{ ~S~^~}~%"
1029                            traps)
1030                    (write-line
1031                     "No traps are enabled? How can this be?"
1032                     stream))))))
1033
1034 (define-condition index-too-large-error (type-error)
1035   ()
1036   (:report
1037    (lambda (condition stream)
1038      (format stream
1039              "The index ~S is too large."
1040              (type-error-datum condition)))))
1041
1042 (define-condition bounding-indices-bad-error (reference-condition type-error)
1043   ((object :reader bounding-indices-bad-object :initarg :object))
1044   (:report
1045    (lambda (condition stream)
1046      (let* ((datum (type-error-datum condition))
1047             (start (car datum))
1048             (end (cdr datum))
1049             (object (bounding-indices-bad-object condition)))
1050        (etypecase object
1051          (sequence
1052           (format stream
1053                   "The bounding indices ~S and ~S are bad ~
1054                    for a sequence of length ~S."
1055                   start end (length object)))
1056          (array
1057           ;; from WITH-ARRAY-DATA
1058           (format stream
1059                   "The START and END parameters ~S and ~S are ~
1060                    bad for an array of total size ~S."
1061                   start end (array-total-size object)))))))
1062   (:default-initargs 
1063       :references 
1064       (list '(:ansi-cl :glossary "bounding index designator")
1065             '(:ansi-cl :issue "SUBSEQ-OUT-OF-BOUNDS:IS-AN-ERROR"))))
1066
1067 (define-condition nil-array-accessed-error (reference-condition type-error)
1068   ()
1069   (:report (lambda (condition stream)
1070              (declare (ignore condition))
1071              (format stream
1072                      "An attempt to access an array of element-type ~
1073                       NIL was made.  Congratulations!")))
1074   (:default-initargs
1075       :references (list '(:ansi-cl :function sb!xc:upgraded-array-element-type)
1076                         '(:ansi-cl :section (15 1 2 1))
1077                         '(:ansi-cl :section (15 1 2 2)))))
1078
1079 (define-condition io-timeout (stream-error)
1080   ((direction :reader io-timeout-direction :initarg :direction))
1081   (:report
1082    (lambda (condition stream)
1083      (declare (type stream stream))
1084      (format stream
1085              "I/O timeout ~(~A~)ing ~S"
1086              (io-timeout-direction condition)
1087              (stream-error-stream condition)))))
1088
1089 (define-condition namestring-parse-error (parse-error)
1090   ((complaint :reader namestring-parse-error-complaint :initarg :complaint)
1091    (args :reader namestring-parse-error-args :initarg :args :initform nil)
1092    (namestring :reader namestring-parse-error-namestring :initarg :namestring)
1093    (offset :reader namestring-parse-error-offset :initarg :offset))
1094   (:report
1095    (lambda (condition stream)
1096      (format stream
1097              "parse error in namestring: ~?~%  ~A~%  ~V@T^"
1098              (namestring-parse-error-complaint condition)
1099              (namestring-parse-error-args condition)
1100              (namestring-parse-error-namestring condition)
1101              (namestring-parse-error-offset condition)))))
1102
1103 (define-condition simple-package-error (simple-condition package-error) ())
1104
1105 (define-condition reader-package-error (reader-error) ())
1106
1107 (define-condition reader-eof-error (end-of-file)
1108   ((context :reader reader-eof-error-context :initarg :context))
1109   (:report
1110    (lambda (condition stream)
1111      (format stream
1112              "unexpected end of file on ~S ~A"
1113              (stream-error-stream condition)
1114              (reader-eof-error-context condition)))))
1115
1116 (define-condition reader-impossible-number-error (reader-error)
1117   ((error :reader reader-impossible-number-error-error :initarg :error))
1118   (:report
1119    (lambda (condition stream)
1120      (let ((error-stream (stream-error-stream condition)))
1121        (format stream "READER-ERROR ~@[at ~W ~]on ~S:~%~?~%Original error: ~A"
1122                (file-position-or-nil-for-error error-stream) error-stream
1123                (reader-error-format-control condition)
1124                (reader-error-format-arguments condition)
1125                (reader-impossible-number-error-error condition))))))
1126
1127 (define-condition timeout (serious-condition) ())
1128
1129 (define-condition declaration-type-conflict-error (reference-condition
1130                                                    simple-error)
1131   ()
1132   (:default-initargs
1133       :format-control "symbol ~S cannot be both the name of a type and the name of a declaration"
1134     :references (list '(:ansi-cl :section (3 8 21)))))
1135
1136 ;;; Single stepping conditions
1137
1138 (define-condition step-condition ()
1139   ((form :initarg :form :reader step-condition-form))
1140   #!+sb-doc
1141   (:documentation "Common base class of single-stepping conditions.
1142 STEP-CONDITION-FORM holds a string representation of the form being
1143 stepped."))
1144
1145 #!+sb-doc
1146 (setf (fdocumentation 'step-condition-form 'function)
1147       "Form associated with the STEP-CONDITION.")
1148
1149 (define-condition step-form-condition (step-condition)
1150   ((source-path :initarg :source-path :reader step-condition-source-path)
1151    (pathname :initarg :pathname :reader step-condition-pathname))
1152   #!+sb-doc
1153   (:documentation "Condition signalled by code compiled with
1154 single-stepping information when about to execute a form.
1155 STEP-CONDITION-FORM holds the form, STEP-CONDITION-PATHNAME holds the
1156 pathname of the original file or NIL, and STEP-CONDITION-SOURCE-PATH
1157 holds the source-path to the original form within that file or NIL.
1158 Associated with this condition are always the restarts STEP-INTO,
1159 STEP-NEXT, and STEP-CONTINUE."))
1160
1161 #!+sb-doc
1162 (setf (fdocumentation 'step-condition-source-path 'function)
1163       "Source-path of the original form associated with the
1164 STEP-FORM-CONDITION or NIL."
1165       (fdocumentation 'step-condition-pathname 'function)
1166       "Pathname of the original source-file associated with the
1167 STEP-FORM-CONDITION or NIL.")
1168
1169 (define-condition step-result-condition (step-condition)
1170   ((result :initarg :result :reader step-condition-result)))
1171
1172 #!+sb-doc
1173 (setf (fdocumentation 'step-condition-result 'function)
1174       "Return values associated with STEP-VALUES-CONDITION as a list,
1175 or the variable value associated with STEP-VARIABLE-CONDITION.")
1176
1177 (define-condition step-values-condition (step-result-condition)
1178   ()
1179   #!+sb-doc
1180   (:documentation "Condition signalled by code compiled with
1181 single-stepping information after executing a form.
1182 STEP-CONDITION-FORM holds the form, and STEP-CONDITION-RESULT holds
1183 the values returned by the form as a list. No associated restarts."))
1184
1185 (define-condition step-variable-condition (step-result-condition)
1186   ()
1187   #!+sb-doc
1188   (:documentation "Condition signalled by code compiled with
1189 single-stepping information when referencing a variable.
1190 STEP-CONDITION-FORM hold the symbol, and STEP-CONDITION-RESULT holds
1191 the value of the variable. No associated restarts."))
1192
1193 \f
1194 ;;;; restart definitions
1195
1196 (define-condition abort-failure (control-error) ()
1197   (:report
1198    "An ABORT restart was found that failed to transfer control dynamically."))
1199
1200 (defun abort (&optional condition)
1201   #!+sb-doc
1202   "Transfer control to a restart named ABORT, signalling a CONTROL-ERROR if
1203    none exists."
1204   (invoke-restart (find-restart-or-control-error 'abort condition))
1205   ;; ABORT signals an error in case there was a restart named ABORT
1206   ;; that did not transfer control dynamically. This could happen with
1207   ;; RESTART-BIND.
1208   (error 'abort-failure))
1209
1210 (defun muffle-warning (&optional condition)
1211   #!+sb-doc
1212   "Transfer control to a restart named MUFFLE-WARNING, signalling a
1213    CONTROL-ERROR if none exists."
1214   (invoke-restart (find-restart-or-control-error 'muffle-warning condition)))
1215
1216 (macrolet ((define-nil-returning-restart (name args doc)
1217              #!-sb-doc (declare (ignore doc))
1218              `(defun ,name (,@args &optional condition)
1219                 #!+sb-doc ,doc
1220                 ;; FIXME: Perhaps this shared logic should be pulled out into
1221                 ;; FLET MAYBE-INVOKE-RESTART? See whether it shrinks code..
1222                 (let ((restart (find-restart ',name condition)))
1223                   (when restart
1224                     (invoke-restart restart ,@args))))))
1225   (define-nil-returning-restart continue ()
1226     "Transfer control to a restart named CONTINUE, or return NIL if none exists.")
1227   (define-nil-returning-restart store-value (value)
1228     "Transfer control and VALUE to a restart named STORE-VALUE, or return NIL if
1229    none exists.")
1230   (define-nil-returning-restart use-value (value)
1231     "Transfer control and VALUE to a restart named USE-VALUE, or return NIL if
1232    none exists."))
1233
1234 ;;; single-stepping restarts
1235
1236 (macrolet ((def (name doc)
1237                #!-sb-doc (declare (ignore doc))
1238                `(defun ,name (condition)
1239                  #!+sb-doc ,doc
1240                  (invoke-restart (find-restart-or-control-error ',name condition)))))
1241   (def step-continue
1242       "Transfers control to the STEP-CONTINUE restart associated with
1243 the condition, continuing execution without stepping. Signals a
1244 CONTROL-ERROR if the restart does not exist.")
1245   (def step-next
1246       "Transfers control to the STEP-NEXT restart associated with the
1247 condition, executing the current form without stepping and continuing
1248 stepping with the next form. Signals CONTROL-ERROR is the restart does
1249 not exists.")
1250   (def step-into
1251       "Transfers control to the STEP-INTO restart associated with the
1252 condition, stepping into the current form. Signals a CONTROL-ERROR is
1253 the restart does not exist."))
1254
1255 (/show0 "condition.lisp end of file")
1256