Next: , Up: Handling of Types


3.2.1 Declarations as Assertions

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).

There are three type checking policies available in SBCL, selectable via optimize declarations.

Full Type Checks
All declarations are considered assertions to be checked at runtime, and all type checks are precise.

Used when (and (< 0 safety) (or (>= safety 2) (>= safety speed))). The default compilation policy provides full type checks.

Weak Type Checks
Any or all type declarations may be believed without runtime assertions, and assertions that are done may be imprecise. It should be noted that it is relatively easy to corrupt the heap when weak type checks are used, and type-errors are introduced into the program.

Used when (and (< safety 2) (< safety speed))

No Type Checks
All declarations are believed without assertions. Also disables argument count and array bounds checking.

Used when (= safety 0).