The SBCL compiler treats type declarations differently from most other Lisp compilers. Under default compilation policy the compiler doesn't blindly believe type declarations, but considers them assertions about the program that should be checked: all type declarations that have not been proven to always hold are asserted at runtime.
Remaining bugs in the compiler's handling of types unfortunately provide some exceptions to this rule, see Implementation Limitations.
CLOS slot types form a notable exception. Types declared using the
:type
slot option in defclass
are asserted if and only
if the class was defined in safe code and the slot access
location is in safe code as well. This laxness does not pose
any internal consistency issues, as the CLOS slot types are not
available for the type inferencer, nor do CLOS slot types provide any
efficiency benefits.
There are three type checking policies available in SBCL, selectable
via optimize
declarations.
Used when (or (>= safety 2) (>= safety speed 1))
.
(or (integer -17 -7) (integer 7 17))
is simplified
into (integer -17 17)
.
Note: it is relatively easy to corrupt the heap when weak type checks are used if the program contains type-errors.
Used when (and (< safety 2) (< safety speed))
Note: any type errors in code where type checks are not performed are liable to corrupt the heap.
Used when (= safety 0)
.