1 ;;;; stuff originally from CMU CL's error.lisp which can or should
2 ;;;; come late (mostly related to the CONDITION class itself)
5 ;;;; This software is part of the SBCL system. See the README file for
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.
14 (in-package "SB!KERNEL")
16 ;;;; the CONDITION class
18 (/show0
"condition.lisp 20")
20 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
22 (/show0
"condition.lisp 24")
24 (def!struct
(condition-classoid (:include classoid
)
25 (:constructor make-condition-classoid
))
26 ;; list of CONDITION-SLOT structures for the direct slots of this
28 (slots nil
:type list
)
29 ;; list of CONDITION-SLOT structures for all of the effective class
30 ;; slots of this class
31 (class-slots nil
:type list
)
32 ;; report function or NIL
33 (report nil
:type
(or function null
))
34 ;; list of specifications of the form
36 ;; (INITARG INITFORM THUNK)
38 ;; where THUNK, when called without arguments, returns the value for
40 (direct-default-initargs () :type list
)
41 ;; class precedence list as a list of CLASS objects, with all
42 ;; non-CONDITION classes removed
44 ;; a list of all the effective instance allocation slots of this
45 ;; class that have a non-constant initform or default-initarg.
46 ;; Values for these slots must be computed in the dynamic
47 ;; environment of MAKE-CONDITION.
48 (hairy-slots nil
:type list
))
50 (/show0
"condition.lisp 49")
54 (!defstruct-with-alternate-metaclass condition
55 :slot-names
(actual-initargs assigned-slots
)
56 :boa-constructor %make-condition-object
58 :metaclass-name condition-classoid
59 :metaclass-constructor make-condition-classoid
62 (defstruct (condition-slot (:copier nil
))
63 (name (missing-arg) :type symbol
)
64 ;; list of all applicable initargs
65 (initargs (missing-arg) :type list
)
66 ;; names of reader and writer functions
67 (readers (missing-arg) :type list
)
68 (writers (missing-arg) :type list
)
69 ;; true if :INITFORM was specified
70 (initform-p (missing-arg) :type
(member t nil
))
71 ;; the initform if :INITFORM was specified, otherwise NIL
72 (initform nil
:type t
)
73 ;; if this is a function, call it with no args to get the initform value
74 (initfunction (missing-arg) :type t
)
75 ;; allocation of this slot, or NIL until defaulted
76 (allocation nil
:type
(member :instance
:class nil
))
77 ;; If ALLOCATION is :CLASS, this is a cons whose car holds the value
78 (cell nil
:type
(or cons null
))
80 (documentation nil
:type
(or string null
)))
82 ;;; KLUDGE: It's not clear to me why CONDITION-CLASS has itself listed
83 ;;; in its CPL, while other classes derived from CONDITION-CLASS don't
84 ;;; have themselves listed in their CPLs. This behavior is inherited
85 ;;; from CMU CL, and didn't seem to be explained there, and I haven't
86 ;;; figured out whether it's right. -- WHN 19990612
87 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
88 (/show0
"condition.lisp 103")
89 (let ((condition-class (locally
90 ;; KLUDGE: There's a DEFTRANSFORM
91 ;; FIND-CLASSOID for constant class names
92 ;; which creates fast but
93 ;; non-cold-loadable, non-compact code. In
94 ;; this context, we'd rather have compact,
95 ;; cold-loadable code. -- WHN 19990928
96 (declare (notinline find-classoid
))
97 (find-classoid 'condition
))))
98 (setf (condition-classoid-cpl condition-class
)
99 (list condition-class
)))
100 (/show0
"condition.lisp 103"))
102 (setf (condition-classoid-report (locally
103 ;; KLUDGE: There's a DEFTRANSFORM
104 ;; FIND-CLASSOID for constant class
105 ;; names which creates fast but
106 ;; non-cold-loadable, non-compact
107 ;; code. In this context, we'd
108 ;; rather have compact,
109 ;; cold-loadable code. -- WHN
111 (declare (notinline find-classoid
))
112 (find-classoid 'condition
)))
113 (lambda (cond stream
)
114 (format stream
"Condition ~S was signalled." (type-of cond
))))
116 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
118 (defun find-condition-layout (name parent-types
)
119 (let* ((cpl (remove-duplicates
123 (condition-classoid-cpl
126 (cond-layout (info :type
:compiler-layout
'condition
))
127 (olayout (info :type
:compiler-layout name
))
128 ;; FIXME: Does this do the right thing in case of multiple
129 ;; inheritance? A quick look at DEFINE-CONDITION didn't make
130 ;; it obvious what ANSI intends to be done in the case of
131 ;; multiple inheritance, so it's not actually clear what the
134 (order-layout-inherits (concatenate 'simple-vector
135 (layout-inherits cond-layout
)
136 (mapcar #'classoid-layout cpl
)))))
138 (not (mismatch (layout-inherits olayout
) new-inherits
)))
140 (make-layout :classoid
(make-undefined-classoid name
)
141 :inherits new-inherits
143 :length
(layout-length cond-layout
)))))
147 ;;; FIXME: ANSI's definition of DEFINE-CONDITION says
148 ;;; Condition reporting is mediated through the PRINT-OBJECT method
149 ;;; for the condition type in question, with *PRINT-ESCAPE* always
150 ;;; being nil. Specifying (:REPORT REPORT-NAME) in the definition of
151 ;;; a condition type C is equivalent to:
152 ;;; (defmethod print-object ((x c) stream)
153 ;;; (if *print-escape* (call-next-method) (report-name x stream)))
154 ;;; The current code doesn't seem to quite match that.
155 (def!method print-object
((x condition
) stream
)
157 (if (and (typep x
'simple-condition
) (slot-value x
'format-control
))
158 (print-unreadable-object (x stream
:type t
:identity t
)
159 (write (simple-condition-format-control x
)
162 (print-unreadable-object (x stream
:type t
:identity t
)))
163 ;; KLUDGE: A comment from CMU CL here said
164 ;; 7/13/98 BUG? CPL is not sorted and results here depend on order of
165 ;; superclasses in define-condition call!
166 (dolist (class (condition-classoid-cpl (classoid-of x
))
167 (error "no REPORT? shouldn't happen!"))
168 (let ((report (condition-classoid-report class
)))
170 (return (funcall report x stream
)))))))
172 ;;;; slots of CONDITION objects
174 (defvar *empty-condition-slot
* '(empty))
176 (defun find-slot-default (class slot
)
177 (let ((initargs (condition-slot-initargs slot
))
178 (cpl (condition-classoid-cpl class
)))
179 ;; When CLASS or a superclass has a default initarg for SLOT, use
182 (let ((direct-default-initargs
183 (condition-classoid-direct-default-initargs class
)))
184 (dolist (initarg initargs
)
185 (let ((initfunction (third (assoc initarg direct-default-initargs
))))
187 (return-from find-slot-default
(funcall initfunction
)))))))
189 ;; Otherwise use the initform of SLOT, if there is one.
190 (if (condition-slot-initform-p slot
)
191 (let ((initfun (condition-slot-initfunction slot
)))
192 (aver (functionp initfun
))
194 (error "unbound condition slot: ~S" (condition-slot-name slot
)))))
196 (defun find-condition-class-slot (condition-class slot-name
)
198 (condition-classoid-cpl condition-class
)
199 (error "There is no slot named ~S in ~S."
200 slot-name condition-class
))
201 (dolist (slot (condition-classoid-slots sclass
))
202 (when (eq (condition-slot-name slot
) slot-name
)
203 (return-from find-condition-class-slot slot
)))))
205 (defun condition-writer-function (condition new-value name
)
206 (dolist (cslot (condition-classoid-class-slots
207 (layout-classoid (%instance-layout condition
)))
208 (setf (getf (condition-assigned-slots condition
) name
)
210 (when (eq (condition-slot-name cslot
) name
)
211 (return (setf (car (condition-slot-cell cslot
)) new-value
)))))
213 (defun condition-reader-function (condition name
)
214 (let ((class (layout-classoid (%instance-layout condition
))))
215 (dolist (cslot (condition-classoid-class-slots class
))
216 (when (eq (condition-slot-name cslot
) name
)
217 (return-from condition-reader-function
218 (car (condition-slot-cell cslot
)))))
219 (let ((val (getf (condition-assigned-slots condition
) name
220 *empty-condition-slot
*)))
221 (if (eq val
*empty-condition-slot
*)
222 (let ((actual-initargs (condition-actual-initargs condition
))
223 (slot (find-condition-class-slot class name
)))
225 (error "missing slot ~S of ~S" name condition
))
226 (do ((initargs actual-initargs
(cddr initargs
)))
228 (setf (getf (condition-assigned-slots condition
) name
)
229 (find-slot-default class slot
)))
230 (when (member (car initargs
) (condition-slot-initargs slot
))
231 (return-from condition-reader-function
232 (setf (getf (condition-assigned-slots condition
)
239 (defun allocate-condition (type &rest initargs
)
240 (let* ((classoid (if (symbolp type
)
241 (find-classoid type nil
)
243 (class (typecase classoid
244 (condition-classoid classoid
)
246 (return-from allocate-condition
247 (apply #'allocate-condition
(class-name classoid
) initargs
)))
249 (error 'simple-type-error
251 :expected-type
'condition-class
252 :format-control
"~S is not a condition class."
253 :format-arguments
(list type
)))
255 (error 'simple-type-error
257 :expected-type
'condition-class
259 "~S does not designate a condition class."
260 :format-arguments
(list type
)))))
261 (condition (%make-condition-object initargs
'())))
262 (setf (%instance-layout condition
) (classoid-layout class
))
263 (values condition class
)))
265 (defun make-condition (type &rest initargs
)
267 "Make an instance of a condition object using the specified initargs."
268 ;; Note: ANSI specifies no exceptional situations in this function.
269 ;; signalling simple-type-error would not be wrong.
270 (multiple-value-bind (condition class
)
271 (apply #'allocate-condition type initargs
)
273 ;; Set any class slots with initargs present in this call.
274 (dolist (cslot (condition-classoid-class-slots class
))
275 (dolist (initarg (condition-slot-initargs cslot
))
276 (let ((val (getf initargs initarg
*empty-condition-slot
*)))
277 (unless (eq val
*empty-condition-slot
*)
278 (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 initargs initarg
*empty-condition-slot
*)
284 *empty-condition-slot
*)
286 (setf (getf (condition-assigned-slots condition
)
287 (condition-slot-name hslot
))
288 (find-slot-default class hslot
))))
293 ;;;; DEFINE-CONDITION
295 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
296 (defun %compiler-define-condition
(name direct-supers layout
297 all-readers all-writers
)
298 (with-single-package-locked-error
299 (:symbol name
"defining ~A as a condition")
300 (sb!xc
:proclaim
`(ftype (function (t) t
) ,@all-readers
))
301 (sb!xc
:proclaim
`(ftype (function (t t
) t
) ,@all-writers
))
302 (multiple-value-bind (class old-layout
)
303 (insured-find-classoid name
304 #'condition-classoid-p
305 #'make-condition-classoid
)
306 (setf (layout-classoid layout
) class
)
307 (setf (classoid-direct-superclasses class
)
308 (mapcar #'find-classoid direct-supers
))
309 (cond ((not old-layout
)
310 (register-layout layout
))
311 ((not *type-system-initialized
*)
312 (setf (layout-classoid old-layout
) class
)
313 (setq layout old-layout
)
314 (unless (eq (classoid-layout class
) layout
)
315 (register-layout layout
)))
316 ((redefine-layout-warning "current"
319 (layout-length layout
)
320 (layout-inherits layout
)
321 (layout-depthoid layout
)
322 (layout-raw-slot-metadata layout
))
323 (register-layout layout
:invalidate t
))
324 ((not (classoid-layout class
))
325 (register-layout layout
)))
327 ;; This looks totally bogus - it essentially means that the LAYOUT-INFO
328 ;; of a condition is good for nothing, because it describes something
329 ;; that is not the condition class being defined.
330 ;; In addition to which, the INFO for CONDITION itself describes
331 ;; slots which do not exist, viz:
332 ;; (dd-slots (layout-info (classoid-layout (find-classoid 'condition))))
333 ;; => (#<DEFSTRUCT-SLOT-DESCRIPTION ACTUAL-INITARGS>
334 ;; #<DEFSTRUCT-SLOT-DESCRIPTION ASSIGNED-SLOTS>)
335 (setf (layout-info layout
)
337 ;; KLUDGE: There's a FIND-CLASS DEFTRANSFORM for constant class
338 ;; names which creates fast but non-cold-loadable, non-compact
339 ;; code. In this context, we'd rather have compact, cold-loadable
340 ;; code. -- WHN 19990928
341 (declare (notinline find-classoid
))
342 (layout-info (classoid-layout (find-classoid 'condition
)))))
344 (setf (find-classoid name
) class
)
346 ;; Initialize CPL slot.
347 (setf (condition-classoid-cpl class
)
348 (remove-if-not #'condition-classoid-p
349 (std-compute-class-precedence-list class
)))))
353 ;;; Compute the effective slots of CLASS, copying inherited slots and
354 ;;; destructively modifying direct slots.
356 ;;; FIXME: It'd be nice to explain why it's OK to destructively modify
357 ;;; direct slots. Presumably it follows from the semantics of
358 ;;; inheritance and redefinition of conditions, but finding the cite
359 ;;; and documenting it here would be good. (Or, if this is not in fact
360 ;;; ANSI-compliant, fixing it would also be good.:-)
361 (defun compute-effective-slots (class)
362 (collect ((res (copy-list (condition-classoid-slots class
))))
363 (dolist (sclass (cdr (condition-classoid-cpl class
)))
364 (dolist (sslot (condition-classoid-slots sclass
))
365 (let ((found (find (condition-slot-name sslot
) (res)
366 :key
#'condition-slot-name
)))
368 (setf (condition-slot-initargs found
)
369 (union (condition-slot-initargs found
)
370 (condition-slot-initargs sslot
)))
371 (unless (condition-slot-initform-p found
)
372 (setf (condition-slot-initform-p found
)
373 (condition-slot-initform-p sslot
))
374 (setf (condition-slot-initform found
)
375 (condition-slot-initform sslot
))
376 (setf (condition-slot-initfunction found
)
377 (condition-slot-initfunction sslot
)))
378 (unless (condition-slot-allocation found
)
379 (setf (condition-slot-allocation found
)
380 (condition-slot-allocation sslot
))))
382 (res (copy-structure sslot
)))))))
385 ;;; Early definitions of slot accessor creators.
387 ;;; Slot accessors must be generic functions, but ANSI does not seem
388 ;;; to specify any of them, and we cannot support it before end of
389 ;;; warm init. So we use ordinary functions inside SBCL, and switch to
390 ;;; GFs only at the end of building.
391 (declaim (notinline install-condition-slot-reader
392 install-condition-slot-writer
))
393 (defun install-condition-slot-reader (name condition slot-name
)
394 (declare (ignore condition
))
395 (setf (fdefinition name
)
397 (condition-reader-function condition slot-name
))))
398 (defun install-condition-slot-writer (name condition slot-name
)
399 (declare (ignore condition
))
400 (setf (fdefinition name
)
401 (lambda (new-value condition
)
402 (condition-writer-function condition new-value slot-name
))))
404 (!defvar
*define-condition-hooks
* nil
)
406 (defun %set-condition-report
(name report
)
407 (setf (condition-classoid-report (find-classoid name
))
410 (defun %define-condition
(name parent-types layout slots documentation
411 direct-default-initargs all-readers all-writers
413 (with-single-package-locked-error
414 (:symbol name
"defining ~A as a condition")
415 (%compiler-define-condition name parent-types layout all-readers all-writers
)
416 (sb!c
:with-source-location
(source-location)
417 (setf (layout-source-location layout
)
419 (let ((class (find-classoid name
))) ; FIXME: rename to 'classoid'
420 (setf (condition-classoid-slots class
) slots
421 (condition-classoid-direct-default-initargs class
) direct-default-initargs
422 (fdocumentation name
'type
) documentation
)
426 ;; Set up reader and writer functions.
427 (let ((slot-name (condition-slot-name slot
)))
428 (dolist (reader (condition-slot-readers slot
))
429 (install-condition-slot-reader reader name slot-name
))
430 (dolist (writer (condition-slot-writers slot
))
431 (install-condition-slot-writer writer name slot-name
))))
433 ;; Compute effective slots and set up the class and hairy slots
434 ;; (subsets of the effective slots.)
435 (setf (condition-classoid-class-slots class
) '()
436 (condition-classoid-hairy-slots class
) '())
437 (let ((eslots (compute-effective-slots class
))
440 (mapcar #'condition-classoid-direct-default-initargs
441 (condition-classoid-cpl class
)))))
442 (dolist (slot eslots
)
443 (ecase (condition-slot-allocation slot
)
445 (unless (condition-slot-cell slot
)
446 (setf (condition-slot-cell slot
)
447 (list (if (condition-slot-initform-p slot
)
448 (let ((initfun (condition-slot-initfunction slot
)))
449 (aver (functionp initfun
))
451 *empty-condition-slot
*))))
452 (push slot
(condition-classoid-class-slots class
)))
454 (setf (condition-slot-allocation slot
) :instance
)
455 ;; FIXME: isn't this "always hairy"?
456 (when (or (functionp (condition-slot-initfunction slot
))
457 (dolist (initarg (condition-slot-initargs slot
) nil
)
458 (when (functionp (third (assoc initarg e-def-initargs
)))
460 (push slot
(condition-classoid-hairy-slots class
)))))))
461 (dolist (fun *define-condition-hooks
*)
462 (funcall fun class
)))
465 (defmacro define-condition
(name (&rest parent-types
) (&rest slot-specs
)
468 "DEFINE-CONDITION Name (Parent-Type*) (Slot-Spec*) Option*
469 Define NAME as a condition type. This new type inherits slots and its
470 report function from the specified PARENT-TYPEs. A slot spec is a list of:
471 (slot-name :reader <rname> :initarg <iname> {Option Value}*
473 The DEFINE-CLASS slot options :ALLOCATION, :INITFORM, [slot] :DOCUMENTATION
474 and :TYPE and the overall options :DEFAULT-INITARGS and
475 [type] :DOCUMENTATION are also allowed.
477 The :REPORT option is peculiar to DEFINE-CONDITION. Its argument is either
478 a string or a two-argument lambda or function name. If a function, the
479 function is called with the condition and stream to report the condition.
480 If a string, the string is printed.
482 Condition types are classes, but (as allowed by ANSI and not as described in
483 CLtL2) are neither STANDARD-OBJECTs nor STRUCTURE-OBJECTs. WITH-SLOTS and
484 SLOT-VALUE may not be used on condition objects."
485 (let* ((parent-types (or parent-types
'(condition)))
486 (layout (find-condition-layout name parent-types
))
489 (direct-default-initargs ()))
491 (all-readers nil append
)
492 (all-writers nil append
))
493 (dolist (spec slot-specs
)
494 (when (keywordp spec
)
495 (warn "Keyword slot name indicates probable syntax error:~% ~S"
497 (let* ((spec (if (consp spec
) spec
(list spec
)))
498 (slot-name (first spec
))
499 (allocation :instance
)
506 (do ((options (rest spec
) (cddr options
)))
508 (unless (and (consp options
) (consp (cdr options
)))
509 (error "malformed condition slot spec:~% ~S." spec
))
510 (let ((arg (second options
)))
511 (case (first options
)
512 (:reader
(readers arg
))
513 (:writer
(writers arg
))
516 (writers `(setf ,arg
)))
519 (error "more than one :INITFORM in ~S" spec
))
522 (:initarg
(initargs arg
))
524 (setq allocation arg
))
527 (error "more than one :DOCUMENTATION in ~S" spec
))
528 (unless (stringp arg
)
529 (error "slot :DOCUMENTATION argument is not a string: ~S"
531 (setq documentation arg
))
534 (error "unknown slot option:~% ~S" (first options
))))))
536 (all-readers (readers))
537 (all-writers (writers))
538 (slots `(make-condition-slot
540 :initargs
',(initargs)
543 :initform-p
',initform-p
544 :documentation
',documentation
545 :initform
,(when initform-p
`',initform
)
546 :initfunction
,(when initform-p
547 `#'(lambda () ,initform
))
548 :allocation
',allocation
)))))
550 (dolist (option options
)
551 (unless (consp option
)
552 (error "bad option:~% ~S" option
))
554 (:documentation
(setq documentation
(second option
)))
556 (let ((arg (second option
)))
559 `#'(lambda (condition stream
)
560 (declare (ignore condition
))
561 (write-string ,arg stream
))
562 `#'(lambda (condition stream
)
563 (funcall #',arg condition stream
))))))
565 (doplist (initarg initform
) (rest option
)
566 (push ``(,',initarg
,',initform
,#'(lambda () ,initform
))
567 direct-default-initargs
)))
569 (error "unknown option: ~S" (first option
)))))
572 (eval-when (:compile-toplevel
)
573 (%compiler-define-condition
',name
',parent-types
',layout
574 ',(all-readers) ',(all-writers)))
575 (%define-condition
',name
580 (list ,@direct-default-initargs
)
583 (sb!c
:source-location
))
584 ;; This needs to be after %DEFINE-CONDITION in case :REPORT
585 ;; is a lambda referring to condition slot accessors:
586 ;; they're not proclaimed as functions before it has run if
587 ;; we're under EVAL or loaded as source.
588 (%set-condition-report
',name
,report
)
591 ;;;; various CONDITIONs specified by ANSI
593 (define-condition serious-condition
(condition) ())
595 (define-condition error
(serious-condition) ())
597 (define-condition warning
(condition) ())
598 (define-condition style-warning
(warning) ())
600 (defun simple-condition-printer (condition stream
)
601 (let ((control (simple-condition-format-control condition
)))
603 (apply #'format stream
605 (simple-condition-format-arguments condition
))
606 (error "No format-control for ~S" condition
))))
608 (define-condition simple-condition
()
609 ((format-control :reader simple-condition-format-control
610 :initarg
:format-control
612 :type format-control
)
613 (format-arguments :reader simple-condition-format-arguments
614 :initarg
:format-arguments
617 (:report simple-condition-printer
))
619 (define-condition simple-warning
(simple-condition warning
) ())
621 (define-condition simple-error
(simple-condition error
) ())
623 (define-condition storage-condition
(serious-condition) ())
625 (define-condition type-error
(error)
626 ((datum :reader type-error-datum
:initarg
:datum
)
627 (expected-type :reader type-error-expected-type
:initarg
:expected-type
))
629 (lambda (condition stream
)
631 "~@<The value ~2I~:_~S ~I~_is not of type ~2I~_~S.~:>"
632 (type-error-datum condition
)
633 (type-error-expected-type condition
)))))
635 (def!method print-object
((condition type-error
) stream
)
636 (if (and *print-escape
*
637 (slot-boundp condition
'expected-type
)
638 (slot-boundp condition
'datum
))
639 (flet ((maybe-string (thing)
641 (write-to-string thing
:lines
1 :readably nil
:array nil
:pretty t
))))
642 (let ((type (maybe-string (type-error-expected-type condition
)))
643 (datum (maybe-string (type-error-datum condition
))))
645 (print-unreadable-object (condition stream
:type t
)
646 (format stream
"~@<expected-type: ~A ~_datum: ~A~:@>" type datum
))
647 (call-next-method))))
650 ;;; not specified by ANSI, but too useful not to have around.
651 (define-condition simple-style-warning
(simple-condition style-warning
) ())
652 (define-condition simple-type-error
(simple-condition type-error
) ())
654 ;; Can't have a function called SIMPLE-TYPE-ERROR or TYPE-ERROR...
655 (declaim (ftype (sfunction (t t t
&rest t
) nil
) bad-type
))
656 (defun bad-type (datum type control
&rest arguments
)
657 (error 'simple-type-error
660 :format-control control
661 :format-arguments arguments
))
663 (define-condition program-error
(error) ())
664 (define-condition parse-error
(error) ())
665 (define-condition control-error
(error) ())
666 (define-condition stream-error
(error)
667 ((stream :reader stream-error-stream
:initarg
:stream
)))
669 (define-condition end-of-file
(stream-error) ()
671 (lambda (condition stream
)
674 (stream-error-stream condition
)))))
676 (define-condition closed-stream-error
(stream-error) ()
678 (lambda (condition stream
)
679 (format stream
"~S is closed" (stream-error-stream condition
)))))
681 (define-condition file-error
(error)
682 ((pathname :reader file-error-pathname
:initarg
:pathname
))
684 (lambda (condition stream
)
685 (format stream
"error on file ~S" (file-error-pathname condition
)))))
687 (define-condition package-error
(error)
688 ((package :reader package-error-package
:initarg
:package
)))
690 (define-condition cell-error
(error)
691 ((name :reader cell-error-name
:initarg
:name
)))
693 (def!method print-object
((condition cell-error
) stream
)
694 (if (and *print-escape
* (slot-boundp condition
'name
))
695 (print-unreadable-object (condition stream
:type t
:identity t
)
696 (princ (cell-error-name condition
) stream
))
699 (define-condition unbound-variable
(cell-error) ()
701 (lambda (condition stream
)
703 "The variable ~S is unbound."
704 (cell-error-name condition
)))))
706 (define-condition undefined-function
(cell-error) ()
708 (lambda (condition stream
)
709 (let ((*package
* (find-package :keyword
)))
711 "The function ~S is undefined."
712 (cell-error-name condition
))))))
714 (define-condition special-form-function
(undefined-function) ()
716 (lambda (condition stream
)
718 "Cannot FUNCALL the SYMBOL-FUNCTION of special operator ~S."
719 (cell-error-name condition
)))))
721 (define-condition arithmetic-error
(error)
722 ((operation :reader arithmetic-error-operation
725 (operands :reader arithmetic-error-operands
727 (:report
(lambda (condition stream
)
729 "arithmetic error ~S signalled"
731 (when (arithmetic-error-operation condition
)
733 "~%Operation was ~S, operands ~S."
734 (arithmetic-error-operation condition
)
735 (arithmetic-error-operands condition
))))))
737 (define-condition division-by-zero
(arithmetic-error) ())
738 (define-condition floating-point-overflow
(arithmetic-error) ())
739 (define-condition floating-point-underflow
(arithmetic-error) ())
740 (define-condition floating-point-inexact
(arithmetic-error) ())
741 (define-condition floating-point-invalid-operation
(arithmetic-error) ())
743 (define-condition print-not-readable
(error)
744 ((object :reader print-not-readable-object
:initarg
:object
))
746 (lambda (condition stream
)
747 (let ((obj (print-not-readable-object condition
))
749 (format stream
"~S cannot be printed readably." obj
)))))
751 (define-condition reader-error
(parse-error stream-error
) ()
752 (:report
(lambda (condition stream
)
753 (%report-reader-error condition stream
))))
755 ;;; a READER-ERROR whose REPORTing is controlled by FORMAT-CONTROL and
756 ;;; FORMAT-ARGS (the usual case for READER-ERRORs signalled from
757 ;;; within SBCL itself)
759 ;;; (Inheriting CL:SIMPLE-CONDITION here isn't quite consistent with
760 ;;; the letter of the ANSI spec: this is not a condition signalled by
761 ;;; SIGNAL when a format-control is supplied by the function's first
762 ;;; argument. It seems to me (WHN) to be basically in the spirit of
763 ;;; the spec, but if not, it'd be straightforward to do our own
764 ;;; DEFINE-CONDITION SB-INT:SIMPLISTIC-CONDITION with
765 ;;; FORMAT-CONTROL and FORMAT-ARGS slots, and use that condition in
766 ;;; place of CL:SIMPLE-CONDITION here.)
767 (define-condition simple-reader-error
(reader-error simple-condition
)
769 (:report
(lambda (condition stream
)
770 (%report-reader-error condition stream
:simple t
))))
772 ;;; base REPORTing of a READER-ERROR
774 ;;; When SIMPLE, we expect and use SIMPLE-CONDITION-ish FORMAT-CONTROL
775 ;;; and FORMAT-ARGS slots.
776 (defun %report-reader-error
(condition stream
&key simple position
)
777 (let ((error-stream (stream-error-stream condition
)))
778 (pprint-logical-block (stream nil
)
780 (apply #'format stream
781 (simple-condition-format-control condition
)
782 (simple-condition-format-arguments condition
))
783 (prin1 (class-name (class-of condition
)) stream
))
784 (format stream
"~2I~@[~_~_~:{~:(~A~): ~S~:^, ~:_~}~]~_~_Stream: ~S"
785 (stream-error-position-info error-stream position
)
788 ;;;; special SBCL extension conditions
790 ;;; an error apparently caused by a bug in SBCL itself
792 ;;; Note that we don't make any serious effort to use this condition
793 ;;; for *all* errors in SBCL itself. E.g. type errors and array
794 ;;; indexing errors can occur in functions called from SBCL code, and
795 ;;; will just end up as ordinary TYPE-ERROR or invalid index error,
796 ;;; because the signalling code has no good way to know that the
797 ;;; underlying problem is a bug in SBCL. But in the fairly common case
798 ;;; that the signalling code does know that it's found a bug in SBCL,
799 ;;; this condition is appropriate, reusing boilerplate and helping
800 ;;; users to recognize it as an SBCL bug.
801 (define-condition bug
(simple-error)
804 (lambda (condition stream
)
807 (simple-condition-format-control condition
)
808 (simple-condition-format-arguments condition
)
809 "~@<This is probably a bug in SBCL itself. (Alternatively, ~
810 SBCL might have been corrupted by bad user code, e.g. by an ~
811 undefined Lisp operation like ~S, or by stray pointers from ~
812 alien code or from unsafe Lisp code; or there might be a bug ~
813 in the OS or hardware that SBCL is running on.) If it seems to ~
814 be a bug in SBCL itself, the maintainers would like to know ~
815 about it. Bug reports are welcome on the SBCL ~
816 mailing lists, which you can find at ~
817 <http://sbcl.sourceforge.net/>.~:@>"
818 '((fmakunbound 'compile
))))))
820 (define-condition simple-storage-condition
(storage-condition simple-condition
)
823 ;;; a condition for use in stubs for operations which aren't supported
824 ;;; on some platforms
826 ;;; E.g. in sbcl-0.7.0.5, it might be appropriate to do something like
827 ;;; #-(or freebsd linux)
828 ;;; (defun load-foreign (&rest rest)
829 ;;; (error 'unsupported-operator :name 'load-foreign))
830 ;;; #+(or freebsd linux)
831 ;;; (defun load-foreign ... actual definition ...)
832 ;;; By signalling a standard condition in this case, we make it
833 ;;; possible for test code to distinguish between (1) intentionally
834 ;;; unimplemented and (2) unintentionally just screwed up somehow.
835 ;;; (Before this condition was defined, test code tried to deal with
836 ;;; this by checking for FBOUNDP, but that didn't work reliably. In
837 ;;; sbcl-0.7.0, a package screwup left the definition of
838 ;;; LOAD-FOREIGN in the wrong package, so it was unFBOUNDP even on
839 ;;; architectures where it was supposed to be supported, and the
840 ;;; regression tests cheerfully passed because they assumed that
841 ;;; unFBOUNDPness meant they were running on an system which didn't
842 ;;; support the extension.)
843 (define-condition unsupported-operator
(simple-error) ())
845 ;;; (:ansi-cl :function remove)
846 ;;; (:ansi-cl :section (a b c))
847 ;;; (:ansi-cl :glossary "similar")
849 ;;; (:sbcl :node "...")
850 ;;; (:sbcl :variable *ed-functions*)
852 ;;; FIXME: this is not the right place for this.
853 (defun print-reference (reference stream
)
854 (ecase (car reference
)
856 (format stream
"AMOP")
858 (destructuring-bind (type data
) (cdr reference
)
860 (:readers
"Readers for ~:(~A~) Metaobjects"
861 (substitute #\
#\-
(symbol-name data
)))
863 (format stream
"Initialization of ~:(~A~) Metaobjects"
864 (substitute #\
#\-
(symbol-name data
))))
865 (:generic-function
(format stream
"Generic Function ~S" data
))
866 (:function
(format stream
"Function ~S" data
))
867 (:section
(format stream
"Section ~{~D~^.~}" data
)))))
869 (format stream
"The ANSI Standard")
871 (destructuring-bind (type data
) (cdr reference
)
873 (:function
(format stream
"Function ~S" data
))
874 (:special-operator
(format stream
"Special Operator ~S" data
))
875 (:macro
(format stream
"Macro ~S" data
))
876 (:section
(format stream
"Section ~{~D~^.~}" data
))
877 (:glossary
(format stream
"Glossary entry for ~S" data
))
878 (:type
(format stream
"Type ~S" data
))
879 (:system-class
(format stream
"System Class ~S" data
))
880 (:issue
(format stream
"writeup for Issue ~A" data
)))))
882 (format stream
"The SBCL Manual")
884 (destructuring-bind (type data
) (cdr reference
)
886 (:node
(format stream
"Node ~S" data
))
887 (:variable
(format stream
"Variable ~S" data
))
888 (:function
(format stream
"Function ~S" data
)))))
889 ;; FIXME: other documents (e.g. CLIM, Franz documentation :-)
891 (define-condition reference-condition
()
892 ((references :initarg
:references
:reader reference-condition-references
)))
893 (defvar *print-condition-references
* t
)
894 (def!method print-object
:around
((o reference-condition
) s
)
896 (unless (or *print-escape
* *print-readably
*)
897 (when (and *print-condition-references
*
898 (reference-condition-references o
))
899 (format s
"~&See also:~%")
900 (pprint-logical-block (s nil
:per-line-prefix
" ")
901 (do* ((rs (reference-condition-references o
) (cdr rs
))
902 (r (car rs
) (car rs
)))
904 (print-reference r s
)
905 (unless (null (cdr rs
))
908 (define-condition simple-reference-error
(reference-condition simple-error
)
911 (define-condition simple-reference-warning
(reference-condition simple-warning
)
914 (define-condition arguments-out-of-domain-error
915 (arithmetic-error reference-condition
)
918 ;; per CLHS: "The consequences are unspecified if functions are ...
919 ;; multiply defined in the same file." so we are within reason to do any
920 ;; unspecified behavior at compile-time and/or time, but the compiler was
921 ;; annoyingly mum about genuinely inadvertent duplicate macro definitions.
922 ;; Redefinition is henceforth a style-warning, and for compatibility it does
923 ;; not cause the ERRORP value from COMPILE-TIME to be T.
924 ;; Nor do we cite section 3.2.2.3 as the governing prohibition.
925 (defun report-duplicate-definition (condition stream
)
926 (format stream
"~@<Duplicate definition for ~S found in one file.~@:>"
927 (slot-value condition
'name
)))
929 (define-condition duplicate-definition
(reference-condition warning
)
930 ((name :initarg
:name
:reader duplicate-definition-name
))
931 (:report report-duplicate-definition
)
932 (:default-initargs
:references
(list '(:ansi-cl
:section
(3 2 2 3)))))
933 ;; To my thinking, DUPLICATE-DEFINITION should be the ancestor condition,
934 ;; and not fatal. But changing the meaning of that concept would be a bad idea,
935 ;; so instead there is a new condition for the softer variant, which does not
936 ;; inherit from the former.
937 (define-condition same-file-redefinition-warning
(style-warning)
938 ;; Slot readers aren't proper generic functions until CLOS is built,
939 ;; so this doesn't get a reader because you can't pick the same name,
940 ;; and it wouldn't do any good to pick a different name that nothing knows.
941 ((name :initarg
:name
))
942 (:report report-duplicate-definition
))
944 (define-condition constant-modified
(reference-condition warning
)
945 ((fun-name :initarg
:fun-name
:reader constant-modified-fun-name
))
946 (:report
(lambda (c s
)
947 (format s
"~@<Destructive function ~S called on ~
949 (constant-modified-fun-name c
))))
950 (:default-initargs
:references
(list '(:ansi-cl
:special-operator quote
)
951 '(:ansi-cl
:section
(3 2 2 3)))))
953 (define-condition package-at-variance
(reference-condition simple-warning
)
955 (:default-initargs
:references
(list '(:ansi-cl
:macro defpackage
)
956 '(:sbcl
:variable
*on-package-variance
*))))
958 (define-condition package-at-variance-error
(reference-condition simple-condition
961 (:default-initargs
:references
(list '(:ansi-cl
:macro defpackage
))))
963 (define-condition defconstant-uneql
(reference-condition error
)
964 ((name :initarg
:name
:reader defconstant-uneql-name
)
965 (old-value :initarg
:old-value
:reader defconstant-uneql-old-value
)
966 (new-value :initarg
:new-value
:reader defconstant-uneql-new-value
))
968 (lambda (condition stream
)
970 "~@<The constant ~S is being redefined (from ~S to ~S)~@:>"
971 (defconstant-uneql-name condition
)
972 (defconstant-uneql-old-value condition
)
973 (defconstant-uneql-new-value condition
))))
974 (:default-initargs
:references
(list '(:ansi-cl
:macro defconstant
)
975 '(:sbcl
:node
"Idiosyncrasies"))))
977 (define-condition array-initial-element-mismatch
978 (reference-condition simple-warning
)
982 '(:ansi-cl
:function make-array
)
983 '(:ansi-cl
:function sb
!xc
:upgraded-array-element-type
))))
985 (define-condition type-warning
(reference-condition simple-warning
)
987 (:default-initargs
:references
(list '(:sbcl
:node
"Handling of Types"))))
988 (define-condition type-style-warning
(reference-condition simple-style-warning
)
990 (:default-initargs
:references
(list '(:sbcl
:node
"Handling of Types"))))
992 (define-condition local-argument-mismatch
(reference-condition simple-warning
)
994 (:default-initargs
:references
(list '(:ansi-cl
:section
(3 2 2 3)))))
996 (define-condition format-args-mismatch
(reference-condition)
998 (:default-initargs
:references
(list '(:ansi-cl
:section
(22 3 10 2)))))
1000 (define-condition format-too-few-args-warning
1001 (format-args-mismatch simple-warning
)
1003 (define-condition format-too-many-args-warning
1004 (format-args-mismatch simple-style-warning
)
1007 (define-condition implicit-generic-function-warning
(style-warning)
1008 ((name :initarg
:name
:reader implicit-generic-function-name
))
1010 (lambda (condition stream
)
1011 (format stream
"~@<Implicitly creating new generic function ~
1012 ~/sb-impl::print-symbol-with-prefix/.~:@>"
1013 (implicit-generic-function-name condition
)))))
1015 (define-condition extension-failure
(reference-condition simple-error
)
1018 (define-condition structure-initarg-not-keyword
1019 (reference-condition simple-style-warning
)
1021 (:default-initargs
:references
(list '(:ansi-cl
:section
(2 4 8 13)))))
1026 (define-condition package-lock-violation
(package-error
1029 ((current-package :initform
*package
*
1030 :reader package-lock-violation-in-package
))
1032 (lambda (condition stream
)
1033 (let ((control (simple-condition-format-control condition
))
1034 (error-package (package-name
1035 (package-error-package condition
)))
1036 (current-package (package-name
1037 (package-lock-violation-in-package condition
))))
1038 (format stream
"~@<Lock on package ~A violated~@[~{ when ~?~}~] ~
1039 while in package ~A.~:@>"
1042 (list control
(simple-condition-format-arguments condition
)))
1044 ;; no :default-initargs -- reference-stuff provided by the
1045 ;; signalling form in target-package.lisp
1048 "Subtype of CL:PACKAGE-ERROR. A subtype of this error is signalled
1049 when a package-lock is violated."))
1051 (define-condition package-locked-error
(package-lock-violation) ()
1054 "Subtype of SB-EXT:PACKAGE-LOCK-VIOLATION. An error of this type is
1055 signalled when an operation on a package violates a package lock."))
1057 (define-condition symbol-package-locked-error
(package-lock-violation)
1058 ((symbol :initarg
:symbol
:reader package-locked-error-symbol
))
1061 "Subtype of SB-EXT:PACKAGE-LOCK-VIOLATION. An error of this type is
1062 signalled when an operation on a symbol violates a package lock. The
1063 symbol that caused the violation is accessed by the function
1064 SB-EXT:PACKAGE-LOCKED-ERROR-SYMBOL."))
1068 (define-condition undefined-alien-error
(cell-error) ()
1070 (lambda (condition stream
)
1071 (if (slot-boundp condition
'name
)
1072 (format stream
"Undefined alien: ~S" (cell-error-name condition
))
1073 (format stream
"Undefined alien symbol.")))))
1075 (define-condition undefined-alien-variable-error
(undefined-alien-error) ()
1077 (lambda (condition stream
)
1078 (declare (ignore condition
))
1079 (format stream
"Attempt to access an undefined alien variable."))))
1081 (define-condition undefined-alien-function-error
(undefined-alien-error) ()
1083 (lambda (condition stream
)
1084 (if (and (slot-boundp condition
'name
)
1085 (cell-error-name condition
))
1086 (format stream
"The alien function ~s is undefined."
1087 (cell-error-name condition
))
1088 (format stream
"Attempt to call an undefined alien function.")))))
1091 ;;;; various other (not specified by ANSI) CONDITIONs
1093 ;;;; These might logically belong in other files; they're here, after
1094 ;;;; setup of CONDITION machinery, only because that makes it easier to
1095 ;;;; get cold init to work.
1097 ;;; OAOOM warning: see cross-condition.lisp
1098 (define-condition encapsulated-condition
(condition)
1099 ((condition :initarg
:condition
:reader encapsulated-condition
)))
1101 ;;; KLUDGE: a condition for floating point errors when we can't or
1102 ;;; won't figure out what type they are. (In FreeBSD and OpenBSD we
1103 ;;; don't know how, at least as of sbcl-0.6.7; in Linux we probably
1104 ;;; know how but the old code was broken by the conversion to POSIX
1105 ;;; signal handling and hasn't been fixed as of sbcl-0.6.7.)
1107 ;;; FIXME: Perhaps this should also be a base class for all
1108 ;;; floating point exceptions?
1109 (define-condition floating-point-exception
(arithmetic-error)
1110 ((flags :initarg
:traps
1112 :reader floating-point-exception-traps
))
1113 (:report
(lambda (condition stream
)
1115 "An arithmetic error ~S was signalled.~%"
1116 (type-of condition
))
1117 (let ((traps (floating-point-exception-traps condition
)))
1120 "Trapping conditions are: ~%~{ ~S~^~}~%"
1123 "No traps are enabled? How can this be?"
1126 (define-condition invalid-array-index-error
(type-error)
1127 ((array :initarg
:array
:reader invalid-array-index-error-array
)
1128 (axis :initarg
:axis
:reader invalid-array-index-error-axis
))
1130 (lambda (condition stream
)
1131 (let ((array (invalid-array-index-error-array condition
)))
1132 (format stream
"Index ~W out of bounds for ~@[axis ~W of ~]~S, ~
1133 should be nonnegative and <~W."
1134 (type-error-datum condition
)
1135 (when (> (array-rank array
) 1)
1136 (invalid-array-index-error-axis condition
))
1138 ;; Extract the bound from (INTEGER 0 (BOUND))
1139 (caaddr (type-error-expected-type condition
)))))))
1141 (define-condition invalid-array-error
(reference-condition type-error
) ()
1143 (lambda (condition stream
)
1144 (let ((*print-array
* nil
))
1146 "~@<Displaced array originally of type ~S has been invalidated ~
1147 due its displaced-to array ~S having become too small to hold ~
1148 it: the displaced array's dimensions have all been set to zero ~
1149 to trap accesses to it.~:@>"
1150 (type-error-expected-type condition
)
1151 (array-displacement (type-error-datum condition
))))))
1154 (list '(:ansi-cl
:function adjust-array
))))
1156 (define-condition index-too-large-error
(type-error)
1159 (lambda (condition stream
)
1161 "The index ~S is too large."
1162 (type-error-datum condition
)))))
1164 (define-condition bounding-indices-bad-error
(reference-condition type-error
)
1165 ((object :reader bounding-indices-bad-object
:initarg
:object
))
1167 (lambda (condition stream
)
1168 (let* ((datum (type-error-datum condition
))
1171 (object (bounding-indices-bad-object condition
)))
1175 "The bounding indices ~S and ~S are bad ~
1176 for a sequence of length ~S."
1177 start end
(length object
)))
1179 ;; from WITH-ARRAY-DATA
1181 "The START and END parameters ~S and ~S are ~
1182 bad for an array of total size ~S."
1183 start end
(array-total-size object
)))))))
1186 (list '(:ansi-cl
:glossary
"bounding index designator")
1187 '(:ansi-cl
:issue
"SUBSEQ-OUT-OF-BOUNDS:IS-AN-ERROR"))))
1189 (define-condition nil-array-accessed-error
(reference-condition type-error
)
1191 (:report
(lambda (condition stream
)
1192 (declare (ignore condition
))
1194 "An attempt to access an array of element-type ~
1195 NIL was made. Congratulations!")))
1197 :references
(list '(:ansi-cl
:function sb
!xc
:upgraded-array-element-type
)
1198 '(:ansi-cl
:section
(15 1 2 1))
1199 '(:ansi-cl
:section
(15 1 2 2)))))
1201 (define-condition namestring-parse-error
(parse-error)
1202 ((complaint :reader namestring-parse-error-complaint
:initarg
:complaint
)
1203 (args :reader namestring-parse-error-args
:initarg
:args
:initform nil
)
1204 (namestring :reader namestring-parse-error-namestring
:initarg
:namestring
)
1205 (offset :reader namestring-parse-error-offset
:initarg
:offset
))
1207 (lambda (condition stream
)
1209 "parse error in namestring: ~?~% ~A~% ~V@T^"
1210 (namestring-parse-error-complaint condition
)
1211 (namestring-parse-error-args condition
)
1212 (namestring-parse-error-namestring condition
)
1213 (namestring-parse-error-offset condition
)))))
1215 (define-condition simple-package-error
(simple-condition package-error
) ())
1217 (define-condition simple-reader-package-error
(simple-reader-error package-error
) ())
1219 (define-condition reader-eof-error
(end-of-file)
1220 ((context :reader reader-eof-error-context
:initarg
:context
))
1222 (lambda (condition stream
)
1224 "unexpected end of file on ~S ~A"
1225 (stream-error-stream condition
)
1226 (reader-eof-error-context condition
)))))
1228 (define-condition reader-impossible-number-error
(simple-reader-error)
1229 ((error :reader reader-impossible-number-error-error
:initarg
:error
))
1231 (lambda (condition stream
)
1232 (let ((error-stream (stream-error-stream condition
)))
1234 "READER-ERROR ~@[at ~W ~]on ~S:~%~?~%Original error: ~A"
1235 (file-position-or-nil-for-error error-stream
) error-stream
1236 (simple-condition-format-control condition
)
1237 (simple-condition-format-arguments condition
)
1238 (reader-impossible-number-error-error condition
))))))
1240 (define-condition standard-readtable-modified-error
(reference-condition error
)
1241 ((operation :initarg
:operation
:reader standard-readtable-modified-operation
))
1242 (:report
(lambda (condition stream
)
1243 (format stream
"~S would modify the standard readtable."
1244 (standard-readtable-modified-operation condition
))))
1245 (:default-initargs
:references
`((:ansi-cl
:section
(2 1 1 2))
1246 (:ansi-cl
:glossary
"standard readtable"))))
1248 (define-condition standard-pprint-dispatch-table-modified-error
1249 (reference-condition error
)
1250 ((operation :initarg
:operation
1251 :reader standard-pprint-dispatch-table-modified-operation
))
1252 (:report
(lambda (condition stream
)
1253 (format stream
"~S would modify the standard pprint dispatch table."
1254 (standard-pprint-dispatch-table-modified-operation
1257 :references
`((:ansi-cl
:glossary
"standard pprint dispatch table"))))
1259 (define-condition timeout
(serious-condition)
1260 ((seconds :initarg
:seconds
:initform nil
:reader timeout-seconds
))
1261 (:report
(lambda (condition stream
)
1262 (format stream
"Timeout occurred~@[ after ~A seconds~]."
1263 (timeout-seconds condition
)))))
1265 (define-condition io-timeout
(stream-error timeout
)
1266 ((direction :reader io-timeout-direction
:initarg
:direction
))
1268 (lambda (condition stream
)
1269 (declare (type stream stream
))
1271 "I/O timeout while doing ~(~A~) on ~S."
1272 (io-timeout-direction condition
)
1273 (stream-error-stream condition
)))))
1275 (define-condition deadline-timeout
(timeout) ()
1276 (:report
(lambda (condition stream
)
1277 (format stream
"A deadline was reached after ~A seconds."
1278 (timeout-seconds condition
)))))
1280 (define-condition declaration-type-conflict-error
(reference-condition
1284 :format-control
"symbol ~S cannot be both the name of a type and the name of a declaration"
1285 :references
(list '(:ansi-cl
:section
(3 8 21)))))
1287 ;;; Single stepping conditions
1289 (define-condition step-condition
()
1290 ((form :initarg
:form
:reader step-condition-form
))
1293 (:documentation
"Common base class of single-stepping conditions.
1294 STEP-CONDITION-FORM holds a string representation of the form being
1298 (setf (fdocumentation 'step-condition-form
'function
)
1299 "Form associated with the STEP-CONDITION.")
1301 (define-condition step-form-condition
(step-condition)
1302 ((args :initarg
:args
:reader step-condition-args
))
1304 (lambda (condition stream
)
1305 (let ((*print-circle
* t
)
1307 (*print-readably
* nil
))
1309 "Evaluating call:~%~< ~@;~A~:>~%~
1310 ~:[With arguments:~%~{ ~S~%~}~;With unknown arguments~]~%"
1311 (list (step-condition-form condition
))
1312 (eq (step-condition-args condition
) :unknown
)
1313 (step-condition-args condition
)))))
1315 (:documentation
"Condition signalled by code compiled with
1316 single-stepping information when about to execute a form.
1317 STEP-CONDITION-FORM holds the form, STEP-CONDITION-PATHNAME holds the
1318 pathname of the original file or NIL, and STEP-CONDITION-SOURCE-PATH
1319 holds the source-path to the original form within that file or NIL.
1320 Associated with this condition are always the restarts STEP-INTO,
1321 STEP-NEXT, and STEP-CONTINUE."))
1323 (define-condition step-result-condition
(step-condition)
1324 ((result :initarg
:result
:reader step-condition-result
)))
1327 (setf (fdocumentation 'step-condition-result
'function
)
1328 "Return values associated with STEP-VALUES-CONDITION as a list,
1329 or the variable value associated with STEP-VARIABLE-CONDITION.")
1331 (define-condition step-values-condition
(step-result-condition)
1334 (:documentation
"Condition signalled by code compiled with
1335 single-stepping information after executing a form.
1336 STEP-CONDITION-FORM holds the form, and STEP-CONDITION-RESULT holds
1337 the values returned by the form as a list. No associated restarts."))
1339 (define-condition step-finished-condition
(step-condition)
1342 (lambda (condition stream
)
1343 (declare (ignore condition
))
1344 (format stream
"Returning from STEP")))
1346 (:documentation
"Condition signaled when STEP returns."))
1348 ;;; A knob for muffling warnings, mostly for use while loading files.
1349 (defvar *muffled-warnings
* 'uninteresting-redefinition
1351 "A type that ought to specify a subtype of WARNING. Whenever a
1352 warning is signaled, if the warning if of this type and is not
1353 handled by any other handler, it will be muffled.")
1355 ;;; Various STYLE-WARNING signaled in the system.
1356 ;; For the moment, we're only getting into the details for function
1357 ;; redefinitions, but other redefinitions could be done later
1359 (define-condition redefinition-warning
(style-warning)
1362 :reader redefinition-warning-name
)
1364 :initarg
:new-location
1365 :reader redefinition-warning-new-location
)))
1367 (define-condition function-redefinition-warning
(redefinition-warning)
1369 :initarg
:new-function
1370 :reader function-redefinition-warning-new-function
)))
1372 (define-condition redefinition-with-defun
(function-redefinition-warning)
1374 (:report
(lambda (warning stream
)
1375 (format stream
"redefining ~/sb-impl::print-symbol-with-prefix/ ~
1377 (redefinition-warning-name warning
)))))
1379 (define-condition redefinition-with-defmacro
(function-redefinition-warning)
1381 (:report
(lambda (warning stream
)
1382 (format stream
"redefining ~/sb-impl::print-symbol-with-prefix/ ~
1384 (redefinition-warning-name warning
)))))
1386 (define-condition redefinition-with-defgeneric
(redefinition-warning)
1388 (:report
(lambda (warning stream
)
1389 (format stream
"redefining ~/sb-impl::print-symbol-with-prefix/ ~
1391 (redefinition-warning-name warning
)))))
1393 (define-condition redefinition-with-defmethod
(redefinition-warning)
1394 ((qualifiers :initarg
:qualifiers
1395 :reader redefinition-with-defmethod-qualifiers
)
1396 (specializers :initarg
:specializers
1397 :reader redefinition-with-defmethod-specializers
)
1398 (new-location :initarg
:new-location
1399 :reader redefinition-with-defmethod-new-location
)
1400 (old-method :initarg
:old-method
1401 :reader redefinition-with-defmethod-old-method
))
1402 (:report
(lambda (warning stream
)
1403 (format stream
"redefining ~S~{ ~S~} ~S in DEFMETHOD"
1404 (redefinition-warning-name warning
)
1405 (redefinition-with-defmethod-qualifiers warning
)
1406 (redefinition-with-defmethod-specializers warning
)))))
1408 ;;;; Deciding which redefinitions are "interesting".
1410 (defun function-file-namestring (function)
1412 (when (typep function
'sb
!eval
:interpreted-function
)
1413 (return-from function-file-namestring
1414 (sb!c
:definition-source-location-namestring
1415 (sb!eval
:interpreted-function-source-location function
))))
1416 (let* ((fun (%fun-fun function
))
1417 (code (fun-code-header fun
))
1418 (debug-info (%code-debug-info code
))
1419 (debug-source (when debug-info
1420 (sb!c
::debug-info-source debug-info
)))
1421 (namestring (when debug-source
1422 (sb!c
::debug-source-namestring debug-source
))))
1425 (defun interesting-function-redefinition-warning-p (warning old
)
1426 (let ((new (function-redefinition-warning-new-function warning
))
1427 (source-location (redefinition-warning-new-location warning
)))
1429 ;; compiled->interpreted is interesting.
1430 (and (typep old
'compiled-function
)
1431 (typep new
'(not compiled-function
)))
1432 ;; fin->regular is interesting except for interpreted->compiled.
1433 (and (typep old
'(and funcallable-instance
1434 #!+sb-eval
(not sb
!eval
:interpreted-function
)))
1435 (typep new
'(not funcallable-instance
)))
1436 ;; different file or unknown location is interesting.
1437 (let* ((old-namestring (function-file-namestring old
))
1439 (or (function-file-namestring new
)
1440 (when source-location
1441 (sb!c
::definition-source-location-namestring source-location
)))))
1442 (and (or (not old-namestring
)
1443 (not new-namestring
)
1444 (not (string= old-namestring new-namestring
))))))))
1446 (defun uninteresting-ordinary-function-redefinition-p (warning)
1448 (typep warning
'redefinition-with-defun
)
1450 (let ((name (redefinition-warning-name warning
)))
1451 (not (interesting-function-redefinition-warning-p
1452 warning
(or (fdefinition name
) (macro-function name
)))))))
1454 (defun uninteresting-macro-redefinition-p (warning)
1456 (typep warning
'redefinition-with-defmacro
)
1458 (let ((name (redefinition-warning-name warning
)))
1459 (not (interesting-function-redefinition-warning-p
1460 warning
(or (macro-function name
) (fdefinition name
)))))))
1462 (defun uninteresting-generic-function-redefinition-p (warning)
1464 (typep warning
'redefinition-with-defgeneric
)
1465 ;; Can't use the shared logic above, since GF's don't get a "new"
1466 ;; definition -- rather the FIN-FUNCTION is set.
1467 (let* ((name (redefinition-warning-name warning
))
1468 (old (fdefinition name
))
1469 (old-location (when (typep old
'generic-function
)
1470 (sb!pcl
::definition-source old
)))
1471 (old-namestring (when old-location
1472 (sb!c
:definition-source-location-namestring old-location
)))
1473 (new-location (redefinition-warning-new-location warning
))
1474 (new-namestring (when new-location
1475 (sb!c
:definition-source-location-namestring new-location
))))
1478 (string= old-namestring new-namestring
)))))
1480 (defun uninteresting-method-redefinition-p (warning)
1482 (typep warning
'redefinition-with-defmethod
)
1483 ;; Can't use the shared logic above, since GF's don't get a "new"
1484 ;; definition -- rather the FIN-FUNCTION is set.
1485 (let* ((old-method (redefinition-with-defmethod-old-method warning
))
1486 (old-location (sb!pcl
::definition-source old-method
))
1487 (old-namestring (when old-location
1488 (sb!c
:definition-source-location-namestring old-location
)))
1489 (new-location (redefinition-warning-new-location warning
))
1490 (new-namestring (when new-location
1491 (sb!c
:definition-source-location-namestring new-location
))))
1494 (string= new-namestring old-namestring
)))))
1496 (deftype uninteresting-redefinition
()
1497 '(or (satisfies uninteresting-ordinary-function-redefinition-p
)
1498 (satisfies uninteresting-macro-redefinition-p
)
1499 (satisfies uninteresting-generic-function-redefinition-p
)
1500 (satisfies uninteresting-method-redefinition-p
)))
1502 (define-condition redefinition-with-deftransform
(redefinition-warning)
1503 ((transform :initarg
:transform
1504 :reader redefinition-with-deftransform-transform
))
1505 (:report
(lambda (warning stream
)
1506 (format stream
"Overwriting ~S"
1507 (redefinition-with-deftransform-transform warning
)))))
1509 ;;; Various other STYLE-WARNINGS
1510 (define-condition dubious-asterisks-around-variable-name
1511 (style-warning simple-condition
)
1513 (:report
(lambda (warning stream
)
1514 (format stream
"~@?, even though the name follows~@
1515 the usual naming convention (names like *FOO*) for special variables"
1516 (simple-condition-format-control warning
)
1517 (simple-condition-format-arguments warning
)))))
1519 (define-condition asterisks-around-lexical-variable-name
1520 (dubious-asterisks-around-variable-name)
1523 (define-condition asterisks-around-constant-variable-name
1524 (dubious-asterisks-around-variable-name)
1527 ;; We call this UNDEFINED-ALIEN-STYLE-WARNING because there are some
1528 ;; subclasses of ERROR above having to do with undefined aliens.
1529 (define-condition undefined-alien-style-warning
(style-warning)
1530 ((symbol :initarg
:symbol
:reader undefined-alien-symbol
))
1531 (:report
(lambda (warning stream
)
1532 (format stream
"Undefined alien: ~S"
1533 (undefined-alien-symbol warning
)))))
1536 (define-condition lexical-environment-too-complex
(style-warning)
1537 ((form :initarg
:form
:reader lexical-environment-too-complex-form
)
1538 (lexenv :initarg
:lexenv
:reader lexical-environment-too-complex-lexenv
))
1539 (:report
(lambda (warning stream
)
1541 "~@<Native lexical environment too complex for ~
1542 SB-EVAL to evaluate ~S, falling back to ~
1543 SIMPLE-EVAL-IN-LEXENV. Lexenv: ~S~:@>"
1544 (lexical-environment-too-complex-form warning
)
1545 (lexical-environment-too-complex-lexenv warning
)))))
1547 ;; Although this has -ERROR- in the name, it's just a STYLE-WARNING.
1548 (define-condition character-decoding-error-in-comment
(style-warning)
1549 ((stream :initarg
:stream
:reader decoding-error-in-comment-stream
)
1550 (position :initarg
:position
:reader decoding-error-in-comment-position
))
1551 (:report
(lambda (warning stream
)
1553 "Character decoding error in a ~A-comment at ~
1554 position ~A reading source stream ~A, ~
1556 (decoding-error-in-comment-macro warning
)
1557 (decoding-error-in-comment-position warning
)
1558 (decoding-error-in-comment-stream warning
)))))
1560 (define-condition character-decoding-error-in-macro-char-comment
1561 (character-decoding-error-in-comment)
1562 ((char :initform
#\
; :initarg :char
1563 :reader character-decoding-error-in-macro-char-comment-char
)))
1565 (define-condition character-decoding-error-in-dispatch-macro-char-comment
1566 (character-decoding-error-in-comment)
1567 ;; ANSI doesn't give a way for a reader function invoked by a
1568 ;; dispatch macro character to determine which dispatch character
1569 ;; was used, so if a user wants to signal one of these from a custom
1570 ;; comment reader, he'll have to supply the :DISP-CHAR himself.
1571 ((disp-char :initform
#\
# :initarg
:disp-char
1572 :reader character-decoding-error-in-macro-char-comment-disp-char
)
1573 (sub-char :initarg
:sub-char
1574 :reader character-decoding-error-in-macro-char-comment-sub-char
)))
1576 (defun decoding-error-in-comment-macro (warning)
1578 (character-decoding-error-in-macro-char-comment
1579 (character-decoding-error-in-macro-char-comment-char warning
))
1580 (character-decoding-error-in-dispatch-macro-char-comment
1583 (character-decoding-error-in-macro-char-comment-disp-char warning
)
1584 (character-decoding-error-in-macro-char-comment-sub-char warning
)))))
1586 (define-condition deprecated-eval-when-situations
(style-warning)
1587 ((situations :initarg
:situations
1588 :reader deprecated-eval-when-situations-situations
))
1589 (:report
(lambda (warning stream
)
1590 (format stream
"using deprecated EVAL-WHEN situation names~{ ~S~}"
1591 (deprecated-eval-when-situations-situations warning
)))))
1593 (define-condition proclamation-mismatch
(condition)
1594 ((kind :initarg
:kind
:reader proclamation-mismatch-kind
)
1595 (description :initarg
:description
:reader proclamation-mismatch-description
:initform nil
)
1596 (name :initarg
:name
:reader proclamation-mismatch-name
)
1597 (old :initarg
:old
:reader proclamation-mismatch-old
)
1598 (new :initarg
:new
:reader proclamation-mismatch-new
))
1600 (lambda (condition stream
)
1601 ;; if we later decide we want package-qualified names, bind
1602 ;; *PACKAGE* to (find-package "KEYWORD") here.
1604 "~@<The new ~A proclamation for~@[ ~A~] ~S~
1606 does not match the old ~4:*~A~3* proclamation~
1608 (proclamation-mismatch-kind condition
)
1609 (proclamation-mismatch-description condition
)
1610 (proclamation-mismatch-name condition
)
1611 (proclamation-mismatch-new condition
)
1612 (proclamation-mismatch-old condition
)))))
1614 (define-condition type-proclamation-mismatch
(proclamation-mismatch)
1616 (:default-initargs
:kind
'type
))
1618 (define-condition type-proclamation-mismatch-warning
(style-warning
1619 type-proclamation-mismatch
)
1622 (defun type-proclamation-mismatch-warn (name old new
&optional description
)
1623 (warn 'type-proclamation-mismatch-warning
1624 :name name
:old old
:new new
:description description
))
1626 (define-condition ftype-proclamation-mismatch
(proclamation-mismatch)
1628 (:default-initargs
:kind
'ftype
))
1630 (define-condition ftype-proclamation-mismatch-warning
(style-warning
1631 ftype-proclamation-mismatch
)
1634 (defun ftype-proclamation-mismatch-warn (name old new
&optional description
)
1635 (warn 'ftype-proclamation-mismatch-warning
1636 :name name
:old old
:new new
:description description
))
1638 (define-condition ftype-proclamation-mismatch-error
(error
1639 ftype-proclamation-mismatch
)
1641 (:default-initargs
:kind
'ftype
:description
"known function"))
1644 ;;;; deprecation conditions
1646 (define-condition deprecation-condition
()
1647 ((name :initarg
:name
:reader deprecated-name
)
1648 (replacements :initarg
:replacements
:reader deprecated-name-replacements
)
1649 (since :initarg
:since
:reader deprecated-since
)
1650 (runtime-error :initarg
:runtime-error
:reader deprecated-name-runtime-error
)))
1652 (def!method print-object
((condition deprecation-condition
) stream
)
1653 (flet ((print-it (stream)
1654 (sb!impl
::print-deprecation-message
1655 (deprecated-name condition
)
1656 (deprecated-since condition
)
1657 (deprecated-name-replacements condition
)
1660 (print-unreadable-object (condition stream
:type t
)
1662 (print-it stream
))))
1664 (macrolet ((define-deprecation-warning
1665 (name superclass check-runtime-error format-string
)
1667 (define-condition ,name
(,superclass deprecation-condition
) ())
1669 (def!method print-object
:after
((condition ,name
) stream
)
1670 (when (and (not *print-escape
*)
1671 ,@(when check-runtime-error
1672 `((deprecated-name-runtime-error condition
))))
1673 (format stream
,format-string
1674 (deprecated-name condition
)))))))
1676 (define-deprecation-warning early-deprecation-warning style-warning nil
1678 "~%~@<~:@_In future SBCL versions ~
1679 ~/sb!impl:print-symbol-with-prefix/ will signal a full warning ~
1680 at compile-time.~:@>"
1682 "~%~@<~:@_In future SBCL versions ~
1683 ~/sb-impl:print-symbol-with-prefix/ will signal a full warning ~
1684 at compile-time.~:@>")
1686 (define-deprecation-warning late-deprecation-warning warning t
1688 "~%~@<~:@_In future SBCL versions ~
1689 ~/sb!impl:print-symbol-with-prefix/ will signal a runtime ~
1692 "~%~@<~:@_In future SBCL versions ~
1693 ~/sb-impl:print-symbol-with-prefix/ will signal a runtime ~
1696 (define-deprecation-warning final-deprecation-warning warning t
1698 "~%~@<~:@_An error will be signaled at runtime for ~
1699 ~/sb!impl:print-symbol-with-prefix/.~:@>"
1701 "~%~@<~:@_An error will be signaled at runtime for ~
1702 ~/sb-impl:print-symbol-with-prefix/.~:@>"))
1704 (define-condition deprecation-error
(error deprecation-condition
)
1707 ;;;; restart definitions
1709 (define-condition abort-failure
(control-error) ()
1711 "An ABORT restart was found that failed to transfer control dynamically."))
1713 (defun abort (&optional condition
)
1715 "Transfer control to a restart named ABORT, signalling a CONTROL-ERROR if
1717 (invoke-restart (find-restart-or-control-error 'abort condition
))
1718 ;; ABORT signals an error in case there was a restart named ABORT
1719 ;; that did not transfer control dynamically. This could happen with
1721 (error 'abort-failure
))
1723 (defun muffle-warning (&optional condition
)
1725 "Transfer control to a restart named MUFFLE-WARNING, signalling a
1726 CONTROL-ERROR if none exists."
1727 (invoke-restart (find-restart-or-control-error 'muffle-warning condition
)))
1729 (defun try-restart (name condition
&rest arguments
)
1730 (let ((restart (find-restart name condition
)))
1732 (apply #'invoke-restart restart arguments
))))
1734 (macrolet ((define-nil-returning-restart (name args doc
)
1735 #!-sb-doc
(declare (ignore doc
))
1736 `(defun ,name
(,@args
&optional condition
)
1738 (try-restart ',name condition
,@args
))))
1739 (define-nil-returning-restart continue
()
1740 "Transfer control to a restart named CONTINUE, or return NIL if none exists.")
1741 (define-nil-returning-restart store-value
(value)
1742 "Transfer control and VALUE to a restart named STORE-VALUE, or
1743 return NIL if none exists.")
1744 (define-nil-returning-restart use-value
(value)
1745 "Transfer control and VALUE to a restart named USE-VALUE, or
1746 return NIL if none exists.")
1747 (define-nil-returning-restart print-unreadably
()
1748 "Transfer control to a restart named SB-EXT:PRINT-UNREADABLY, or
1749 return NIL if none exists."))
1751 ;;; single-stepping restarts
1753 (macrolet ((def (name doc
)
1754 #!-sb-doc
(declare (ignore doc
))
1755 `(defun ,name
(condition)
1757 (invoke-restart (find-restart-or-control-error ',name condition
)))))
1759 "Transfers control to the STEP-CONTINUE restart associated with
1760 the condition, continuing execution without stepping. Signals a
1761 CONTROL-ERROR if the restart does not exist.")
1763 "Transfers control to the STEP-NEXT restart associated with the
1764 condition, executing the current form without stepping and continuing
1765 stepping with the next form. Signals CONTROL-ERROR is the restart does
1768 "Transfers control to the STEP-INTO restart associated with the
1769 condition, stepping into the current form. Signals a CONTROL-ERROR is
1770 the restart does not exist."))
1772 ;;; Compiler macro magic
1774 (define-condition compiler-macro-keyword-problem
()
1775 ((argument :initarg
:argument
:reader compiler-macro-keyword-argument
))
1776 (:report
(lambda (condition stream
)
1777 (format stream
"~@<Argument ~S in keyword position is not ~
1778 a self-evaluating symbol, preventing compiler-macro ~
1780 (compiler-macro-keyword-argument condition
)))))
1782 ;; After (or if) we deem this the optimal name for this condition,
1783 ;; it should be exported from SB-EXT so that people can muffle it.
1784 (define-condition sb
!c
:inlining-dependency-failure
(simple-style-warning) ())
1786 (/show0
"condition.lisp end of file")