Optimize some callers of SIGNAL a little more.
[sbcl.git] / src / code / warm-error.lisp
blob89914f30d5b723f5ca11ee9c69b28b3bff8c303c
1 ;;;; error stuff that needs to wait until warm load
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
12 (in-package "SB-KERNEL")
14 ;;; Moved from 'cold-error' to this file because of (at least) these reasons:
15 ;;; - the LOAD-TIME-VALUE forms need to run after 'condition.lisp'
16 ;;; has created the WARNING and STYLE-WARNING classoids
17 ;;; - even if this were loaded no earlier than the classoid definitions,
18 ;;; the entirety of condition handling doesn't work soon enough in cold-init.
19 (flet ((%warn (datum super default-type &rest arguments)
20 (infinite-error-protect
21 (let ((condition (apply #'coerce-to-condition datum default-type 'warn
22 arguments))
23 (superclassoid-name (classoid-name super)))
24 ;; CONDITION is necessarily an INSTANCE,
25 ;; but pedantry requires it be the right subtype of instance.
26 (unless (classoid-typep (%instance-layout condition)
27 super condition)
28 (error 'simple-type-error
29 :datum datum :expected-type superclassoid-name
30 :format-control "~S does not designate a ~A class"
31 :format-arguments (list datum superclassoid-name)))
32 (restart-case (%signal condition)
33 (muffle-warning ()
34 :report "Skip warning."
35 (return-from %warn nil)))
36 (format *error-output* "~&~@<~S: ~3i~:_~A~:>~%"
37 superclassoid-name condition)))
38 nil))
40 ;; We don't warn about redefinition of WARN, apparently (not sure why)
41 (defun warn (datum &rest arguments)
42 #+sb-doc
43 "Warn about a situation by signalling a condition formed by DATUM and
44 ARGUMENTS. While the condition is being signaled, a MUFFLE-WARNING restart
45 exists that causes WARN to immediately return NIL."
46 (declare (explicit-check))
47 ;; FIXME: figure out how to get genesis to understand that certain
48 ;; classoids (particularly those defined by the language standard)
49 ;; never need to go through the classoid-cell indirection,
50 ;; as the classoid object itself is essentially permanent.
51 (apply #'%warn datum (load-time-value (find-classoid 'warning) t)
52 'simple-warning arguments))
54 ;; But we would warn about redefinition of STYLE-WARN.
55 (fmakunbound 'style-warn)
57 (defun style-warn (datum &rest arguments)
58 (declare (explicit-check))
59 (apply #'%warn datum (load-time-value (find-classoid 'style-warning) t)
60 'simple-style-warning arguments)))