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 ;;;; miscellaneous support utilities
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.)
33 (ignore-errors (file-position stream pos))
34 (ignore-errors (file-position stream))))
36 ;;;; the CONDITION class
38 (/show0 "condition.lisp 20")
40 (eval-when (:compile-toplevel :load-toplevel :execute)
42 (/show0 "condition.lisp 24")
44 (def!struct (condition-classoid (:include classoid)
45 (:constructor make-condition-classoid))
46 ;; list of CONDITION-SLOT structures for the direct slots of this
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
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))
65 (/show0 "condition.lisp 49")
69 (!defstruct-with-alternate-metaclass condition
70 :slot-names (actual-initargs assigned-slots)
71 :boa-constructor %make-condition-object
73 :metaclass-name condition-classoid
74 :metaclass-constructor make-condition-classoid
77 (defun make-condition-object (actual-initargs)
78 (%make-condition-object actual-initargs nil))
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
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))
97 (documentation nil :type (or string null)))
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"))
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
128 (declare (notinline find-classoid))
129 (find-classoid 'condition)))
130 (lambda (cond stream)
131 (format stream "Condition ~S was signalled." (type-of cond))))
133 (eval-when (:compile-toplevel :load-toplevel :execute)
135 (defun find-condition-layout (name parent-types)
136 (let* ((cpl (remove-duplicates
140 (condition-classoid-cpl
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
151 (order-layout-inherits (concatenate 'simple-vector
152 (layout-inherits cond-layout)
153 (mapcar #'classoid-layout cpl)))))
155 (not (mismatch (layout-inherits olayout) new-inherits)))
157 (make-layout :classoid (make-undefined-classoid name)
158 :inherits new-inherits
160 :length (layout-length cond-layout)))))
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)
174 (if (and (typep x 'simple-condition) (slot-value x 'format-control))
175 (print-unreadable-object (x stream :type t :identity t)
176 (write (simple-condition-format-control x)
179 (print-unreadable-object (x stream :type t :identity t)))
180 ;; KLUDGE: A comment from CMU CL here said
181 ;; 7/13/98 BUG? CPL is not sorted and results here depend on order of
182 ;; superclasses in define-condition call!
183 (dolist (class (condition-classoid-cpl (classoid-of x))
184 (error "no REPORT? shouldn't happen!"))
185 (let ((report (condition-classoid-report class)))
187 (return (funcall report x stream)))))))
189 ;;;; slots of CONDITION objects
191 (defvar *empty-condition-slot* '(empty))
193 (defun find-slot-default (class slot)
194 (let ((initargs (condition-slot-initargs slot))
195 (cpl (condition-classoid-cpl class)))
197 (let ((default-initargs (condition-classoid-default-initargs class)))
198 (dolist (initarg initargs)
199 (let ((val (getf default-initargs initarg *empty-condition-slot*)))
200 (unless (eq val *empty-condition-slot*)
201 (return-from find-slot-default
206 (if (condition-slot-initform-p slot)
207 (let ((initform (condition-slot-initform slot)))
208 (if (functionp initform)
211 (error "unbound condition slot: ~S" (condition-slot-name slot)))))
213 (defun find-condition-class-slot (condition-class slot-name)
215 (condition-classoid-cpl condition-class)
216 (error "There is no slot named ~S in ~S."
217 slot-name condition-class))
218 (dolist (slot (condition-classoid-slots sclass))
219 (when (eq (condition-slot-name slot) slot-name)
220 (return-from find-condition-class-slot slot)))))
222 (defun condition-writer-function (condition new-value name)
223 (dolist (cslot (condition-classoid-class-slots
224 (layout-classoid (%instance-layout condition)))
225 (setf (getf (condition-assigned-slots condition) name)
227 (when (eq (condition-slot-name cslot) name)
228 (return (setf (car (condition-slot-cell cslot)) new-value)))))
230 (defun condition-reader-function (condition name)
231 (let ((class (layout-classoid (%instance-layout condition))))
232 (dolist (cslot (condition-classoid-class-slots class))
233 (when (eq (condition-slot-name cslot) name)
234 (return-from condition-reader-function
235 (car (condition-slot-cell cslot)))))
236 (let ((val (getf (condition-assigned-slots condition) name
237 *empty-condition-slot*)))
238 (if (eq val *empty-condition-slot*)
239 (let ((actual-initargs (condition-actual-initargs condition))
240 (slot (find-condition-class-slot class name)))
242 (error "missing slot ~S of ~S" name condition))
243 (do ((initargs actual-initargs (cddr initargs)))
245 (setf (getf (condition-assigned-slots condition) name)
246 (find-slot-default class slot)))
247 (when (member (car initargs) (condition-slot-initargs slot))
248 (return-from condition-reader-function
249 (setf (getf (condition-assigned-slots condition)
256 (defun make-condition (type &rest args)
258 "Make an instance of a condition object using the specified initargs."
259 ;; Note: ANSI specifies no exceptional situations in this function.
260 ;; signalling simple-type-error would not be wrong.
261 (let* ((type (or (and (symbolp type) (find-classoid type nil))
263 (class (typecase type
264 (condition-classoid type)
267 (return-from make-condition
268 (apply #'make-instance type args)))
270 (error 'simple-type-error
272 :expected-type 'condition-class
273 :format-control "~S is not a condition class."
274 :format-arguments (list type)))
276 (error 'simple-type-error
278 :expected-type 'condition-class
280 "~s doesn't designate a condition class."
281 :format-arguments (list type)))))
282 (res (make-condition-object args)))
283 (setf (%instance-layout res) (classoid-layout class))
284 ;; Set any class slots with initargs present in this call.
285 (dolist (cslot (condition-classoid-class-slots class))
286 (dolist (initarg (condition-slot-initargs cslot))
287 (let ((val (getf args initarg *empty-condition-slot*)))
288 (unless (eq val *empty-condition-slot*)
289 (setf (car (condition-slot-cell cslot)) val)))))
290 ;; Default any slots with non-constant defaults now.
291 (dolist (hslot (condition-classoid-hairy-slots class))
292 (when (dolist (initarg (condition-slot-initargs hslot) t)
293 (unless (eq (getf args initarg *empty-condition-slot*)
294 *empty-condition-slot*)
296 (setf (getf (condition-assigned-slots res) (condition-slot-name hslot))
297 (find-slot-default class hslot))))
300 ;;;; DEFINE-CONDITION
302 (eval-when (:compile-toplevel :load-toplevel :execute)
303 (defun %compiler-define-condition (name direct-supers layout
304 all-readers all-writers)
305 (with-single-package-locked-error
306 (:symbol name "defining ~A as a condition")
307 (sb!xc:proclaim `(ftype (function (t) t) ,@all-readers))
308 (sb!xc:proclaim `(ftype (function (t t) t) ,@all-writers))
309 (multiple-value-bind (class old-layout)
310 (insured-find-classoid name
311 #'condition-classoid-p
312 #'make-condition-classoid)
313 (setf (layout-classoid layout) class)
314 (setf (classoid-direct-superclasses class)
315 (mapcar #'find-classoid direct-supers))
316 (cond ((not old-layout)
317 (register-layout layout))
318 ((not *type-system-initialized*)
319 (setf (layout-classoid old-layout) class)
320 (setq layout old-layout)
321 (unless (eq (classoid-layout class) layout)
322 (register-layout layout)))
323 ((redefine-layout-warning "current"
326 (layout-length layout)
327 (layout-inherits layout)
328 (layout-depthoid layout)
329 (layout-n-untagged-slots layout))
330 (register-layout layout :invalidate t))
331 ((not (classoid-layout class))
332 (register-layout layout)))
334 (setf (layout-info layout)
336 ;; KLUDGE: There's a FIND-CLASS DEFTRANSFORM for constant class
337 ;; names which creates fast but non-cold-loadable, non-compact
338 ;; code. In this context, we'd rather have compact, cold-loadable
339 ;; code. -- WHN 19990928
340 (declare (notinline find-classoid))
341 (layout-info (classoid-layout (find-classoid 'condition)))))
343 (setf (find-classoid name) class)
345 ;; Initialize CPL slot.
346 (setf (condition-classoid-cpl class)
347 (remove-if-not #'condition-classoid-p
348 (std-compute-class-precedence-list class)))))
352 ;;; Compute the effective slots of CLASS, copying inherited slots and
353 ;;; destructively modifying direct slots.
355 ;;; FIXME: It'd be nice to explain why it's OK to destructively modify
356 ;;; direct slots. Presumably it follows from the semantics of
357 ;;; inheritance and redefinition of conditions, but finding the cite
358 ;;; and documenting it here would be good. (Or, if this is not in fact
359 ;;; ANSI-compliant, fixing it would also be good.:-)
360 (defun compute-effective-slots (class)
361 (collect ((res (copy-list (condition-classoid-slots class))))
362 (dolist (sclass (cdr (condition-classoid-cpl class)))
363 (dolist (sslot (condition-classoid-slots sclass))
364 (let ((found (find (condition-slot-name sslot) (res)
365 :key #'condition-slot-name)))
367 (setf (condition-slot-initargs found)
368 (union (condition-slot-initargs found)
369 (condition-slot-initargs sslot)))
370 (unless (condition-slot-initform-p found)
371 (setf (condition-slot-initform-p found)
372 (condition-slot-initform-p sslot))
373 (setf (condition-slot-initform found)
374 (condition-slot-initform sslot)))
375 (unless (condition-slot-allocation found)
376 (setf (condition-slot-allocation found)
377 (condition-slot-allocation sslot))))
379 (res (copy-structure sslot)))))))
382 ;;; Early definitions of slot accessor creators.
384 ;;; Slot accessors must be generic functions, but ANSI does not seem
385 ;;; to specify any of them, and we cannot support it before end of
386 ;;; warm init. So we use ordinary functions inside SBCL, and switch to
387 ;;; GFs only at the end of building.
388 (declaim (notinline install-condition-slot-reader
389 install-condition-slot-writer))
390 (defun install-condition-slot-reader (name condition slot-name)
391 (declare (ignore condition))
392 (setf (fdefinition name)
394 (condition-reader-function condition slot-name))))
395 (defun install-condition-slot-writer (name condition slot-name)
396 (declare (ignore condition))
397 (setf (fdefinition name)
398 (lambda (new-value condition)
399 (condition-writer-function condition new-value slot-name))))
401 (defvar *define-condition-hooks* nil)
403 (defun %set-condition-report (name report)
404 (setf (condition-classoid-report (find-classoid name))
407 (defun %define-condition (name parent-types layout slots documentation
408 default-initargs all-readers all-writers
410 (with-single-package-locked-error
411 (:symbol name "defining ~A as a condition")
412 (%compiler-define-condition name parent-types layout all-readers all-writers)
413 (sb!c:with-source-location (source-location)
414 (setf (layout-source-location layout)
416 (let ((class (find-classoid name)))
417 (setf (condition-classoid-slots class) slots)
418 (setf (condition-classoid-default-initargs class) default-initargs)
419 (setf (fdocumentation name 'type) documentation)
423 ;; Set up reader and writer functions.
424 (let ((slot-name (condition-slot-name slot)))
425 (dolist (reader (condition-slot-readers slot))
426 (install-condition-slot-reader reader name slot-name))
427 (dolist (writer (condition-slot-writers slot))
428 (install-condition-slot-writer writer name slot-name))))
430 ;; Compute effective slots and set up the class and hairy slots
431 ;; (subsets of the effective slots.)
432 (let ((eslots (compute-effective-slots class))
435 (mapcar #'condition-classoid-default-initargs
436 (condition-classoid-cpl class)))))
437 (dolist (slot eslots)
438 (ecase (condition-slot-allocation slot)
440 (unless (condition-slot-cell slot)
441 (setf (condition-slot-cell slot)
442 (list (if (condition-slot-initform-p slot)
443 (let ((initform (condition-slot-initform slot)))
444 (if (functionp initform)
447 *empty-condition-slot*))))
448 (push slot (condition-classoid-class-slots class)))
450 (setf (condition-slot-allocation slot) :instance)
451 (when (or (functionp (condition-slot-initform slot))
452 (dolist (initarg (condition-slot-initargs slot) nil)
453 (when (functionp (getf e-def-initargs initarg))
455 (push slot (condition-classoid-hairy-slots class)))))))
456 (when (boundp '*define-condition-hooks*)
457 (dolist (fun *define-condition-hooks*)
458 (funcall fun class))))
461 (defmacro define-condition (name (&rest parent-types) (&rest slot-specs)
464 "DEFINE-CONDITION Name (Parent-Type*) (Slot-Spec*) Option*
465 Define NAME as a condition type. This new type inherits slots and its
466 report function from the specified PARENT-TYPEs. A slot spec is a list of:
467 (slot-name :reader <rname> :initarg <iname> {Option Value}*
469 The DEFINE-CLASS slot options :ALLOCATION, :INITFORM, [slot] :DOCUMENTATION
470 and :TYPE and the overall options :DEFAULT-INITARGS and
471 [type] :DOCUMENTATION are also allowed.
473 The :REPORT option is peculiar to DEFINE-CONDITION. Its argument is either
474 a string or a two-argument lambda or function name. If a function, the
475 function is called with the condition and stream to report the condition.
476 If a string, the string is printed.
478 Condition types are classes, but (as allowed by ANSI and not as described in
479 CLtL2) are neither STANDARD-OBJECTs nor STRUCTURE-OBJECTs. WITH-SLOTS and
480 SLOT-VALUE may not be used on condition objects."
481 (let* ((parent-types (or parent-types '(condition)))
482 (layout (find-condition-layout name parent-types))
485 (default-initargs ()))
487 (all-readers nil append)
488 (all-writers nil append))
489 (dolist (spec slot-specs)
490 (when (keywordp spec)
491 (warn "Keyword slot name indicates probable syntax error:~% ~S"
493 (let* ((spec (if (consp spec) spec (list spec)))
494 (slot-name (first spec))
495 (allocation :instance)
502 (do ((options (rest spec) (cddr options)))
504 (unless (and (consp options) (consp (cdr options)))
505 (error "malformed condition slot spec:~% ~S." spec))
506 (let ((arg (second options)))
507 (case (first options)
508 (:reader (readers arg))
509 (:writer (writers arg))
512 (writers `(setf ,arg)))
515 (error "more than one :INITFORM in ~S" spec))
518 (:initarg (initargs arg))
520 (setq allocation arg))
523 (error "more than one :DOCUMENTATION in ~S" spec))
524 (unless (stringp arg)
525 (error "slot :DOCUMENTATION argument is not a string: ~S"
527 (setq documentation arg))
530 (error "unknown slot option:~% ~S" (first options))))))
532 (all-readers (readers))
533 (all-writers (writers))
534 (slots `(make-condition-slot
536 :initargs ',(initargs)
539 :initform-p ',initform-p
540 :documentation ',documentation
542 ,(if (sb!xc:constantp initform)
543 `',(constant-form-value initform)
544 `#'(lambda () ,initform)))))))
546 (dolist (option options)
547 (unless (consp option)
548 (error "bad option:~% ~S" option))
550 (:documentation (setq documentation (second option)))
552 (let ((arg (second option)))
555 `#'(lambda (condition stream)
556 (declare (ignore condition))
557 (write-string ,arg stream))
558 `#'(lambda (condition stream)
559 (funcall #',arg condition stream))))))
561 (do ((initargs (rest option) (cddr initargs)))
563 (let ((val (second initargs)))
564 (setq default-initargs
565 (list* `',(first initargs)
566 (if (sb!xc:constantp val)
567 `',(constant-form-value val)
569 default-initargs)))))
571 (error "unknown option: ~S" (first option)))))
574 (eval-when (:compile-toplevel)
575 (%compiler-define-condition ',name ',parent-types ',layout
576 ',(all-readers) ',(all-writers)))
577 (eval-when (:load-toplevel :execute)
578 (%define-condition ',name
583 (list ,@default-initargs)
586 (sb!c:source-location))
587 ;; This needs to be after %DEFINE-CONDITION in case :REPORT
588 ;; is a lambda referring to condition slot accessors:
589 ;; they're not proclaimed as functions before it has run if
590 ;; we're under EVAL or loaded as source.
591 (%set-condition-report ',name ,report)
594 ;;;; various CONDITIONs specified by ANSI
596 (define-condition serious-condition (condition) ())
598 (define-condition error (serious-condition) ())
600 (define-condition warning (condition) ())
601 (define-condition style-warning (warning) ())
603 (defun simple-condition-printer (condition stream)
604 (let ((control (simple-condition-format-control condition)))
606 (apply #'format stream
608 (simple-condition-format-arguments condition))
609 (error "No format-control for ~S" condition))))
611 (define-condition simple-condition ()
612 ((format-control :reader simple-condition-format-control
613 :initarg :format-control
615 :type format-control)
616 (format-arguments :reader simple-condition-format-arguments
617 :initarg :format-arguments
620 (:report simple-condition-printer))
622 (define-condition simple-warning (simple-condition warning) ())
624 (define-condition simple-error (simple-condition error) ())
626 (define-condition storage-condition (serious-condition) ())
628 (define-condition type-error (error)
629 ((datum :reader type-error-datum :initarg :datum)
630 (expected-type :reader type-error-expected-type :initarg :expected-type))
632 (lambda (condition stream)
634 "~@<The value ~2I~:_~S ~I~_is not of type ~2I~_~S.~:>"
635 (type-error-datum condition)
636 (type-error-expected-type condition)))))
638 (def!method print-object ((condition type-error) stream)
640 (flet ((maybe-string (thing)
642 (write-to-string thing :lines 1 :readably nil :array nil :pretty t))))
643 (let ((type (maybe-string (type-error-expected-type condition)))
644 (datum (maybe-string (type-error-datum condition))))
646 (print-unreadable-object (condition stream :type t)
647 (format stream "~@<expected-type: ~A ~_datum: ~A~:@>" type datum))
648 (call-next-method))))
651 ;;; not specified by ANSI, but too useful not to have around.
652 (define-condition simple-style-warning (simple-condition style-warning) ())
653 (define-condition simple-type-error (simple-condition type-error) ())
655 ;; Can't have a function called SIMPLE-TYPE-ERROR or TYPE-ERROR...
656 (declaim (ftype (sfunction (t t t &rest t) nil) bad-type))
657 (defun bad-type (datum type control &rest arguments)
658 (error 'simple-type-error
661 :format-control control
662 :format-arguments arguments))
664 (define-condition program-error (error) ())
665 (define-condition parse-error (error) ())
666 (define-condition control-error (error) ())
667 (define-condition stream-error (error)
668 ((stream :reader stream-error-stream :initarg :stream)))
670 (define-condition end-of-file (stream-error) ()
672 (lambda (condition stream)
675 (stream-error-stream condition)))))
677 (define-condition closed-stream-error (stream-error) ()
679 (lambda (condition stream)
680 (format stream "~S is closed" (stream-error-stream condition)))))
682 (define-condition file-error (error)
683 ((pathname :reader file-error-pathname :initarg :pathname))
685 (lambda (condition stream)
686 (format stream "error on file ~S" (file-error-pathname condition)))))
688 (define-condition package-error (error)
689 ((package :reader package-error-package :initarg :package)))
691 (define-condition cell-error (error)
692 ((name :reader cell-error-name :initarg :name)))
694 (def!method print-object ((condition cell-error) stream)
695 (if (and *print-escape* (slot-boundp condition 'name))
696 (print-unreadable-object (condition stream :type t :identity t)
697 (princ (cell-error-name condition) stream))
700 (define-condition unbound-variable (cell-error) ()
702 (lambda (condition stream)
704 "The variable ~S is unbound."
705 (cell-error-name condition)))))
707 (define-condition undefined-function (cell-error) ()
709 (lambda (condition stream)
711 "The function ~/sb-impl::print-symbol-with-prefix/ 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 (defun stream-error-position-info (stream &optional position)
773 (unless (interactive-stream-p stream)
774 (let ((now (file-position-or-nil-for-error stream))
776 (when (and (not pos) now (plusp now))
777 ;; FILE-POSITION is the next character -- error is at the previous one.
781 (< pos sb!xc:array-dimension-limit)
782 (file-position stream :start))
784 (make-string pos :element-type (stream-element-type stream))))
785 (when (= pos (read-sequence string stream))
786 ;; Lines count from 1, columns from 0. It's stupid and traditional.
787 (setq lineno (1+ (count #\Newline string))
788 colno (- pos (or (position #\Newline string :from-end t) 0)))))
789 (file-position-or-nil-for-error stream now))
790 (remove-if-not #'second
791 (list (list :line lineno)
793 (list :file-position pos)))))))
795 ;;; base REPORTing of a READER-ERROR
797 ;;; When SIMPLE, we expect and use SIMPLE-CONDITION-ish FORMAT-CONTROL
798 ;;; and FORMAT-ARGS slots.
799 (defun %report-reader-error (condition stream &key simple position)
800 (let ((error-stream (stream-error-stream condition)))
801 (pprint-logical-block (stream nil)
803 (apply #'format stream
804 (simple-condition-format-control condition)
805 (simple-condition-format-arguments condition))
806 (prin1 (class-name (class-of condition)) stream))
807 (format stream "~2I~@[~_~_~:{~:(~A~): ~S~:^, ~:_~}~]~_~_Stream: ~S"
808 (stream-error-position-info error-stream position)
811 ;;;; special SBCL extension conditions
813 ;;; an error apparently caused by a bug in SBCL itself
815 ;;; Note that we don't make any serious effort to use this condition
816 ;;; for *all* errors in SBCL itself. E.g. type errors and array
817 ;;; indexing errors can occur in functions called from SBCL code, and
818 ;;; will just end up as ordinary TYPE-ERROR or invalid index error,
819 ;;; because the signalling code has no good way to know that the
820 ;;; underlying problem is a bug in SBCL. But in the fairly common case
821 ;;; that the signalling code does know that it's found a bug in SBCL,
822 ;;; this condition is appropriate, reusing boilerplate and helping
823 ;;; users to recognize it as an SBCL bug.
824 (define-condition bug (simple-error)
827 (lambda (condition stream)
830 (simple-condition-format-control condition)
831 (simple-condition-format-arguments condition)
832 "~@<This is probably a bug in SBCL itself. (Alternatively, ~
833 SBCL might have been corrupted by bad user code, e.g. by an ~
834 undefined Lisp operation like ~S, or by stray pointers from ~
835 alien code or from unsafe Lisp code; or there might be a bug ~
836 in the OS or hardware that SBCL is running on.) If it seems to ~
837 be a bug in SBCL itself, the maintainers would like to know ~
838 about it. Bug reports are welcome on the SBCL ~
839 mailing lists, which you can find at ~
840 <http://sbcl.sourceforge.net/>.~:@>"
841 '((fmakunbound 'compile))))))
843 (define-condition simple-storage-condition (storage-condition simple-condition)
846 ;;; a condition for use in stubs for operations which aren't supported
847 ;;; on some platforms
849 ;;; E.g. in sbcl-0.7.0.5, it might be appropriate to do something like
850 ;;; #-(or freebsd linux)
851 ;;; (defun load-foreign (&rest rest)
852 ;;; (error 'unsupported-operator :name 'load-foreign))
853 ;;; #+(or freebsd linux)
854 ;;; (defun load-foreign ... actual definition ...)
855 ;;; By signalling a standard condition in this case, we make it
856 ;;; possible for test code to distinguish between (1) intentionally
857 ;;; unimplemented and (2) unintentionally just screwed up somehow.
858 ;;; (Before this condition was defined, test code tried to deal with
859 ;;; this by checking for FBOUNDP, but that didn't work reliably. In
860 ;;; sbcl-0.7.0, a package screwup left the definition of
861 ;;; LOAD-FOREIGN in the wrong package, so it was unFBOUNDP even on
862 ;;; architectures where it was supposed to be supported, and the
863 ;;; regression tests cheerfully passed because they assumed that
864 ;;; unFBOUNDPness meant they were running on an system which didn't
865 ;;; support the extension.)
866 (define-condition unsupported-operator (simple-error) ())
868 ;;; (:ansi-cl :function remove)
869 ;;; (:ansi-cl :section (a b c))
870 ;;; (:ansi-cl :glossary "similar")
872 ;;; (:sbcl :node "...")
873 ;;; (:sbcl :variable *ed-functions*)
875 ;;; FIXME: this is not the right place for this.
876 (defun print-reference (reference stream)
877 (ecase (car reference)
879 (format stream "AMOP")
881 (destructuring-bind (type data) (cdr reference)
883 (:readers "Readers for ~:(~A~) Metaobjects"
884 (substitute #\ #\- (symbol-name data)))
886 (format stream "Initialization of ~:(~A~) Metaobjects"
887 (substitute #\ #\- (symbol-name data))))
888 (:generic-function (format stream "Generic Function ~S" data))
889 (:function (format stream "Function ~S" data))
890 (:section (format stream "Section ~{~D~^.~}" data)))))
892 (format stream "The ANSI Standard")
894 (destructuring-bind (type data) (cdr reference)
896 (:function (format stream "Function ~S" data))
897 (:special-operator (format stream "Special Operator ~S" data))
898 (:macro (format stream "Macro ~S" data))
899 (:section (format stream "Section ~{~D~^.~}" data))
900 (:glossary (format stream "Glossary entry for ~S" data))
901 (:issue (format stream "writeup for Issue ~A" data)))))
903 (format stream "The SBCL Manual")
905 (destructuring-bind (type data) (cdr reference)
907 (:node (format stream "Node ~S" data))
908 (:variable (format stream "Variable ~S" data))
909 (:function (format stream "Function ~S" data)))))
910 ;; FIXME: other documents (e.g. CLIM, Franz documentation :-)
912 (define-condition reference-condition ()
913 ((references :initarg :references :reader reference-condition-references)))
914 (defvar *print-condition-references* t)
915 (def!method print-object :around ((o reference-condition) s)
917 (unless (or *print-escape* *print-readably*)
918 (when (and *print-condition-references*
919 (reference-condition-references o))
920 (format s "~&See also:~%")
921 (pprint-logical-block (s nil :per-line-prefix " ")
922 (do* ((rs (reference-condition-references o) (cdr rs))
923 (r (car rs) (car rs)))
925 (print-reference r s)
926 (unless (null (cdr rs))
929 (define-condition simple-reference-error (reference-condition simple-error)
932 (define-condition simple-reference-warning (reference-condition simple-warning)
935 (define-condition arguments-out-of-domain-error
936 (arithmetic-error reference-condition)
939 (define-condition duplicate-definition (reference-condition warning)
940 ((name :initarg :name :reader duplicate-definition-name))
941 (:report (lambda (c s)
942 (format s "~@<Duplicate definition for ~S found in ~
944 (duplicate-definition-name c))))
945 (:default-initargs :references (list '(:ansi-cl :section (3 2 2 3)))))
947 (define-condition constant-modified (reference-condition warning)
948 ((fun-name :initarg :fun-name :reader constant-modified-fun-name))
949 (:report (lambda (c s)
950 (format s "~@<Destructive function ~S called on ~
952 (constant-modified-fun-name c))))
953 (:default-initargs :references (list '(:ansi-cl :special-operator quote)
954 '(:ansi-cl :section (3 2 2 3)))))
956 (define-condition package-at-variance (reference-condition simple-warning)
958 (:default-initargs :references (list '(:ansi-cl :macro defpackage))))
960 (define-condition defconstant-uneql (reference-condition error)
961 ((name :initarg :name :reader defconstant-uneql-name)
962 (old-value :initarg :old-value :reader defconstant-uneql-old-value)
963 (new-value :initarg :new-value :reader defconstant-uneql-new-value))
965 (lambda (condition stream)
967 "~@<The constant ~S is being redefined (from ~S to ~S)~@:>"
968 (defconstant-uneql-name condition)
969 (defconstant-uneql-old-value condition)
970 (defconstant-uneql-new-value condition))))
971 (:default-initargs :references (list '(:ansi-cl :macro defconstant)
972 '(:sbcl :node "Idiosyncrasies"))))
974 (define-condition array-initial-element-mismatch
975 (reference-condition simple-warning)
979 '(:ansi-cl :function make-array)
980 '(:ansi-cl :function sb!xc:upgraded-array-element-type))))
982 (define-condition type-warning (reference-condition simple-warning)
984 (:default-initargs :references (list '(:sbcl :node "Handling of Types"))))
985 (define-condition type-style-warning (reference-condition simple-style-warning)
987 (:default-initargs :references (list '(:sbcl :node "Handling of Types"))))
989 (define-condition local-argument-mismatch (reference-condition simple-warning)
991 (:default-initargs :references (list '(:ansi-cl :section (3 2 2 3)))))
993 (define-condition format-args-mismatch (reference-condition)
995 (:default-initargs :references (list '(:ansi-cl :section (22 3 10 2)))))
997 (define-condition format-too-few-args-warning
998 (format-args-mismatch simple-warning)
1000 (define-condition format-too-many-args-warning
1001 (format-args-mismatch simple-style-warning)
1004 (define-condition implicit-generic-function-warning (style-warning)
1005 ((name :initarg :name :reader implicit-generic-function-name))
1007 (lambda (condition stream)
1008 (let ((*package* (find-package :keyword)))
1009 (format stream "~@<Implicitly creating new generic function ~S.~:@>"
1010 (implicit-generic-function-name condition))))))
1012 (define-condition extension-failure (reference-condition simple-error)
1015 (define-condition structure-initarg-not-keyword
1016 (reference-condition simple-style-warning)
1018 (:default-initargs :references (list '(:ansi-cl :section (2 4 8 13)))))
1023 (define-condition package-lock-violation (package-error
1026 ((current-package :initform *package*
1027 :reader package-lock-violation-in-package))
1029 (lambda (condition stream)
1030 (let ((control (simple-condition-format-control condition))
1031 (error-package (package-name (package-error-package condition)))
1032 (current-package (package-name (package-lock-violation-in-package condition))))
1034 (apply #'format stream
1035 (format nil "~~@<Lock on package ~A violated when ~A while in package ~A.~~:@>"
1039 (simple-condition-format-arguments condition))
1040 (format stream "~@<Lock on package ~A violated while in package ~A.~:@>"
1042 current-package)))))
1043 ;; no :default-initargs -- reference-stuff provided by the
1044 ;; signalling form in target-package.lisp
1047 "Subtype of CL:PACKAGE-ERROR. A subtype of this error is signalled
1048 when a package-lock is violated."))
1050 (define-condition package-locked-error (package-lock-violation) ()
1053 "Subtype of SB-EXT:PACKAGE-LOCK-VIOLATION. An error of this type is
1054 signalled when an operation on a package violates a package lock."))
1056 (define-condition symbol-package-locked-error (package-lock-violation)
1057 ((symbol :initarg :symbol :reader package-locked-error-symbol))
1060 "Subtype of SB-EXT:PACKAGE-LOCK-VIOLATION. An error of this type is
1061 signalled when an operation on a symbol violates a package lock. The
1062 symbol that caused the violation is accessed by the function
1063 SB-EXT:PACKAGE-LOCKED-ERROR-SYMBOL."))
1067 (define-condition undefined-alien-error (cell-error) ()
1069 (lambda (condition stream)
1070 (if (slot-boundp condition 'name)
1071 (format stream "Undefined alien: ~S" (cell-error-name condition))
1072 (format stream "Undefined alien symbol.")))))
1074 (define-condition undefined-alien-variable-error (undefined-alien-error) ()
1076 (lambda (condition stream)
1077 (declare (ignore condition))
1078 (format stream "Attempt to access an undefined alien variable."))))
1080 (define-condition undefined-alien-function-error (undefined-alien-error) ()
1082 (lambda (condition stream)
1083 (declare (ignore condition))
1084 (format stream "Attempt to call an undefined alien function."))))
1087 ;;;; various other (not specified by ANSI) CONDITIONs
1089 ;;;; These might logically belong in other files; they're here, after
1090 ;;;; setup of CONDITION machinery, only because that makes it easier to
1091 ;;;; get cold init to work.
1093 ;;; OAOOM warning: see cross-condition.lisp
1094 (define-condition encapsulated-condition (condition)
1095 ((condition :initarg :condition :reader encapsulated-condition)))
1097 ;;; KLUDGE: a condition for floating point errors when we can't or
1098 ;;; won't figure out what type they are. (In FreeBSD and OpenBSD we
1099 ;;; don't know how, at least as of sbcl-0.6.7; in Linux we probably
1100 ;;; know how but the old code was broken by the conversion to POSIX
1101 ;;; signal handling and hasn't been fixed as of sbcl-0.6.7.)
1103 ;;; FIXME: Perhaps this should also be a base class for all
1104 ;;; floating point exceptions?
1105 (define-condition floating-point-exception (arithmetic-error)
1106 ((flags :initarg :traps
1108 :reader floating-point-exception-traps))
1109 (:report (lambda (condition stream)
1111 "An arithmetic error ~S was signalled.~%"
1112 (type-of condition))
1113 (let ((traps (floating-point-exception-traps condition)))
1116 "Trapping conditions are: ~%~{ ~S~^~}~%"
1119 "No traps are enabled? How can this be?"
1122 (define-condition invalid-array-index-error (type-error)
1123 ((array :initarg :array :reader invalid-array-index-error-array)
1124 (axis :initarg :axis :reader invalid-array-index-error-axis))
1126 (lambda (condition stream)
1127 (let ((array (invalid-array-index-error-array condition)))
1128 (format stream "Index ~W out of bounds for ~@[axis ~W of ~]~S, ~
1129 should be nonnegative and <~W."
1130 (type-error-datum condition)
1131 (when (> (array-rank array) 1)
1132 (invalid-array-index-error-axis condition))
1134 ;; Extract the bound from (INTEGER 0 (BOUND))
1135 (caaddr (type-error-expected-type condition)))))))
1137 (define-condition invalid-array-error (reference-condition type-error) ()
1139 (lambda (condition stream)
1140 (let ((*print-array* nil))
1142 "~@<Displaced array originally of type ~S has been invalidated ~
1143 due its displaced-to array ~S having become too small to hold ~
1144 it: the displaced array's dimensions have all been set to zero ~
1145 to trap accesses to it.~:@>"
1146 (type-error-expected-type condition)
1147 (array-displacement (type-error-datum condition))))))
1150 (list '(:ansi-cl :function adjust-array))))
1152 (define-condition index-too-large-error (type-error)
1155 (lambda (condition stream)
1157 "The index ~S is too large."
1158 (type-error-datum condition)))))
1160 (define-condition bounding-indices-bad-error (reference-condition type-error)
1161 ((object :reader bounding-indices-bad-object :initarg :object))
1163 (lambda (condition stream)
1164 (let* ((datum (type-error-datum condition))
1167 (object (bounding-indices-bad-object condition)))
1171 "The bounding indices ~S and ~S are bad ~
1172 for a sequence of length ~S."
1173 start end (length object)))
1175 ;; from WITH-ARRAY-DATA
1177 "The START and END parameters ~S and ~S are ~
1178 bad for an array of total size ~S."
1179 start end (array-total-size object)))))))
1182 (list '(:ansi-cl :glossary "bounding index designator")
1183 '(:ansi-cl :issue "SUBSEQ-OUT-OF-BOUNDS:IS-AN-ERROR"))))
1185 (define-condition nil-array-accessed-error (reference-condition type-error)
1187 (:report (lambda (condition stream)
1188 (declare (ignore condition))
1190 "An attempt to access an array of element-type ~
1191 NIL was made. Congratulations!")))
1193 :references (list '(:ansi-cl :function sb!xc:upgraded-array-element-type)
1194 '(:ansi-cl :section (15 1 2 1))
1195 '(:ansi-cl :section (15 1 2 2)))))
1197 (define-condition namestring-parse-error (parse-error)
1198 ((complaint :reader namestring-parse-error-complaint :initarg :complaint)
1199 (args :reader namestring-parse-error-args :initarg :args :initform nil)
1200 (namestring :reader namestring-parse-error-namestring :initarg :namestring)
1201 (offset :reader namestring-parse-error-offset :initarg :offset))
1203 (lambda (condition stream)
1205 "parse error in namestring: ~?~% ~A~% ~V@T^"
1206 (namestring-parse-error-complaint condition)
1207 (namestring-parse-error-args condition)
1208 (namestring-parse-error-namestring condition)
1209 (namestring-parse-error-offset condition)))))
1211 (define-condition simple-package-error (simple-condition package-error) ())
1213 (define-condition simple-reader-package-error (simple-reader-error package-error) ())
1215 (define-condition reader-eof-error (end-of-file)
1216 ((context :reader reader-eof-error-context :initarg :context))
1218 (lambda (condition stream)
1220 "unexpected end of file on ~S ~A"
1221 (stream-error-stream condition)
1222 (reader-eof-error-context condition)))))
1224 (define-condition reader-impossible-number-error (simple-reader-error)
1225 ((error :reader reader-impossible-number-error-error :initarg :error))
1227 (lambda (condition stream)
1228 (let ((error-stream (stream-error-stream condition)))
1230 "READER-ERROR ~@[at ~W ~]on ~S:~%~?~%Original error: ~A"
1231 (file-position-or-nil-for-error error-stream) error-stream
1232 (simple-condition-format-control condition)
1233 (simple-condition-format-arguments condition)
1234 (reader-impossible-number-error-error condition))))))
1236 (define-condition standard-readtable-modified-error (reference-condition error)
1237 ((operation :initarg :operation :reader standard-readtable-modified-operation))
1238 (:report (lambda (condition stream)
1239 (format stream "~S would modify the standard readtable."
1240 (standard-readtable-modified-operation condition))))
1241 (:default-initargs :references `((:ansi-cl :section (2 1 1 2))
1242 (:ansi-cl :glossary "standard readtable"))))
1244 (define-condition standard-pprint-dispatch-table-modified-error
1245 (reference-condition error)
1246 ((operation :initarg :operation
1247 :reader standard-pprint-dispatch-table-modified-operation))
1248 (:report (lambda (condition stream)
1249 (format stream "~S would modify the standard pprint dispatch table."
1250 (standard-pprint-dispatch-table-modified-operation
1253 :references `((:ansi-cl :glossary "standard pprint dispatch table"))))
1255 (define-condition timeout (serious-condition)
1256 ((seconds :initarg :seconds :initform nil :reader timeout-seconds))
1257 (:report (lambda (condition stream)
1258 (format stream "Timeout occurred~@[ after ~A seconds~]."
1259 (timeout-seconds condition)))))
1261 (define-condition io-timeout (stream-error timeout)
1262 ((direction :reader io-timeout-direction :initarg :direction))
1264 (lambda (condition stream)
1265 (declare (type stream stream))
1267 "I/O timeout while doing ~(~A~) on ~S."
1268 (io-timeout-direction condition)
1269 (stream-error-stream condition)))))
1271 (define-condition deadline-timeout (timeout) ()
1272 (:report (lambda (condition stream)
1273 (format stream "A deadline was reached after ~A seconds."
1274 (timeout-seconds condition)))))
1276 (define-condition declaration-type-conflict-error (reference-condition
1280 :format-control "symbol ~S cannot be both the name of a type and the name of a declaration"
1281 :references (list '(:ansi-cl :section (3 8 21)))))
1283 ;;; Single stepping conditions
1285 (define-condition step-condition ()
1286 ((form :initarg :form :reader step-condition-form))
1289 (:documentation "Common base class of single-stepping conditions.
1290 STEP-CONDITION-FORM holds a string representation of the form being
1294 (setf (fdocumentation 'step-condition-form 'function)
1295 "Form associated with the STEP-CONDITION.")
1297 (define-condition step-form-condition (step-condition)
1298 ((args :initarg :args :reader step-condition-args))
1300 (lambda (condition stream)
1301 (let ((*print-circle* t)
1303 (*print-readably* nil))
1305 "Evaluating call:~%~< ~@;~A~:>~%~
1306 ~:[With arguments:~%~{ ~S~%~}~;With unknown arguments~]~%"
1307 (list (step-condition-form condition))
1308 (eq (step-condition-args condition) :unknown)
1309 (step-condition-args condition)))))
1311 (:documentation "Condition signalled by code compiled with
1312 single-stepping information when about to execute a form.
1313 STEP-CONDITION-FORM holds the form, STEP-CONDITION-PATHNAME holds the
1314 pathname of the original file or NIL, and STEP-CONDITION-SOURCE-PATH
1315 holds the source-path to the original form within that file or NIL.
1316 Associated with this condition are always the restarts STEP-INTO,
1317 STEP-NEXT, and STEP-CONTINUE."))
1319 (define-condition step-result-condition (step-condition)
1320 ((result :initarg :result :reader step-condition-result)))
1323 (setf (fdocumentation 'step-condition-result 'function)
1324 "Return values associated with STEP-VALUES-CONDITION as a list,
1325 or the variable value associated with STEP-VARIABLE-CONDITION.")
1327 (define-condition step-values-condition (step-result-condition)
1330 (:documentation "Condition signalled by code compiled with
1331 single-stepping information after executing a form.
1332 STEP-CONDITION-FORM holds the form, and STEP-CONDITION-RESULT holds
1333 the values returned by the form as a list. No associated restarts."))
1335 (define-condition step-finished-condition (step-condition)
1338 (lambda (condition stream)
1339 (declare (ignore condition))
1340 (format stream "Returning from STEP")))
1342 (:documentation "Condition signaled when STEP returns."))
1344 ;;; A knob for muffling warnings, mostly for use while loading files.
1345 (defvar *muffled-warnings* 'uninteresting-redefinition
1346 "A type that ought to specify a subtype of WARNING. Whenever a
1347 warning is signaled, if the warning if of this type and is not
1348 handled by any other handler, it will be muffled.")
1350 ;;; Various STYLE-WARNING signaled in the system.
1351 ;; For the moment, we're only getting into the details for function
1352 ;; redefinitions, but other redefinitions could be done later
1354 (define-condition redefinition-warning (style-warning)
1357 :reader redefinition-warning-name)
1359 :initarg :new-location
1360 :reader redefinition-warning-new-location)))
1362 (define-condition function-redefinition-warning (redefinition-warning)
1364 :initarg :new-function
1365 :reader function-redefinition-warning-new-function)))
1367 (define-condition redefinition-with-defun (function-redefinition-warning)
1369 (:report (lambda (warning stream)
1370 (format stream "redefining ~/sb-impl::print-symbol-with-prefix/ ~
1372 (redefinition-warning-name warning)))))
1374 (define-condition redefinition-with-defmacro (function-redefinition-warning)
1376 (:report (lambda (warning stream)
1377 (format stream "redefining ~/sb-impl::print-symbol-with-prefix/ ~
1379 (redefinition-warning-name warning)))))
1381 (define-condition redefinition-with-defgeneric (redefinition-warning)
1383 (:report (lambda (warning stream)
1384 (format stream "redefining ~/sb-impl::print-symbol-with-prefix/ ~
1386 (redefinition-warning-name warning)))))
1388 (define-condition redefinition-with-defmethod (redefinition-warning)
1389 ((qualifiers :initarg :qualifiers
1390 :reader redefinition-with-defmethod-qualifiers)
1391 (specializers :initarg :specializers
1392 :reader redefinition-with-defmethod-specializers)
1393 (new-location :initarg :new-location
1394 :reader redefinition-with-defmethod-new-location)
1395 (old-method :initarg :old-method
1396 :reader redefinition-with-defmethod-old-method))
1397 (:report (lambda (warning stream)
1398 (format stream "redefining ~S~{ ~S~} ~S in DEFMETHOD"
1399 (redefinition-warning-name warning)
1400 (redefinition-with-defmethod-qualifiers warning)
1401 (redefinition-with-defmethod-specializers warning)))))
1403 ;;;; Deciding which redefinitions are "interesting".
1405 (defun function-file-namestring (function)
1407 (when (typep function 'sb!eval:interpreted-function)
1408 (return-from function-file-namestring
1409 (sb!c:definition-source-location-namestring
1410 (sb!eval:interpreted-function-source-location function))))
1411 (let* ((fun (sb!kernel:%fun-fun function))
1412 (code (sb!kernel:fun-code-header fun))
1413 (debug-info (sb!kernel:%code-debug-info code))
1414 (debug-source (when debug-info
1415 (sb!c::debug-info-source debug-info)))
1416 (namestring (when debug-source
1417 (sb!c::debug-source-namestring debug-source))))
1420 (defun interesting-function-redefinition-warning-p (warning old)
1421 (let ((new (function-redefinition-warning-new-function warning))
1422 (source-location (redefinition-warning-new-location warning)))
1424 ;; Compiled->Interpreted is interesting.
1425 (and (typep old 'compiled-function)
1426 (typep new '(not compiled-function)))
1427 ;; FIN->Regular is interesting.
1428 (and (typep old 'funcallable-instance)
1429 (typep new '(not funcallable-instance)))
1430 ;; Different file or unknown location is interesting.
1431 (let* ((old-namestring (function-file-namestring old))
1433 (or (function-file-namestring new)
1434 (when source-location
1435 (sb!c::definition-source-location-namestring source-location)))))
1436 (and (or (not old-namestring)
1437 (not new-namestring)
1438 (not (string= old-namestring new-namestring))))))))
1440 (defun uninteresting-ordinary-function-redefinition-p (warning)
1442 ;; There's garbage in various places when the first DEFUN runs in
1444 sb!kernel::*cold-init-complete-p*
1445 (typep warning 'redefinition-with-defun)
1447 (let ((name (redefinition-warning-name warning)))
1448 (not (interesting-function-redefinition-warning-p
1449 warning (or (fdefinition name) (macro-function name)))))))
1451 (defun uninteresting-macro-redefinition-p (warning)
1453 (typep warning 'redefinition-with-defmacro)
1455 (let ((name (redefinition-warning-name warning)))
1456 (not (interesting-function-redefinition-warning-p
1457 warning (or (macro-function name) (fdefinition name)))))))
1459 (defun uninteresting-generic-function-redefinition-p (warning)
1461 (typep warning 'redefinition-with-defgeneric)
1462 ;; Can't use the shared logic above, since GF's don't get a "new"
1463 ;; definition -- rather the FIN-FUNCTION is set.
1464 (let* ((name (redefinition-warning-name warning))
1465 (old (fdefinition name))
1466 (old-location (when (typep old 'generic-function)
1467 (sb!pcl::definition-source old)))
1468 (old-namestring (when old-location
1469 (sb!c:definition-source-location-namestring old-location)))
1470 (new-location (redefinition-warning-new-location warning))
1471 (new-namestring (when new-location
1472 (sb!c:definition-source-location-namestring new-location))))
1475 (string= old-namestring new-namestring)))))
1477 (defun uninteresting-method-redefinition-p (warning)
1479 (typep warning 'redefinition-with-defmethod)
1480 ;; Can't use the shared logic above, since GF's don't get a "new"
1481 ;; definition -- rather the FIN-FUNCTION is set.
1482 (let* ((old-method (redefinition-with-defmethod-old-method warning))
1483 (old-location (sb!pcl::definition-source old-method))
1484 (old-namestring (when old-location
1485 (sb!c:definition-source-location-namestring old-location)))
1486 (new-location (redefinition-warning-new-location warning))
1487 (new-namestring (when new-location
1488 (sb!c:definition-source-location-namestring new-location))))
1491 (string= new-namestring old-namestring)))))
1493 (deftype uninteresting-redefinition ()
1494 '(or (satisfies uninteresting-ordinary-function-redefinition-p)
1495 (satisfies uninteresting-macro-redefinition-p)
1496 (satisfies uninteresting-generic-function-redefinition-p)
1497 (satisfies uninteresting-method-redefinition-p)))
1499 (define-condition redefinition-with-deftransform (redefinition-warning)
1500 ((transform :initarg :transform
1501 :reader redefinition-with-deftransform-transform))
1502 (:report (lambda (warning stream)
1503 (format stream "Overwriting ~S"
1504 (redefinition-with-deftransform-transform warning)))))
1506 ;;; Various other STYLE-WARNINGS
1507 (define-condition dubious-asterisks-around-variable-name
1508 (style-warning simple-condition)
1510 (:report (lambda (warning stream)
1511 (format stream "~@?, even though the name follows~@
1512 the usual naming convention (names like *FOO*) for special variables"
1513 (simple-condition-format-control warning)
1514 (simple-condition-format-arguments warning)))))
1516 (define-condition asterisks-around-lexical-variable-name
1517 (dubious-asterisks-around-variable-name)
1520 (define-condition asterisks-around-constant-variable-name
1521 (dubious-asterisks-around-variable-name)
1524 ;; We call this UNDEFINED-ALIEN-STYLE-WARNING because there are some
1525 ;; subclasses of ERROR above having to do with undefined aliens.
1526 (define-condition undefined-alien-style-warning (style-warning)
1527 ((symbol :initarg :symbol :reader undefined-alien-symbol))
1528 (:report (lambda (warning stream)
1529 (format stream "Undefined alien: ~S"
1530 (undefined-alien-symbol warning)))))
1533 (define-condition lexical-environment-too-complex (style-warning)
1534 ((form :initarg :form :reader lexical-environment-too-complex-form)
1535 (lexenv :initarg :lexenv :reader lexical-environment-too-complex-lexenv))
1536 (:report (lambda (warning stream)
1538 "~@<Native lexical environment too complex for ~
1539 SB-EVAL to evaluate ~S, falling back to ~
1540 SIMPLE-EVAL-IN-LEXENV. Lexenv: ~S~:@>"
1541 (lexical-environment-too-complex-form warning)
1542 (lexical-environment-too-complex-lexenv warning)))))
1544 ;; Although this has -ERROR- in the name, it's just a STYLE-WARNING.
1545 (define-condition character-decoding-error-in-comment (style-warning)
1546 ((stream :initarg :stream :reader decoding-error-in-comment-stream)
1547 (position :initarg :position :reader decoding-error-in-comment-position))
1548 (:report (lambda (warning stream)
1550 "Character decoding error in a ~A-comment at ~
1551 position ~A reading source stream ~A, ~
1553 (decoding-error-in-comment-macro warning)
1554 (decoding-error-in-comment-position warning)
1555 (decoding-error-in-comment-stream warning)))))
1557 (define-condition character-decoding-error-in-macro-char-comment
1558 (character-decoding-error-in-comment)
1559 ((char :initform #\; :initarg :char
1560 :reader character-decoding-error-in-macro-char-comment-char)))
1562 (define-condition character-decoding-error-in-dispatch-macro-char-comment
1563 (character-decoding-error-in-comment)
1564 ;; ANSI doesn't give a way for a reader function invoked by a
1565 ;; dispatch macro character to determine which dispatch character
1566 ;; was used, so if a user wants to signal one of these from a custom
1567 ;; comment reader, he'll have to supply the :DISP-CHAR himself.
1568 ((disp-char :initform #\# :initarg :disp-char
1569 :reader character-decoding-error-in-macro-char-comment-disp-char)
1570 (sub-char :initarg :sub-char
1571 :reader character-decoding-error-in-macro-char-comment-sub-char)))
1573 (defun decoding-error-in-comment-macro (warning)
1575 (character-decoding-error-in-macro-char-comment
1576 (character-decoding-error-in-macro-char-comment-char warning))
1577 (character-decoding-error-in-dispatch-macro-char-comment
1580 (character-decoding-error-in-macro-char-comment-disp-char warning)
1581 (character-decoding-error-in-macro-char-comment-sub-char warning)))))
1583 (define-condition deprecated-eval-when-situations (style-warning)
1584 ((situations :initarg :situations
1585 :reader deprecated-eval-when-situations-situations))
1586 (:report (lambda (warning stream)
1587 (format stream "using deprecated EVAL-WHEN situation names~{ ~S~}"
1588 (deprecated-eval-when-situations-situations warning)))))
1590 (define-condition proclamation-mismatch (style-warning)
1591 ((name :initarg :name :reader proclamation-mismatch-name)
1592 (old :initarg :old :reader proclamation-mismatch-old)
1593 (new :initarg :new :reader proclamation-mismatch-new)))
1595 (define-condition type-proclamation-mismatch (proclamation-mismatch)
1597 (:report (lambda (warning stream)
1599 "The new TYPE proclamation~% ~S for ~S does not ~
1600 match the old TYPE proclamation ~S"
1601 (proclamation-mismatch-new warning)
1602 (proclamation-mismatch-name warning)
1603 (proclamation-mismatch-old warning)))))
1605 (define-condition ftype-proclamation-mismatch (proclamation-mismatch)
1607 (:report (lambda (warning stream)
1609 "The new FTYPE proclamation~% ~S for ~S does not ~
1610 match the old FTYPE proclamation ~S"
1611 (proclamation-mismatch-new warning)
1612 (proclamation-mismatch-name warning)
1613 (proclamation-mismatch-old warning)))))
1615 ;;;; deprecation conditions
1617 (define-condition deprecation-condition ()
1618 ((name :initarg :name :reader deprecated-name)
1619 (replacements :initarg :replacements :reader deprecated-name-replacements)
1620 (since :initarg :since :reader deprecated-since)
1621 (runtime-error :initarg :runtime-error :reader deprecated-name-runtime-error)))
1623 (def!method print-object ((condition deprecation-condition) stream)
1624 (let ((*package* (find-package :keyword)))
1626 (print-unreadable-object (condition stream :type t)
1628 stream "~S is deprecated.~
1629 ~#[~; Use ~S instead.~; ~
1630 Use ~S or ~S instead.~:; ~
1631 Use~@{~#[~; or~] ~S~^,~} instead.~]"
1632 (deprecated-name condition)
1633 (deprecated-name-replacements condition)))
1635 stream "~@<~S has been deprecated as of SBCL ~A.~
1636 ~#[~; Use ~S instead.~; ~
1637 Use ~S or ~S instead.~:; ~
1638 Use~@{~#[~; or~] ~S~^,~:_~} instead.~]~:@>"
1639 (deprecated-name condition)
1640 (deprecated-since condition)
1641 (deprecated-name-replacements condition)))))
1643 (define-condition early-deprecation-warning (style-warning deprecation-condition)
1646 (def!method print-object :after ((warning early-deprecation-warning) stream)
1647 (unless *print-escape*
1648 (let ((*package* (find-package :keyword)))
1649 (format stream "~%~@<~:@_In future SBCL versions ~S will signal a full warning ~
1650 at compile-time.~:@>"
1651 (deprecated-name warning)))))
1653 (define-condition late-deprecation-warning (warning deprecation-condition)
1656 (def!method print-object :after ((warning late-deprecation-warning) stream)
1657 (unless *print-escape*
1658 (when (deprecated-name-runtime-error warning)
1659 (let ((*package* (find-package :keyword)))
1660 (format stream "~%~@<~:@_In future SBCL versions ~S will signal a runtime error.~:@>"
1661 (deprecated-name warning))))))
1663 (define-condition final-deprecation-warning (warning deprecation-condition)
1666 (def!method print-object :after ((warning final-deprecation-warning) stream)
1667 (unless *print-escape*
1668 (when (deprecated-name-runtime-error warning)
1669 (let ((*package* (find-package :keyword)))
1670 (format stream "~%~@<~:@_An error will be signaled at runtime for ~S.~:@>"
1671 (deprecated-name warning))))))
1673 (define-condition deprecation-error (error deprecation-condition)
1676 ;;;; restart definitions
1678 (define-condition abort-failure (control-error) ()
1680 "An ABORT restart was found that failed to transfer control dynamically."))
1682 (defun abort (&optional condition)
1684 "Transfer control to a restart named ABORT, signalling a CONTROL-ERROR if
1686 (invoke-restart (find-restart-or-control-error 'abort condition))
1687 ;; ABORT signals an error in case there was a restart named ABORT
1688 ;; that did not transfer control dynamically. This could happen with
1690 (error 'abort-failure))
1692 (defun muffle-warning (&optional condition)
1694 "Transfer control to a restart named MUFFLE-WARNING, signalling a
1695 CONTROL-ERROR if none exists."
1696 (invoke-restart (find-restart-or-control-error 'muffle-warning condition)))
1698 (defun try-restart (name condition &rest arguments)
1699 (let ((restart (find-restart name condition)))
1701 (apply #'invoke-restart restart arguments))))
1703 (macrolet ((define-nil-returning-restart (name args doc)
1704 #!-sb-doc (declare (ignore doc))
1705 `(defun ,name (,@args &optional condition)
1707 (try-restart ',name condition ,@args))))
1708 (define-nil-returning-restart continue ()
1709 "Transfer control to a restart named CONTINUE, or return NIL if none exists.")
1710 (define-nil-returning-restart store-value (value)
1711 "Transfer control and VALUE to a restart named STORE-VALUE, or
1712 return NIL if none exists.")
1713 (define-nil-returning-restart use-value (value)
1714 "Transfer control and VALUE to a restart named USE-VALUE, or
1715 return NIL if none exists.")
1716 (define-nil-returning-restart print-unreadably ()
1717 "Transfer control to a restart named SB-EXT:PRINT-UNREADABLY, or
1718 return NIL if none exists."))
1720 ;;; single-stepping restarts
1722 (macrolet ((def (name doc)
1723 #!-sb-doc (declare (ignore doc))
1724 `(defun ,name (condition)
1726 (invoke-restart (find-restart-or-control-error ',name condition)))))
1728 "Transfers control to the STEP-CONTINUE restart associated with
1729 the condition, continuing execution without stepping. Signals a
1730 CONTROL-ERROR if the restart does not exist.")
1732 "Transfers control to the STEP-NEXT restart associated with the
1733 condition, executing the current form without stepping and continuing
1734 stepping with the next form. Signals CONTROL-ERROR is the restart does
1737 "Transfers control to the STEP-INTO restart associated with the
1738 condition, stepping into the current form. Signals a CONTROL-ERROR is
1739 the restart does not exist."))
1741 ;;; Compiler macro magic
1743 (define-condition compiler-macro-keyword-problem ()
1744 ((argument :initarg :argument :reader compiler-macro-keyword-argument))
1745 (:report (lambda (condition stream)
1746 (format stream "~@<Argument ~S in keyword position is not ~
1747 a self-evaluating symbol, preventing compiler-macro ~
1749 (compiler-macro-keyword-argument condition)))))
1751 (/show0 "condition.lisp end of file")