[ Home ]
SBCL Internals

The pages on this CLiki-driven site can be edited by anybody at any time. No warranty of any kind can therefore be made; any implied warranties of merchantability or fitness for a particular purpose are expressly disclaimed
[ Home ] [ Recent Changes ] [ About CLiki ] [ Text Formatting ]

"Declarations are Assertions" is a principle which, in the aid of maintainability of complex pieces of code, the SBCL compiler aims to support in safe code (i.e. code compiled with the SAFETY optimization quality higher than others). The basic idea is that user type declarations should be checked, not trusted, in these compilation regimes, to enable user errors to be caught earlier.


What to do, though, with declarations in unsafe code? Currently, unless SAFETY is 0, declarations are partially checked (see MAYBE-WEAKEN-CHECK -- as of sbcl-0.7.5, a check is inserted for a convenient supertype).


It is not clear that, in unsafe code, the three following forms have the same effect:

(the fixnum x)

(sb-ext:truly-the fixnum x)

(locally (declare (type fixnum x)) x)

Probably they ought to.


The "declarations are assertions" principle does provide a convenient way of writing compiler IR1 transforms. The second return value from a DEFTRANSFORM? is a list of declarations to be inserted into the generated code; thus, in safe mode, the transformed code compiles to instructions protected by a type check; in unsafe mode, the compiler will implicitly believe the declaration. For an example of this as of sbcl-0.7.6, see the DEFTRANSFORM for FILL.

CLiki pages can be edited by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively