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 (defstruct (condition-slot (:copier nil
))
21 (name (missing-arg) :type symbol
)
22 ;; list of all applicable initargs
23 (initargs (missing-arg) :type list
)
24 ;; names of reader and writer functions
25 (readers (missing-arg) :type list
)
26 (writers (missing-arg) :type list
)
27 ;; true if :INITFORM was specified
28 (initform-p (missing-arg) :type
(member t nil
))
29 ;; the initform if :INITFORM was specified, otherwise NIL
30 (initform nil
:type t
)
31 ;; if this is a function, call it with no args to get the initform value
32 (initfunction (missing-arg) :type t
)
33 ;; allocation of this slot, or NIL until defaulted
34 (allocation nil
:type
(member :instance
:class nil
))
35 ;; If ALLOCATION is :CLASS, this is a cons whose car holds the value
36 (cell nil
:type
(or cons null
))
38 (documentation nil
:type
(or string null
)))
40 ;;; KLUDGE: It's not clear to me why CONDITION-CLASS has itself listed
41 ;;; in its CPL, while other classes derived from CONDITION-CLASS don't
42 ;;; have themselves listed in their CPLs. This behavior is inherited
43 ;;; from CMU CL, and didn't seem to be explained there, and I haven't
44 ;;; figured out whether it's right. -- WHN 19990612
45 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
46 (/show0
"condition.lisp 103")
47 (let ((condition-class (find-classoid 'condition
)))
48 (setf (condition-classoid-cpl condition-class
)
49 (list condition-class
)))
50 (/show0
"condition.lisp 103"))
52 (setf (condition-classoid-report (find-classoid 'condition
))
54 (format stream
"Condition ~S was signalled." (type-of cond
))))
56 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
58 (defun find-condition-layout (name parent-types
)
59 (let* ((cpl (remove-duplicates
63 (condition-classoid-cpl
66 (cond-layout (info :type
:compiler-layout
'condition
))
67 (olayout (info :type
:compiler-layout name
))
68 ;; FIXME: Does this do the right thing in case of multiple
69 ;; inheritance? A quick look at DEFINE-CONDITION didn't make
70 ;; it obvious what ANSI intends to be done in the case of
71 ;; multiple inheritance, so it's not actually clear what the
74 (order-layout-inherits (concatenate 'simple-vector
75 (layout-inherits cond-layout
)
76 (mapcar #'classoid-layout cpl
)))))
78 (not (mismatch (layout-inherits olayout
) new-inherits
)))
80 (make-layout :classoid
(make-undefined-classoid name
)
81 :inherits new-inherits
83 :length
(layout-length cond-layout
)))))
87 ;;; FIXME: ANSI's definition of DEFINE-CONDITION says
88 ;;; Condition reporting is mediated through the PRINT-OBJECT method
89 ;;; for the condition type in question, with *PRINT-ESCAPE* always
90 ;;; being nil. Specifying (:REPORT REPORT-NAME) in the definition of
91 ;;; a condition type C is equivalent to:
92 ;;; (defmethod print-object ((x c) stream)
93 ;;; (if *print-escape* (call-next-method) (report-name x stream)))
94 ;;; The current code doesn't seem to quite match that.
95 (def*method print-object
((x condition
) stream
)
97 (if (and (typep x
'simple-condition
) (slot-value x
'format-control
))
98 (print-unreadable-object (x stream
:type t
:identity t
)
99 (write (simple-condition-format-control x
)
102 (print-unreadable-object (x stream
:type t
:identity t
)))
103 ;; KLUDGE: A comment from CMU CL here said
104 ;; 7/13/98 BUG? CPL is not sorted and results here depend on order of
105 ;; superclasses in define-condition call!
106 (dolist (class (condition-classoid-cpl (classoid-of x
))
107 (error "no REPORT? shouldn't happen!"))
108 (let ((report (condition-classoid-report class
)))
110 (return (funcall report x stream
)))))))
112 ;;; It is essential that there be a method that works in warm load
113 ;;; because any conditions signaled are not printable otherwise,
114 ;;; except by the method on type T which is completely unhelpful.
115 (defmethod print-object ((x condition
) stream
)
116 (print-unreadable-object (x stream
:type t
:identity t
)
117 (write (%instance-ref x
1) :stream stream
:escape t
)))
119 ;;;; slots of CONDITION objects
121 (defvar *empty-condition-slot
* '(empty))
123 (defun find-slot-default (class slot
)
124 (let ((initargs (condition-slot-initargs slot
))
125 (cpl (condition-classoid-cpl class
)))
126 ;; When CLASS or a superclass has a default initarg for SLOT, use
129 (let ((direct-default-initargs
130 (condition-classoid-direct-default-initargs class
)))
131 (dolist (initarg initargs
)
132 (let ((initfunction (third (assoc initarg direct-default-initargs
))))
134 (return-from find-slot-default
(funcall initfunction
)))))))
136 ;; Otherwise use the initform of SLOT, if there is one.
137 (if (condition-slot-initform-p slot
)
138 (let ((initfun (condition-slot-initfunction slot
)))
139 (aver (functionp initfun
))
141 (error "unbound condition slot: ~S" (condition-slot-name slot
)))))
143 (defun find-condition-class-slot (condition-class slot-name
)
145 (condition-classoid-cpl condition-class
)
146 (error "There is no slot named ~S in ~S."
147 slot-name condition-class
))
148 (dolist (slot (condition-classoid-slots sclass
))
149 (when (eq (condition-slot-name slot
) slot-name
)
150 (return-from find-condition-class-slot slot
)))))
152 (defun condition-writer-function (condition new-value name
)
153 (dolist (cslot (condition-classoid-class-slots
154 (layout-classoid (%instance-layout condition
)))
155 (setf (getf (condition-assigned-slots condition
) name
)
157 (when (eq (condition-slot-name cslot
) name
)
158 (return (setf (car (condition-slot-cell cslot
)) new-value
)))))
160 (defun condition-reader-function (condition name
)
161 (let ((class (layout-classoid (%instance-layout condition
))))
162 (dolist (cslot (condition-classoid-class-slots class
))
163 (when (eq (condition-slot-name cslot
) name
)
164 (return-from condition-reader-function
165 (car (condition-slot-cell cslot
)))))
166 (let ((val (getf (condition-assigned-slots condition
) name
167 *empty-condition-slot
*)))
168 (if (eq val
*empty-condition-slot
*)
169 (let ((actual-initargs (condition-actual-initargs condition
))
170 (slot (find-condition-class-slot class name
)))
172 (error "missing slot ~S of ~S" name condition
))
173 (do ((initargs actual-initargs
(cddr initargs
)))
175 (setf (getf (condition-assigned-slots condition
) name
)
176 (find-slot-default class slot
)))
177 (when (member (car initargs
) (condition-slot-initargs slot
))
178 (return-from condition-reader-function
179 (setf (getf (condition-assigned-slots condition
)
186 (defun allocate-condition (designator &rest initargs
)
187 ;; I am going to assume that people are not somehow getting to here
188 ;; with a CLASSOID, which is not strictly legal as a designator,
189 ;; but which is accepted because it is actually the desired thing.
190 ;; It doesn't seem worth sweating over that detail, and in any event
191 ;; we could say that it's a supported extension.
192 (let ((classoid (named-let lookup
((designator designator
))
194 (symbol (find-classoid designator nil
))
195 (class (lookup (class-name designator
)))
197 (if (condition-classoid-p classoid
)
198 (let ((instance (%make-condition-object initargs
'())))
199 (setf (%instance-layout instance
) (classoid-layout classoid
))
200 (values instance classoid
))
201 (error 'simple-type-error
203 ;; CONDITION-CLASS isn't a type-specifier. Is this legal?
204 :expected-type
'condition-class
205 :format-control
"~S does not designate a condition class."
206 :format-arguments
(list designator
)))))
208 (defun make-condition (type &rest initargs
)
210 "Make an instance of a condition object using the specified initargs."
211 ;; Note: While ANSI specifies no exceptional situations in this function,
212 ;; ALLOCATE-CONDITION will signal a type error if TYPE does not designate
213 ;; a condition class. This seems fair enough.
214 (declare (explicit-check))
215 (multiple-value-bind (condition classoid
)
216 (apply #'allocate-condition type initargs
)
218 ;; Set any class slots with initargs present in this call.
219 (dolist (cslot (condition-classoid-class-slots classoid
))
220 (dolist (initarg (condition-slot-initargs cslot
))
221 (let ((val (getf initargs initarg
*empty-condition-slot
*)))
222 (unless (eq val
*empty-condition-slot
*)
223 (setf (car (condition-slot-cell cslot
)) val
)))))
225 ;; Default any slots with non-constant defaults now.
226 (dolist (hslot (condition-classoid-hairy-slots classoid
))
227 (when (dolist (initarg (condition-slot-initargs hslot
) t
)
228 (unless (eq (getf initargs initarg
*empty-condition-slot
*)
229 *empty-condition-slot
*)
231 (setf (getf (condition-assigned-slots condition
)
232 (condition-slot-name hslot
))
233 (find-slot-default classoid hslot
))))
238 ;;;; DEFINE-CONDITION
240 ;;; Compute the effective slots of CLASS, copying inherited slots and
241 ;;; destructively modifying direct slots.
243 ;;; FIXME: It'd be nice to explain why it's OK to destructively modify
244 ;;; direct slots. Presumably it follows from the semantics of
245 ;;; inheritance and redefinition of conditions, but finding the cite
246 ;;; and documenting it here would be good. (Or, if this is not in fact
247 ;;; ANSI-compliant, fixing it would also be good.:-)
248 (defun compute-effective-slots (class)
249 (collect ((res (copy-list (condition-classoid-slots class
))))
250 (dolist (sclass (cdr (condition-classoid-cpl class
)))
251 (dolist (sslot (condition-classoid-slots sclass
))
252 (let ((found (find (condition-slot-name sslot
) (res)
253 :key
#'condition-slot-name
)))
255 (setf (condition-slot-initargs found
)
256 (union (condition-slot-initargs found
)
257 (condition-slot-initargs sslot
)))
258 (unless (condition-slot-initform-p found
)
259 (setf (condition-slot-initform-p found
)
260 (condition-slot-initform-p sslot
))
261 (setf (condition-slot-initform found
)
262 (condition-slot-initform sslot
))
263 (setf (condition-slot-initfunction found
)
264 (condition-slot-initfunction sslot
)))
265 (unless (condition-slot-allocation found
)
266 (setf (condition-slot-allocation found
)
267 (condition-slot-allocation sslot
))))
269 (res (copy-structure sslot
)))))))
272 ;;; Early definitions of slot accessor creators.
274 ;;; Slot accessors must be generic functions, but ANSI does not seem
275 ;;; to specify any of them, and we cannot support it before end of
276 ;;; warm init. So we use ordinary functions inside SBCL, and switch to
277 ;;; GFs only at the end of building.
278 (declaim (notinline install-condition-slot-reader
279 install-condition-slot-writer
))
280 (defun install-condition-slot-reader (name condition slot-name
)
281 (declare (ignore condition
))
282 (setf (fdefinition name
)
284 (condition-reader-function condition slot-name
))))
285 (defun install-condition-slot-writer (name condition slot-name
)
286 (declare (ignore condition
))
287 (setf (fdefinition name
)
288 (lambda (new-value condition
)
289 (condition-writer-function condition new-value slot-name
))))
291 (!defvar
*define-condition-hooks
* nil
)
293 (defun %set-condition-report
(name report
)
294 (setf (condition-classoid-report (find-classoid name
))
297 (defun %define-condition
(name parent-types layout slots
298 direct-default-initargs all-readers all-writers
299 source-location
&optional documentation
)
300 (with-single-package-locked-error
301 (:symbol name
"defining ~A as a condition")
302 (%compiler-define-condition name parent-types layout all-readers all-writers
)
303 (when source-location
304 (setf (layout-source-location layout
) source-location
))
305 (let ((class (find-classoid name
))) ; FIXME: rename to 'classoid'
306 (setf (condition-classoid-slots class
) slots
307 (condition-classoid-direct-default-initargs class
) direct-default-initargs
308 (fdocumentation name
'type
) documentation
)
312 ;; Set up reader and writer functions.
313 (let ((slot-name (condition-slot-name slot
)))
314 (dolist (reader (condition-slot-readers slot
))
315 (install-condition-slot-reader reader name slot-name
))
316 (dolist (writer (condition-slot-writers slot
))
317 (install-condition-slot-writer writer name slot-name
))))
319 ;; Compute effective slots and set up the class and hairy slots
320 ;; (subsets of the effective slots.)
321 (setf (condition-classoid-class-slots class
) '()
322 (condition-classoid-hairy-slots class
) '())
323 (let ((eslots (compute-effective-slots class
))
326 (mapcar #'condition-classoid-direct-default-initargs
327 (condition-classoid-cpl class
)))))
328 (dolist (slot eslots
)
329 (ecase (condition-slot-allocation slot
)
331 (unless (condition-slot-cell slot
)
332 (setf (condition-slot-cell slot
)
333 (list (if (condition-slot-initform-p slot
)
334 (let ((initfun (condition-slot-initfunction slot
)))
335 (aver (functionp initfun
))
337 *empty-condition-slot
*))))
338 (push slot
(condition-classoid-class-slots class
)))
340 (setf (condition-slot-allocation slot
) :instance
)
341 ;; FIXME: isn't this "always hairy"?
342 (when (or (functionp (condition-slot-initfunction slot
))
343 (dolist (initarg (condition-slot-initargs slot
) nil
)
344 (when (functionp (third (assoc initarg e-def-initargs
)))
346 (push slot
(condition-classoid-hairy-slots class
)))))))
347 (dolist (fun *define-condition-hooks
*)
348 (funcall fun class
)))
351 (defmacro define-condition
(name (&rest parent-types
) (&rest slot-specs
)
354 "DEFINE-CONDITION Name (Parent-Type*) (Slot-Spec*) Option*
355 Define NAME as a condition type. This new type inherits slots and its
356 report function from the specified PARENT-TYPEs. A slot spec is a list of:
357 (slot-name :reader <rname> :initarg <iname> {Option Value}*
359 The DEFINE-CLASS slot options :ALLOCATION, :INITFORM, [slot] :DOCUMENTATION
360 and :TYPE and the overall options :DEFAULT-INITARGS and
361 [type] :DOCUMENTATION are also allowed.
363 The :REPORT option is peculiar to DEFINE-CONDITION. Its argument is either
364 a string or a two-argument lambda or function name. If a function, the
365 function is called with the condition and stream to report the condition.
366 If a string, the string is printed.
368 Condition types are classes, but (as allowed by ANSI and not as described in
369 CLtL2) are neither STANDARD-OBJECTs nor STRUCTURE-OBJECTs. WITH-SLOTS and
370 SLOT-VALUE may not be used on condition objects."
371 (let* ((parent-types (or parent-types
'(condition)))
372 (layout (find-condition-layout name parent-types
))
375 (direct-default-initargs ()))
377 (all-readers nil append
)
378 (all-writers nil append
))
379 (dolist (spec slot-specs
)
380 (when (keywordp spec
)
381 (warn "Keyword slot name indicates probable syntax error:~% ~S"
383 (let* ((spec (if (consp spec
) spec
(list spec
)))
384 (slot-name (first spec
))
385 (allocation :instance
)
392 (do ((options (rest spec
) (cddr options
)))
394 (unless (and (consp options
) (consp (cdr options
)))
395 (error "malformed condition slot spec:~% ~S." spec
))
396 (let ((arg (second options
)))
397 (case (first options
)
398 (:reader
(readers arg
))
399 (:writer
(writers arg
))
402 (writers `(setf ,arg
)))
405 (error "more than one :INITFORM in ~S" spec
))
408 (:initarg
(initargs arg
))
410 (setq allocation arg
))
413 (error "more than one :DOCUMENTATION in ~S" spec
))
414 (unless (stringp arg
)
415 (error "slot :DOCUMENTATION argument is not a string: ~S"
417 (setq documentation arg
))
420 (error "unknown slot option:~% ~S" (first options
))))))
422 (all-readers (readers))
423 (all-writers (writers))
424 (slots `(make-condition-slot
426 :initargs
',(initargs)
429 :initform-p
',initform-p
430 :documentation
',documentation
431 :initform
,(when initform-p
`',initform
)
432 :initfunction
,(when initform-p
433 `#'(lambda () ,initform
))
434 :allocation
',allocation
)))))
436 (dolist (option options
)
437 (unless (consp option
)
438 (error "bad option:~% ~S" option
))
440 (:documentation
(setq documentation
(second option
)))
442 (let ((arg (second option
)))
444 `#'(named-lambda (condition-report ,name
) (condition stream
)
446 `((declare (ignore condition
))
447 (write-string ,arg stream
))
448 `((funcall #',arg condition stream
)))))))
450 (doplist (initarg initform
) (rest option
)
451 (push ``(,',initarg
,',initform
,#'(lambda () ,initform
))
452 direct-default-initargs
)))
454 (error "unknown option: ~S" (first option
)))))
457 (eval-when (:compile-toplevel
)
458 (%compiler-define-condition
',name
',parent-types
',layout
459 ',(all-readers) ',(all-writers)))
460 (%define-condition
',name
464 (list ,@direct-default-initargs
)
467 (sb!c
:source-location
)
470 ;; This needs to be after %DEFINE-CONDITION in case :REPORT
471 ;; is a lambda referring to condition slot accessors:
472 ;; they're not proclaimed as functions before it has run if
473 ;; we're under EVAL or loaded as source.
474 (%set-condition-report
',name
,report
)
477 ;;;; various CONDITIONs specified by ANSI
479 (define-condition serious-condition
(condition) ())
481 (define-condition error
(serious-condition) ())
483 (define-condition warning
(condition) ())
484 (define-condition style-warning
(warning) ())
486 (defun simple-condition-printer (condition stream
)
487 (let ((control (simple-condition-format-control condition
)))
489 (apply #'format stream
491 (simple-condition-format-arguments condition
))
492 (error "No format-control for ~S" condition
))))
494 (define-condition simple-condition
()
495 ((format-control :reader simple-condition-format-control
496 :initarg
:format-control
498 :type format-control
)
499 (format-arguments :reader simple-condition-format-arguments
500 :initarg
:format-arguments
503 (:report simple-condition-printer
))
505 (define-condition simple-warning
(simple-condition warning
) ())
507 (define-condition simple-error
(simple-condition error
) ())
509 (define-condition storage-condition
(serious-condition) ())
511 (define-condition type-error
(error)
512 ((datum :reader type-error-datum
:initarg
:datum
)
513 (expected-type :reader type-error-expected-type
:initarg
:expected-type
))
515 (lambda (condition stream
)
517 "~@<The value ~2I~:_~S ~I~_is not of type ~2I~_~S.~:>"
518 (type-error-datum condition
)
519 (type-error-expected-type condition
)))))
521 (def*method print-object
((condition type-error
) stream
)
522 (if (and *print-escape
*
523 (slot-boundp condition
'expected-type
)
524 (slot-boundp condition
'datum
))
525 (flet ((maybe-string (thing)
527 (write-to-string thing
:lines
1 :readably nil
:array nil
:pretty t
))))
528 (let ((type (maybe-string (type-error-expected-type condition
)))
529 (datum (maybe-string (type-error-datum condition
))))
531 (print-unreadable-object (condition stream
:type t
)
532 (format stream
"~@<expected-type: ~A ~_datum: ~A~:@>" type datum
))
533 (call-next-method))))
536 ;;; not specified by ANSI, but too useful not to have around.
537 (define-condition simple-style-warning
(simple-condition style-warning
) ())
538 (define-condition simple-type-error
(simple-condition type-error
) ())
540 (define-condition program-error
(error) ())
541 (define-condition parse-error
(error) ())
542 (define-condition control-error
(error) ())
543 (define-condition stream-error
(error)
544 ((stream :reader stream-error-stream
:initarg
:stream
)))
546 (define-condition end-of-file
(stream-error) ()
548 (lambda (condition stream
)
551 (stream-error-stream condition
)))))
553 (define-condition closed-stream-error
(stream-error) ()
555 (lambda (condition stream
)
556 (format stream
"~S is closed" (stream-error-stream condition
)))))
558 (define-condition file-error
(error)
559 ((pathname :reader file-error-pathname
:initarg
:pathname
))
561 (lambda (condition stream
)
562 (format stream
"error on file ~S" (file-error-pathname condition
)))))
564 (define-condition package-error
(error)
565 ((package :reader package-error-package
:initarg
:package
)))
567 (define-condition cell-error
(error)
568 ((name :reader cell-error-name
:initarg
:name
)))
570 (def*method print-object
((condition cell-error
) stream
)
571 (if (and *print-escape
* (slot-boundp condition
'name
))
572 (print-unreadable-object (condition stream
:type t
:identity t
)
573 (princ (cell-error-name condition
) stream
))
576 (define-condition unbound-variable
(cell-error) ()
578 (lambda (condition stream
)
580 "The variable ~S is unbound."
581 (cell-error-name condition
)))))
583 (define-condition undefined-function
(cell-error) ()
585 (lambda (condition stream
)
586 (let ((*package
* (find-package :keyword
)))
588 "The function ~S is undefined."
589 (cell-error-name condition
))))))
591 (define-condition special-form-function
(undefined-function) ()
593 (lambda (condition stream
)
595 "Cannot FUNCALL the SYMBOL-FUNCTION of special operator ~S."
596 (cell-error-name condition
)))))
598 (define-condition arithmetic-error
(error)
599 ((operation :reader arithmetic-error-operation
602 (operands :reader arithmetic-error-operands
604 (:report
(lambda (condition stream
)
606 "arithmetic error ~S signalled"
608 (when (arithmetic-error-operation condition
)
610 "~%Operation was ~S, operands ~S."
611 (arithmetic-error-operation condition
)
612 (arithmetic-error-operands condition
))))))
614 (define-condition division-by-zero
(arithmetic-error) ())
615 (define-condition floating-point-overflow
(arithmetic-error) ())
616 (define-condition floating-point-underflow
(arithmetic-error) ())
617 (define-condition floating-point-inexact
(arithmetic-error) ())
618 (define-condition floating-point-invalid-operation
(arithmetic-error) ())
620 (define-condition print-not-readable
(error)
621 ((object :reader print-not-readable-object
:initarg
:object
))
623 (lambda (condition stream
)
624 (let ((obj (print-not-readable-object condition
))
626 (format stream
"~S cannot be printed readably." obj
)))))
628 (define-condition reader-error
(parse-error stream-error
) ()
629 (:report
(lambda (condition stream
)
630 (%report-reader-error condition stream
))))
632 ;;; a READER-ERROR whose REPORTing is controlled by FORMAT-CONTROL and
633 ;;; FORMAT-ARGS (the usual case for READER-ERRORs signalled from
634 ;;; within SBCL itself)
636 ;;; (Inheriting CL:SIMPLE-CONDITION here isn't quite consistent with
637 ;;; the letter of the ANSI spec: this is not a condition signalled by
638 ;;; SIGNAL when a format-control is supplied by the function's first
639 ;;; argument. It seems to me (WHN) to be basically in the spirit of
640 ;;; the spec, but if not, it'd be straightforward to do our own
641 ;;; DEFINE-CONDITION SB-INT:SIMPLISTIC-CONDITION with
642 ;;; FORMAT-CONTROL and FORMAT-ARGS slots, and use that condition in
643 ;;; place of CL:SIMPLE-CONDITION here.)
644 (define-condition simple-reader-error
(reader-error simple-condition
)
646 (:report
(lambda (condition stream
)
647 (%report-reader-error condition stream
:simple t
))))
649 ;;; base REPORTing of a READER-ERROR
651 ;;; When SIMPLE, we expect and use SIMPLE-CONDITION-ish FORMAT-CONTROL
652 ;;; and FORMAT-ARGS slots.
653 (defun %report-reader-error
(condition stream
&key simple position
)
654 (let ((error-stream (stream-error-stream condition
)))
655 (pprint-logical-block (stream nil
)
657 (apply #'format stream
658 (simple-condition-format-control condition
)
659 (simple-condition-format-arguments condition
))
660 (prin1 (class-name (class-of condition
)) stream
))
661 (format stream
"~2I~@[~_~_~:{~:(~A~): ~S~:^, ~:_~}~]~_~_Stream: ~S"
662 (stream-error-position-info error-stream position
)
665 ;;;; special SBCL extension conditions
667 ;;; an error apparently caused by a bug in SBCL itself
669 ;;; Note that we don't make any serious effort to use this condition
670 ;;; for *all* errors in SBCL itself. E.g. type errors and array
671 ;;; indexing errors can occur in functions called from SBCL code, and
672 ;;; will just end up as ordinary TYPE-ERROR or invalid index error,
673 ;;; because the signalling code has no good way to know that the
674 ;;; underlying problem is a bug in SBCL. But in the fairly common case
675 ;;; that the signalling code does know that it's found a bug in SBCL,
676 ;;; this condition is appropriate, reusing boilerplate and helping
677 ;;; users to recognize it as an SBCL bug.
678 (define-condition bug
(simple-error)
681 (lambda (condition stream
)
684 (simple-condition-format-control condition
)
685 (simple-condition-format-arguments condition
)
686 "~@<This is probably a bug in SBCL itself. (Alternatively, ~
687 SBCL might have been corrupted by bad user code, e.g. by an ~
688 undefined Lisp operation like ~S, or by stray pointers from ~
689 alien code or from unsafe Lisp code; or there might be a bug ~
690 in the OS or hardware that SBCL is running on.) If it seems to ~
691 be a bug in SBCL itself, the maintainers would like to know ~
692 about it. Bug reports are welcome on the SBCL ~
693 mailing lists, which you can find at ~
694 <http://sbcl.sourceforge.net/>.~:@>"
695 '((fmakunbound 'compile
))))))
697 (define-condition simple-storage-condition
(storage-condition simple-condition
)
700 ;;; a condition for use in stubs for operations which aren't supported
701 ;;; on some platforms
703 ;;; E.g. in sbcl-0.7.0.5, it might be appropriate to do something like
704 ;;; #-(or freebsd linux)
705 ;;; (defun load-foreign (&rest rest)
706 ;;; (error 'unsupported-operator :name 'load-foreign))
707 ;;; #+(or freebsd linux)
708 ;;; (defun load-foreign ... actual definition ...)
709 ;;; By signalling a standard condition in this case, we make it
710 ;;; possible for test code to distinguish between (1) intentionally
711 ;;; unimplemented and (2) unintentionally just screwed up somehow.
712 ;;; (Before this condition was defined, test code tried to deal with
713 ;;; this by checking for FBOUNDP, but that didn't work reliably. In
714 ;;; sbcl-0.7.0, a package screwup left the definition of
715 ;;; LOAD-FOREIGN in the wrong package, so it was unFBOUNDP even on
716 ;;; architectures where it was supposed to be supported, and the
717 ;;; regression tests cheerfully passed because they assumed that
718 ;;; unFBOUNDPness meant they were running on an system which didn't
719 ;;; support the extension.)
720 (define-condition unsupported-operator
(simple-error) ())
722 ;;; (:ansi-cl :function remove)
723 ;;; (:ansi-cl :section (a b c))
724 ;;; (:ansi-cl :glossary "similar")
726 ;;; (:sbcl :node "...")
727 ;;; (:sbcl :variable *ed-functions*)
729 ;;; FIXME: this is not the right place for this.
730 (defun print-reference (reference stream
)
731 (ecase (car reference
)
733 (format stream
"AMOP")
735 (destructuring-bind (type data
) (cdr reference
)
737 (:readers
"Readers for ~:(~A~) Metaobjects"
738 (substitute #\
#\-
(symbol-name data
)))
740 (format stream
"Initialization of ~:(~A~) Metaobjects"
741 (substitute #\
#\-
(symbol-name data
))))
742 (:generic-function
(format stream
"Generic Function ~S" data
))
743 (:function
(format stream
"Function ~S" data
))
744 (:section
(format stream
"Section ~{~D~^.~}" data
)))))
746 (format stream
"The ANSI Standard")
748 (destructuring-bind (type data
) (cdr reference
)
750 (:function
(format stream
"Function ~S" data
))
751 (:special-operator
(format stream
"Special Operator ~S" data
))
752 (:macro
(format stream
"Macro ~S" data
))
753 (:section
(format stream
"Section ~{~D~^.~}" data
))
754 (:glossary
(format stream
"Glossary entry for ~S" data
))
755 (:type
(format stream
"Type ~S" data
))
756 (:system-class
(format stream
"System Class ~S" data
))
757 (:issue
(format stream
"writeup for Issue ~A" data
)))))
759 (format stream
"The SBCL Manual")
761 (destructuring-bind (type data
) (cdr reference
)
763 (:node
(format stream
"Node ~S" data
))
764 (:variable
(format stream
"Variable ~S" data
))
765 (:function
(format stream
"Function ~S" data
)))))
766 ;; FIXME: other documents (e.g. CLIM, Franz documentation :-)
768 (define-condition reference-condition
()
769 ((references :initarg
:references
:reader reference-condition-references
)))
770 (defvar *print-condition-references
* t
)
771 (def*method print-object
:around
((o reference-condition
) s
)
773 (unless (or *print-escape
* *print-readably
*)
774 (when (and *print-condition-references
*
775 (reference-condition-references o
))
776 (format s
"~&See also:~%")
777 (pprint-logical-block (s nil
:per-line-prefix
" ")
778 (do* ((rs (reference-condition-references o
) (cdr rs
))
779 (r (car rs
) (car rs
)))
781 (print-reference r s
)
782 (unless (null (cdr rs
))
785 (define-condition simple-reference-error
(reference-condition simple-error
)
788 (define-condition simple-reference-warning
(reference-condition simple-warning
)
791 (define-condition arguments-out-of-domain-error
792 (arithmetic-error reference-condition
)
795 ;; per CLHS: "The consequences are unspecified if functions are ...
796 ;; multiply defined in the same file." so we are within reason to do any
797 ;; unspecified behavior at compile-time and/or time, but the compiler was
798 ;; annoyingly mum about genuinely inadvertent duplicate macro definitions.
799 ;; Redefinition is henceforth a style-warning, and for compatibility it does
800 ;; not cause the ERRORP value from COMPILE-TIME to be T.
801 ;; Nor do we cite section 3.2.2.3 as the governing prohibition.
802 (defun report-duplicate-definition (condition stream
)
803 (format stream
"~@<Duplicate definition for ~S found in one file.~@:>"
804 (slot-value condition
'name
)))
806 (define-condition duplicate-definition
(reference-condition warning
)
807 ((name :initarg
:name
:reader duplicate-definition-name
))
808 (:report report-duplicate-definition
)
809 (:default-initargs
:references
(list '(:ansi-cl
:section
(3 2 2 3)))))
810 ;; To my thinking, DUPLICATE-DEFINITION should be the ancestor condition,
811 ;; and not fatal. But changing the meaning of that concept would be a bad idea,
812 ;; so instead there is a new condition for the softer variant, which does not
813 ;; inherit from the former.
814 (define-condition same-file-redefinition-warning
(style-warning)
815 ;; Slot readers aren't proper generic functions until CLOS is built,
816 ;; so this doesn't get a reader because you can't pick the same name,
817 ;; and it wouldn't do any good to pick a different name that nothing knows.
818 ((name :initarg
:name
))
819 (:report report-duplicate-definition
))
821 (define-condition constant-modified
(reference-condition warning
)
822 ((fun-name :initarg
:fun-name
:reader constant-modified-fun-name
))
823 (:report
(lambda (c s
)
824 (format s
"~@<Destructive function ~S called on ~
826 (constant-modified-fun-name c
))))
827 (:default-initargs
:references
(list '(:ansi-cl
:special-operator quote
)
828 '(:ansi-cl
:section
(3 2 2 3)))))
830 (define-condition package-at-variance
(reference-condition simple-warning
)
832 (:default-initargs
:references
(list '(:ansi-cl
:macro defpackage
)
833 '(:sbcl
:variable
*on-package-variance
*))))
835 (define-condition package-at-variance-error
(reference-condition simple-condition
838 (:default-initargs
:references
(list '(:ansi-cl
:macro defpackage
))))
840 (define-condition defconstant-uneql
(reference-condition error
)
841 ((name :initarg
:name
:reader defconstant-uneql-name
)
842 (old-value :initarg
:old-value
:reader defconstant-uneql-old-value
)
843 (new-value :initarg
:new-value
:reader defconstant-uneql-new-value
))
845 (lambda (condition stream
)
847 "~@<The constant ~S is being redefined (from ~S to ~S)~@:>"
848 (defconstant-uneql-name condition
)
849 (defconstant-uneql-old-value condition
)
850 (defconstant-uneql-new-value condition
))))
851 (:default-initargs
:references
(list '(:ansi-cl
:macro defconstant
)
852 '(:sbcl
:node
"Idiosyncrasies"))))
854 (define-condition array-initial-element-mismatch
855 (reference-condition simple-warning
)
859 '(:ansi-cl
:function make-array
)
860 '(:ansi-cl
:function sb
!xc
:upgraded-array-element-type
))))
862 (define-condition type-warning
(reference-condition simple-warning
)
864 (:default-initargs
:references
(list '(:sbcl
:node
"Handling of Types"))))
865 (define-condition type-style-warning
(reference-condition simple-style-warning
)
867 (:default-initargs
:references
(list '(:sbcl
:node
"Handling of Types"))))
869 (define-condition local-argument-mismatch
(reference-condition simple-warning
)
871 (:default-initargs
:references
(list '(:ansi-cl
:section
(3 2 2 3)))))
873 (define-condition format-args-mismatch
(reference-condition)
875 (:default-initargs
:references
(list '(:ansi-cl
:section
(22 3 10 2)))))
877 (define-condition format-too-few-args-warning
878 (format-args-mismatch simple-warning
)
880 (define-condition format-too-many-args-warning
881 (format-args-mismatch simple-style-warning
)
884 (define-condition implicit-generic-function-warning
(style-warning)
885 ((name :initarg
:name
:reader implicit-generic-function-name
))
887 (lambda (condition stream
)
888 (format stream
"~@<Implicitly creating new generic function ~
889 ~/sb-impl::print-symbol-with-prefix/.~:@>"
890 (implicit-generic-function-name condition
)))))
892 (define-condition extension-failure
(reference-condition simple-error
)
895 (define-condition structure-initarg-not-keyword
896 (reference-condition simple-style-warning
)
898 (:default-initargs
:references
(list '(:ansi-cl
:section
(2 4 8 13)))))
903 (define-condition package-lock-violation
(package-error
906 ((current-package :initform
*package
*
907 :reader package-lock-violation-in-package
))
909 (lambda (condition stream
)
910 (let ((control (simple-condition-format-control condition
))
911 (error-package (package-name
912 (package-error-package condition
)))
913 (current-package (package-name
914 (package-lock-violation-in-package condition
))))
915 (format stream
"~@<Lock on package ~A violated~@[~{ when ~?~}~] ~
916 while in package ~A.~:@>"
919 (list control
(simple-condition-format-arguments condition
)))
921 ;; no :default-initargs -- reference-stuff provided by the
922 ;; signalling form in target-package.lisp
925 "Subtype of CL:PACKAGE-ERROR. A subtype of this error is signalled
926 when a package-lock is violated."))
928 (define-condition package-locked-error
(package-lock-violation) ()
931 "Subtype of SB-EXT:PACKAGE-LOCK-VIOLATION. An error of this type is
932 signalled when an operation on a package violates a package lock."))
934 (define-condition symbol-package-locked-error
(package-lock-violation)
935 ((symbol :initarg
:symbol
:reader package-locked-error-symbol
))
938 "Subtype of SB-EXT:PACKAGE-LOCK-VIOLATION. An error of this type is
939 signalled when an operation on a symbol violates a package lock. The
940 symbol that caused the violation is accessed by the function
941 SB-EXT:PACKAGE-LOCKED-ERROR-SYMBOL."))
945 (define-condition undefined-alien-error
(cell-error) ()
947 (lambda (condition stream
)
948 (if (slot-boundp condition
'name
)
949 (format stream
"Undefined alien: ~S" (cell-error-name condition
))
950 (format stream
"Undefined alien symbol.")))))
952 (define-condition undefined-alien-variable-error
(undefined-alien-error) ()
954 (lambda (condition stream
)
955 (declare (ignore condition
))
956 (format stream
"Attempt to access an undefined alien variable."))))
958 (define-condition undefined-alien-function-error
(undefined-alien-error) ()
960 (lambda (condition stream
)
961 (if (and (slot-boundp condition
'name
)
962 (cell-error-name condition
))
963 (format stream
"The alien function ~s is undefined."
964 (cell-error-name condition
))
965 (format stream
"Attempt to call an undefined alien function.")))))
968 ;;;; various other (not specified by ANSI) CONDITIONs
970 ;;;; These might logically belong in other files; they're here, after
971 ;;;; setup of CONDITION machinery, only because that makes it easier to
972 ;;;; get cold init to work.
974 ;;; OAOOM warning: see cross-condition.lisp
975 (define-condition encapsulated-condition
(condition)
976 ((condition :initarg
:condition
:reader encapsulated-condition
)))
978 ;;; KLUDGE: a condition for floating point errors when we can't or
979 ;;; won't figure out what type they are. (In FreeBSD and OpenBSD we
980 ;;; don't know how, at least as of sbcl-0.6.7; in Linux we probably
981 ;;; know how but the old code was broken by the conversion to POSIX
982 ;;; signal handling and hasn't been fixed as of sbcl-0.6.7.)
984 ;;; FIXME: Perhaps this should also be a base class for all
985 ;;; floating point exceptions?
986 (define-condition floating-point-exception
(arithmetic-error)
987 ((flags :initarg
:traps
989 :reader floating-point-exception-traps
))
990 (:report
(lambda (condition stream
)
992 "An arithmetic error ~S was signalled.~%"
994 (let ((traps (floating-point-exception-traps condition
)))
997 "Trapping conditions are: ~%~{ ~S~^~}~%"
1000 "No traps are enabled? How can this be?"
1003 (define-condition invalid-array-index-error
(type-error)
1004 ((array :initarg
:array
:reader invalid-array-index-error-array
)
1005 (axis :initarg
:axis
:reader invalid-array-index-error-axis
))
1007 (lambda (condition stream
)
1008 (let ((array (invalid-array-index-error-array condition
)))
1009 (format stream
"Invalid index ~W for ~@[axis ~W of ~]~S, ~
1010 should be a non-negative integer below ~W."
1011 (type-error-datum condition
)
1012 (when (> (array-rank array
) 1)
1013 (invalid-array-index-error-axis condition
))
1015 ;; Extract the bound from (INTEGER 0 (BOUND))
1016 (caaddr (type-error-expected-type condition
)))))))
1018 (define-condition invalid-array-error
(reference-condition type-error
) ()
1020 (lambda (condition stream
)
1021 (let ((*print-array
* nil
))
1023 "~@<Displaced array originally of type ~S has been invalidated ~
1024 due its displaced-to array ~S having become too small to hold ~
1025 it: the displaced array's dimensions have all been set to zero ~
1026 to trap accesses to it.~:@>"
1027 (type-error-expected-type condition
)
1028 (array-displacement (type-error-datum condition
))))))
1031 (list '(:ansi-cl
:function adjust-array
))))
1033 (define-condition index-too-large-error
(type-error)
1036 (lambda (condition stream
)
1038 "The index ~S is too large."
1039 (type-error-datum condition
)))))
1041 (define-condition bounding-indices-bad-error
(reference-condition type-error
)
1042 ((object :reader bounding-indices-bad-object
:initarg
:object
))
1044 (lambda (condition stream
)
1045 (let* ((datum (type-error-datum condition
))
1048 (object (bounding-indices-bad-object condition
)))
1052 "The bounding indices ~S and ~S are bad ~
1053 for a sequence of length ~S."
1054 start end
(length object
)))
1056 ;; from WITH-ARRAY-DATA
1058 "The START and END parameters ~S and ~S are ~
1059 bad for an array of total size ~S."
1060 start end
(array-total-size object
)))))))
1063 (list '(:ansi-cl
:glossary
"bounding index designator")
1064 '(:ansi-cl
:issue
"SUBSEQ-OUT-OF-BOUNDS:IS-AN-ERROR"))))
1066 (define-condition nil-array-accessed-error
(reference-condition type-error
)
1068 (:report
(lambda (condition stream
)
1069 (declare (ignore condition
))
1071 "An attempt to access an array of element-type ~
1072 NIL was made. Congratulations!")))
1074 :references
(list '(:ansi-cl
:function sb
!xc
:upgraded-array-element-type
)
1075 '(:ansi-cl
:section
(15 1 2 1))
1076 '(:ansi-cl
:section
(15 1 2 2)))))
1078 (define-condition namestring-parse-error
(parse-error)
1079 ((complaint :reader namestring-parse-error-complaint
:initarg
:complaint
)
1080 (args :reader namestring-parse-error-args
:initarg
:args
:initform nil
)
1081 (namestring :reader namestring-parse-error-namestring
:initarg
:namestring
)
1082 (offset :reader namestring-parse-error-offset
:initarg
:offset
))
1084 (lambda (condition stream
)
1086 "parse error in namestring: ~?~% ~A~% ~V@T^"
1087 (namestring-parse-error-complaint condition
)
1088 (namestring-parse-error-args condition
)
1089 (namestring-parse-error-namestring condition
)
1090 (namestring-parse-error-offset condition
)))))
1092 (define-condition simple-package-error
(simple-condition package-error
) ())
1094 (define-condition simple-reader-package-error
(simple-reader-error package-error
) ())
1096 (define-condition reader-eof-error
(end-of-file)
1097 ((context :reader reader-eof-error-context
:initarg
:context
))
1099 (lambda (condition stream
)
1101 "unexpected end of file on ~S ~A"
1102 (stream-error-stream condition
)
1103 (reader-eof-error-context condition
)))))
1105 (define-condition reader-impossible-number-error
(simple-reader-error)
1106 ((error :reader reader-impossible-number-error-error
:initarg
:error
))
1108 (lambda (condition stream
)
1109 (let ((error-stream (stream-error-stream condition
)))
1111 "READER-ERROR ~@[at ~W ~]on ~S:~%~?~%Original error: ~A"
1112 (sb!impl
::file-position-or-nil-for-error error-stream
) error-stream
1113 (simple-condition-format-control condition
)
1114 (simple-condition-format-arguments condition
)
1115 (reader-impossible-number-error-error condition
))))))
1117 (define-condition standard-readtable-modified-error
(reference-condition error
)
1118 ((operation :initarg
:operation
:reader standard-readtable-modified-operation
))
1119 (:report
(lambda (condition stream
)
1120 (format stream
"~S would modify the standard readtable."
1121 (standard-readtable-modified-operation condition
))))
1122 (:default-initargs
:references
`((:ansi-cl
:section
(2 1 1 2))
1123 (:ansi-cl
:glossary
"standard readtable"))))
1125 (define-condition standard-pprint-dispatch-table-modified-error
1126 (reference-condition error
)
1127 ((operation :initarg
:operation
1128 :reader standard-pprint-dispatch-table-modified-operation
))
1129 (:report
(lambda (condition stream
)
1130 (format stream
"~S would modify the standard pprint dispatch table."
1131 (standard-pprint-dispatch-table-modified-operation
1134 :references
`((:ansi-cl
:glossary
"standard pprint dispatch table"))))
1136 (define-condition timeout
(serious-condition)
1137 ((seconds :initarg
:seconds
:initform nil
:reader timeout-seconds
))
1138 (:report
(lambda (condition stream
)
1139 (format stream
"Timeout occurred~@[ after ~A seconds~]."
1140 (timeout-seconds condition
)))))
1142 (define-condition io-timeout
(stream-error timeout
)
1143 ((direction :reader io-timeout-direction
:initarg
:direction
))
1145 (lambda (condition stream
)
1146 (declare (type stream stream
))
1148 "I/O timeout while doing ~(~A~) on ~S."
1149 (io-timeout-direction condition
)
1150 (stream-error-stream condition
)))))
1152 (define-condition deadline-timeout
(timeout) ()
1153 (:report
(lambda (condition stream
)
1154 (format stream
"A deadline was reached after ~A seconds."
1155 (timeout-seconds condition
)))))
1157 (define-condition declaration-type-conflict-error
(reference-condition
1161 :format-control
"symbol ~S cannot be both the name of a type and the name of a declaration"
1162 :references
(list '(:ansi-cl
:section
(3 8 21)))))
1164 ;;; Single stepping conditions
1166 (define-condition step-condition
()
1167 ((form :initarg
:form
:reader step-condition-form
))
1170 (:documentation
"Common base class of single-stepping conditions.
1171 STEP-CONDITION-FORM holds a string representation of the form being
1175 (setf (fdocumentation 'step-condition-form
'function
)
1176 "Form associated with the STEP-CONDITION.")
1178 (define-condition step-form-condition
(step-condition)
1179 ((args :initarg
:args
:reader step-condition-args
))
1181 (lambda (condition stream
)
1182 (let ((*print-circle
* t
)
1184 (*print-readably
* nil
))
1186 "Evaluating call:~%~< ~@;~A~:>~%~
1187 ~:[With arguments:~%~{ ~S~%~}~;With unknown arguments~]~%"
1188 (list (step-condition-form condition
))
1189 (eq (step-condition-args condition
) :unknown
)
1190 (step-condition-args condition
)))))
1192 (:documentation
"Condition signalled by code compiled with
1193 single-stepping information when about to execute a form.
1194 STEP-CONDITION-FORM holds the form, STEP-CONDITION-PATHNAME holds the
1195 pathname of the original file or NIL, and STEP-CONDITION-SOURCE-PATH
1196 holds the source-path to the original form within that file or NIL.
1197 Associated with this condition are always the restarts STEP-INTO,
1198 STEP-NEXT, and STEP-CONTINUE."))
1200 (define-condition step-result-condition
(step-condition)
1201 ((result :initarg
:result
:reader step-condition-result
)))
1204 (setf (fdocumentation 'step-condition-result
'function
)
1205 "Return values associated with STEP-VALUES-CONDITION as a list,
1206 or the variable value associated with STEP-VARIABLE-CONDITION.")
1208 (define-condition step-values-condition
(step-result-condition)
1211 (:documentation
"Condition signalled by code compiled with
1212 single-stepping information after executing a form.
1213 STEP-CONDITION-FORM holds the form, and STEP-CONDITION-RESULT holds
1214 the values returned by the form as a list. No associated restarts."))
1216 (define-condition step-finished-condition
(step-condition)
1219 (lambda (condition stream
)
1220 (declare (ignore condition
))
1221 (format stream
"Returning from STEP")))
1223 (:documentation
"Condition signaled when STEP returns."))
1225 ;;; A knob for muffling warnings, mostly for use while loading files.
1226 (defvar *muffled-warnings
* 'uninteresting-redefinition
1228 "A type that ought to specify a subtype of WARNING. Whenever a
1229 warning is signaled, if the warning if of this type and is not
1230 handled by any other handler, it will be muffled.")
1232 ;;; Various STYLE-WARNING signaled in the system.
1233 ;; For the moment, we're only getting into the details for function
1234 ;; redefinitions, but other redefinitions could be done later
1236 (define-condition redefinition-warning
(style-warning)
1239 :reader redefinition-warning-name
)
1241 :initarg
:new-location
1242 :reader redefinition-warning-new-location
)))
1244 (define-condition function-redefinition-warning
(redefinition-warning)
1246 :initarg
:new-function
1247 :reader function-redefinition-warning-new-function
)))
1249 (define-condition redefinition-with-defun
(function-redefinition-warning)
1251 (:report
(lambda (warning stream
)
1252 (format stream
"redefining ~/sb-impl::print-symbol-with-prefix/ ~
1254 (redefinition-warning-name warning
)))))
1256 (define-condition redefinition-with-defmacro
(function-redefinition-warning)
1258 (:report
(lambda (warning stream
)
1259 (format stream
"redefining ~/sb-impl::print-symbol-with-prefix/ ~
1261 (redefinition-warning-name warning
)))))
1263 (define-condition redefinition-with-defgeneric
(redefinition-warning)
1265 (:report
(lambda (warning stream
)
1266 (format stream
"redefining ~/sb-impl::print-symbol-with-prefix/ ~
1268 (redefinition-warning-name warning
)))))
1270 (define-condition redefinition-with-defmethod
(redefinition-warning)
1271 ((qualifiers :initarg
:qualifiers
1272 :reader redefinition-with-defmethod-qualifiers
)
1273 (specializers :initarg
:specializers
1274 :reader redefinition-with-defmethod-specializers
)
1275 (new-location :initarg
:new-location
1276 :reader redefinition-with-defmethod-new-location
)
1277 (old-method :initarg
:old-method
1278 :reader redefinition-with-defmethod-old-method
))
1279 (:report
(lambda (warning stream
)
1280 (format stream
"redefining ~S~{ ~S~} ~S in DEFMETHOD"
1281 (redefinition-warning-name warning
)
1282 (redefinition-with-defmethod-qualifiers warning
)
1283 (redefinition-with-defmethod-specializers warning
)))))
1285 ;;;; Deciding which redefinitions are "interesting".
1287 (defun function-file-namestring (function)
1289 (when (typep function
'sb
!eval
:interpreted-function
)
1290 (return-from function-file-namestring
1291 (sb!c
:definition-source-location-namestring
1292 (sb!eval
:interpreted-function-source-location function
))))
1294 (when (typep function
'sb
!interpreter
:interpreted-function
)
1295 (return-from function-file-namestring
1296 (awhen (sb!interpreter
:fun-source-location function
)
1297 (sb!c
:definition-source-location-namestring it
))))
1298 (let* ((fun (%fun-fun function
))
1299 (code (fun-code-header fun
))
1300 (debug-info (%code-debug-info code
))
1301 (debug-source (when debug-info
1302 (sb!c
::debug-info-source debug-info
)))
1303 (namestring (when debug-source
1304 (sb!c
::debug-source-namestring debug-source
))))
1307 (defun interesting-function-redefinition-warning-p (warning old
)
1308 (let ((new (function-redefinition-warning-new-function warning
))
1309 (source-location (redefinition-warning-new-location warning
)))
1311 ;; compiled->interpreted is interesting.
1312 (and (typep old
'compiled-function
)
1313 (typep new
'(not compiled-function
)))
1314 ;; fin->regular is interesting except for interpreted->compiled.
1315 (and (typep new
'(not funcallable-instance
))
1316 (typep old
'(and funcallable-instance
1317 #!+sb-fasteval
(not sb
!interpreter
:interpreted-function
)
1318 #!+sb-eval
(not sb
!eval
:interpreted-function
))))
1319 ;; different file or unknown location is interesting.
1320 (let* ((old-namestring (function-file-namestring old
))
1322 (or (function-file-namestring new
)
1323 (when source-location
1324 (sb!c
::definition-source-location-namestring source-location
)))))
1325 (and (or (not old-namestring
)
1326 (not new-namestring
)
1327 (not (string= old-namestring new-namestring
))))))))
1329 (setf (info :function
:predicate-truth-constraint
1330 'uninteresting-ordinary-function-redefinition-p
) 'warning
)
1331 (defun uninteresting-ordinary-function-redefinition-p (warning)
1333 (typep warning
'redefinition-with-defun
)
1335 (let ((name (redefinition-warning-name warning
)))
1336 (not (interesting-function-redefinition-warning-p
1337 warning
(or (fdefinition name
) (macro-function name
)))))))
1339 (setf (info :function
:predicate-truth-constraint
1340 'uninteresting-macro-redefinition-p
) 'warning
)
1341 (defun uninteresting-macro-redefinition-p (warning)
1343 (typep warning
'redefinition-with-defmacro
)
1345 (let ((name (redefinition-warning-name warning
)))
1346 (not (interesting-function-redefinition-warning-p
1347 warning
(or (macro-function name
) (fdefinition name
)))))))
1349 (setf (info :function
:predicate-truth-constraint
1350 'uninteresting-generic-function-redefinition-p
) 'warning
)
1351 (defun uninteresting-generic-function-redefinition-p (warning)
1353 (typep warning
'redefinition-with-defgeneric
)
1354 ;; Can't use the shared logic above, since GF's don't get a "new"
1355 ;; definition -- rather the FIN-FUNCTION is set.
1356 (let* ((name (redefinition-warning-name warning
))
1357 (old (fdefinition name
))
1358 (old-location (when (typep old
'generic-function
)
1359 (sb!pcl
::definition-source old
)))
1360 (old-namestring (when old-location
1361 (sb!c
:definition-source-location-namestring old-location
)))
1362 (new-location (redefinition-warning-new-location warning
))
1363 (new-namestring (when new-location
1364 (sb!c
:definition-source-location-namestring new-location
))))
1367 (string= old-namestring new-namestring
)))))
1369 (setf (info :function
:predicate-truth-constraint
1370 'uninteresting-method-redefinition-p
) 'warning
)
1371 (defun uninteresting-method-redefinition-p (warning)
1373 (typep warning
'redefinition-with-defmethod
)
1374 ;; Can't use the shared logic above, since GF's don't get a "new"
1375 ;; definition -- rather the FIN-FUNCTION is set.
1376 (let* ((old-method (redefinition-with-defmethod-old-method warning
))
1377 (old-location (sb!pcl
::definition-source old-method
))
1378 (old-namestring (when old-location
1379 (sb!c
:definition-source-location-namestring old-location
)))
1380 (new-location (redefinition-warning-new-location warning
))
1381 (new-namestring (when new-location
1382 (sb!c
:definition-source-location-namestring new-location
))))
1385 (string= new-namestring old-namestring
)))))
1387 (deftype uninteresting-redefinition
()
1388 '(or (satisfies uninteresting-ordinary-function-redefinition-p
)
1389 (satisfies uninteresting-macro-redefinition-p
)
1390 (satisfies uninteresting-generic-function-redefinition-p
)
1391 (satisfies uninteresting-method-redefinition-p
)))
1393 (define-condition redefinition-with-deftransform
(redefinition-warning)
1394 ((transform :initarg
:transform
1395 :reader redefinition-with-deftransform-transform
))
1396 (:report
(lambda (warning stream
)
1397 (format stream
"Overwriting ~S"
1398 (redefinition-with-deftransform-transform warning
)))))
1400 ;;; Various other STYLE-WARNINGS
1401 (define-condition dubious-asterisks-around-variable-name
1402 (style-warning simple-condition
)
1404 (:report
(lambda (warning stream
)
1405 (format stream
"~@?, even though the name follows~@
1406 the usual naming convention (names like *FOO*) for special variables"
1407 (simple-condition-format-control warning
)
1408 (simple-condition-format-arguments warning
)))))
1410 (define-condition asterisks-around-lexical-variable-name
1411 (dubious-asterisks-around-variable-name)
1414 (define-condition asterisks-around-constant-variable-name
1415 (dubious-asterisks-around-variable-name)
1418 ;; We call this UNDEFINED-ALIEN-STYLE-WARNING because there are some
1419 ;; subclasses of ERROR above having to do with undefined aliens.
1420 (define-condition undefined-alien-style-warning
(style-warning)
1421 ((symbol :initarg
:symbol
:reader undefined-alien-symbol
))
1422 (:report
(lambda (warning stream
)
1423 (format stream
"Undefined alien: ~S"
1424 (undefined-alien-symbol warning
)))))
1426 #!+(or sb-eval sb-fasteval
)
1427 (define-condition lexical-environment-too-complex
(style-warning)
1428 ((form :initarg
:form
:reader lexical-environment-too-complex-form
)
1429 (lexenv :initarg
:lexenv
:reader lexical-environment-too-complex-lexenv
))
1430 (:report
(lambda (warning stream
)
1432 "~@<Native lexical environment too complex for ~
1433 SB-EVAL to evaluate ~S, falling back to ~
1434 SIMPLE-EVAL-IN-LEXENV. Lexenv: ~S~:@>"
1435 (lexical-environment-too-complex-form warning
)
1436 (lexical-environment-too-complex-lexenv warning
)))))
1438 ;; If the interpreter is in use (and the REPL is interpreted),
1439 ;; it's easy to accidentally make the macroexpand-hook an interpreted
1440 ;; function. So MACROEXPAND-1 is a little more careful,
1441 ;; and might signal this, instead of only EVAL being able to signal it.
1442 (define-condition macroexpand-hook-type-error
(type-error)
1444 (:report
(lambda (condition stream
)
1445 (format stream
"The value of *MACROEXPAND-HOOK* is not a designator for a compiled function: ~S"
1446 (type-error-datum condition
)))))
1448 ;; Although this has -ERROR- in the name, it's just a STYLE-WARNING.
1449 (define-condition character-decoding-error-in-comment
(style-warning)
1450 ((stream :initarg
:stream
:reader decoding-error-in-comment-stream
)
1451 (position :initarg
:position
:reader decoding-error-in-comment-position
))
1452 (:report
(lambda (warning stream
)
1454 "Character decoding error in a ~A-comment at ~
1455 position ~A reading source stream ~A, ~
1457 (decoding-error-in-comment-macro warning
)
1458 (decoding-error-in-comment-position warning
)
1459 (decoding-error-in-comment-stream warning
)))))
1461 (define-condition character-decoding-error-in-macro-char-comment
1462 (character-decoding-error-in-comment)
1463 ((char :initform
#\
; :initarg :char
1464 :reader character-decoding-error-in-macro-char-comment-char
)))
1466 (define-condition character-decoding-error-in-dispatch-macro-char-comment
1467 (character-decoding-error-in-comment)
1468 ;; ANSI doesn't give a way for a reader function invoked by a
1469 ;; dispatch macro character to determine which dispatch character
1470 ;; was used, so if a user wants to signal one of these from a custom
1471 ;; comment reader, he'll have to supply the :DISP-CHAR himself.
1472 ((disp-char :initform
#\
# :initarg
:disp-char
1473 :reader character-decoding-error-in-macro-char-comment-disp-char
)
1474 (sub-char :initarg
:sub-char
1475 :reader character-decoding-error-in-macro-char-comment-sub-char
)))
1477 (defun decoding-error-in-comment-macro (warning)
1479 (character-decoding-error-in-macro-char-comment
1480 (character-decoding-error-in-macro-char-comment-char warning
))
1481 (character-decoding-error-in-dispatch-macro-char-comment
1484 (character-decoding-error-in-macro-char-comment-disp-char warning
)
1485 (character-decoding-error-in-macro-char-comment-sub-char warning
)))))
1487 (define-condition deprecated-eval-when-situations
(style-warning)
1488 ((situations :initarg
:situations
1489 :reader deprecated-eval-when-situations-situations
))
1490 (:report
(lambda (warning stream
)
1491 (format stream
"using deprecated EVAL-WHEN situation names~{ ~S~}"
1492 (deprecated-eval-when-situations-situations warning
)))))
1494 (define-condition proclamation-mismatch
(condition)
1495 ((kind :initarg
:kind
:reader proclamation-mismatch-kind
)
1496 (description :initarg
:description
:reader proclamation-mismatch-description
:initform nil
)
1497 (name :initarg
:name
:reader proclamation-mismatch-name
)
1498 (old :initarg
:old
:reader proclamation-mismatch-old
)
1499 (new :initarg
:new
:reader proclamation-mismatch-new
))
1501 (lambda (condition stream
)
1502 ;; if we later decide we want package-qualified names, bind
1503 ;; *PACKAGE* to (find-package "KEYWORD") here.
1505 "~@<The new ~A proclamation for~@[ ~A~] ~S~
1507 does not match the old ~4:*~A~3* proclamation~
1509 (proclamation-mismatch-kind condition
)
1510 (proclamation-mismatch-description condition
)
1511 (proclamation-mismatch-name condition
)
1512 (proclamation-mismatch-new condition
)
1513 (proclamation-mismatch-old condition
)))))
1515 (define-condition type-proclamation-mismatch
(proclamation-mismatch)
1517 (:default-initargs
:kind
'type
))
1519 (define-condition type-proclamation-mismatch-warning
(style-warning
1520 type-proclamation-mismatch
)
1523 (define-condition ftype-proclamation-mismatch
(proclamation-mismatch)
1525 (:default-initargs
:kind
'ftype
))
1527 (define-condition ftype-proclamation-mismatch-warning
(style-warning
1528 ftype-proclamation-mismatch
)
1531 (define-condition ftype-proclamation-mismatch-error
(error
1532 ftype-proclamation-mismatch
)
1534 (:default-initargs
:kind
'ftype
:description
"known function"))
1537 ;;;; deprecation conditions
1539 (define-condition deprecation-condition
(reference-condition)
1540 ((namespace :initarg
:namespace
1541 :reader deprecation-condition-namespace
)
1542 (name :initarg
:name
1543 :reader deprecation-condition-name
)
1544 (replacements :initarg
:replacements
1545 :reader deprecation-condition-replacements
)
1546 (software :initarg
:software
1547 :reader deprecation-condition-software
)
1548 (version :initarg
:version
1549 :reader deprecation-condition-version
)
1550 (runtime-error :initarg
:runtime-error
1551 :reader deprecation-condition-runtime-error
1554 :namespace
(missing-arg)
1556 :replacements
(missing-arg)
1557 :software
(missing-arg)
1558 :version
(missing-arg)
1559 :references
'((:sbcl
:node
"Deprecation Conditions")))
1562 "Superclass for deprecation-related error and warning
1565 (defmethod print-object ((condition deprecation-condition
) stream
)
1566 (flet ((print-it (stream)
1567 (print-deprecation-message
1568 (deprecation-condition-namespace condition
)
1569 (deprecation-condition-name condition
)
1570 (deprecation-condition-software condition
)
1571 (deprecation-condition-version condition
)
1572 (deprecation-condition-replacements condition
)
1575 (print-unreadable-object (condition stream
:type t
)
1577 (print-it stream
))))
1579 (macrolet ((define-deprecation-warning
1580 (name superclass check-runtime-error format-string
1581 &optional documentation
)
1583 (define-condition ,name
(,superclass deprecation-condition
)
1585 ,@(when documentation
1586 `((:documentation
,documentation
))))
1588 (def*method print-object
:after
((condition ,name
) stream
)
1589 (when (and (not *print-escape
*)
1590 ,@(when check-runtime-error
1591 `((deprecation-condition-runtime-error condition
))))
1592 (format stream
,format-string
1593 (deprecation-condition-software condition
)
1594 (deprecation-condition-name condition
)))))))
1596 (define-deprecation-warning early-deprecation-warning style-warning nil
1597 (!uncross-format-control
1598 "~%~@<~:@_In future ~A versions ~
1599 ~/sb!impl:print-symbol-with-prefix/ will signal a full warning ~
1600 at compile-time.~:@>")
1602 "This warning is signaled when the use of a variable,
1603 function, type, etc. in :EARLY deprecation is detected at
1604 compile-time. The use will work at run-time with no warning or
1607 (define-deprecation-warning late-deprecation-warning warning t
1608 (!uncross-format-control
1609 "~%~@<~:@_In future ~A versions ~
1610 ~/sb!impl:print-symbol-with-prefix/ will signal a runtime ~
1613 "This warning is signaled when the use of a variable,
1614 function, type, etc. in :LATE deprecation is detected at
1615 compile-time. The use will work at run-time with no warning or
1618 (define-deprecation-warning final-deprecation-warning warning t
1619 (!uncross-format-control
1620 "~%~@<~:@_~*An error will be signaled at runtime for ~
1621 ~/sb!impl:print-symbol-with-prefix/.~:@>")
1623 "This warning is signaled when the use of a variable,
1624 function, type, etc. in :FINAL deprecation is detected at
1625 compile-time. An error will be signaled at run-time."))
1627 (define-condition deprecation-error
(error deprecation-condition
)
1631 "This error is signaled at run-time when an attempt is made to use
1632 a thing that is in :FINAL deprecation, i.e. call a function or access
1635 ;;;; restart definitions
1637 (define-condition abort-failure
(control-error) ()
1639 "An ABORT restart was found that failed to transfer control dynamically."))
1641 (defun abort (&optional condition
)
1643 "Transfer control to a restart named ABORT, signalling a CONTROL-ERROR if
1645 (invoke-restart (find-restart-or-control-error 'abort condition
))
1646 ;; ABORT signals an error in case there was a restart named ABORT
1647 ;; that did not transfer control dynamically. This could happen with
1649 (error 'abort-failure
))
1651 (defun muffle-warning (&optional condition
)
1653 "Transfer control to a restart named MUFFLE-WARNING, signalling a
1654 CONTROL-ERROR if none exists."
1655 (invoke-restart (find-restart-or-control-error 'muffle-warning condition
)))
1657 (defun try-restart (name condition
&rest arguments
)
1658 (let ((restart (find-restart name condition
)))
1660 (apply #'invoke-restart restart arguments
))))
1662 (macrolet ((define-nil-returning-restart (name args doc
)
1663 #!-sb-doc
(declare (ignore doc
))
1664 `(defun ,name
(,@args
&optional condition
)
1666 (try-restart ',name condition
,@args
))))
1667 (define-nil-returning-restart continue
()
1668 "Transfer control to a restart named CONTINUE, or return NIL if none exists.")
1669 (define-nil-returning-restart store-value
(value)
1670 "Transfer control and VALUE to a restart named STORE-VALUE, or
1671 return NIL if none exists.")
1672 (define-nil-returning-restart use-value
(value)
1673 "Transfer control and VALUE to a restart named USE-VALUE, or
1674 return NIL if none exists.")
1675 (define-nil-returning-restart print-unreadably
()
1676 "Transfer control to a restart named SB-EXT:PRINT-UNREADABLY, or
1677 return NIL if none exists."))
1679 ;;; single-stepping restarts
1681 (macrolet ((def (name doc
)
1682 #!-sb-doc
(declare (ignore doc
))
1683 `(defun ,name
(condition)
1685 (invoke-restart (find-restart-or-control-error ',name condition
)))))
1687 "Transfers control to the STEP-CONTINUE restart associated with
1688 the condition, continuing execution without stepping. Signals a
1689 CONTROL-ERROR if the restart does not exist.")
1691 "Transfers control to the STEP-NEXT restart associated with the
1692 condition, executing the current form without stepping and continuing
1693 stepping with the next form. Signals CONTROL-ERROR is the restart does
1696 "Transfers control to the STEP-INTO restart associated with the
1697 condition, stepping into the current form. Signals a CONTROL-ERROR is
1698 the restart does not exist."))
1700 ;;; Compiler macro magic
1702 (define-condition compiler-macro-keyword-problem
()
1703 ((argument :initarg
:argument
:reader compiler-macro-keyword-argument
))
1704 (:report
(lambda (condition stream
)
1705 (format stream
"~@<Argument ~S in keyword position is not ~
1706 a self-evaluating symbol, preventing compiler-macro ~
1708 (compiler-macro-keyword-argument condition
)))))
1710 ;; After (or if) we deem this the optimal name for this condition,
1711 ;; it should be exported from SB-EXT so that people can muffle it.
1712 (define-condition sb
!c
:inlining-dependency-failure
(simple-style-warning) ())
1714 (/show0
"condition.lisp end of file")