Next: Compiler Errors, Previous: Handling of Types, Up: Compiler
Compiler policy is controlled by the optimize declaration,
supporting all ANSI optimization qualities (debug,
safety, space, and speed).1
For effects of various optimization qualities on type-safety and debuggability see Declarations as Assertions and Debugger Policy Control.
Ordinarily, when the speed quality is high, the compiler emits
notes to notify the programmer about its inability to apply various
optimizations. For selective muffling of these notes See Controlling Verbosity.
The value of space mostly influences the compiler's decision
whether to inline operations, which tend to increase the size of
programs. Use the value 0 with caution, since it can cause the
compiler to inline operations so indiscriminately that the net effect
is to slow the program by causing cache misses or even swapping.
Assing a minimum value to an optimization quality.
qualityis the name of the optimization quality to restrict, andmin(defaulting to zero) is the minimum allowed value.Returns the alist describing the current policy restrictions.
If
qualityisnilor not given, nothing is done.Otherwise, if
minis zero or not given, any existing restrictions ofqualityare removed. Ifminis between one and three inclusive, it becomes the new minimum value for the optimization quality: any future proclamations or declarations of the quality with a value less thenminbehave as if the value wasmininstead.This is intended to be used interactively, to facilitate recompiling large bodies of code with eg. a known minimum safety.
See also
:policyoption inwith-compilation-unit.
experimentalinterface:Subject to change.
Affects compilations that take place within its dynamic extent. It is intended to be eg. wrapped around the compilation of all files in the same system.
Following options are defined:
:overrideBoolean-Form- One of the effects of this form is to delay undefined warnings until the end of the form, instead of giving them at the end of each compilation. If
overrideisnil(the default), then the outermostwith-compilation-unitform grabs the undefined warnings. Specifyingoverridetrue causes that form to grab any enclosed warnings, even if it is enclosed by anotherwith-compilation-unit.:policyOptimize-Declaration-Form- Provides dynamic scoping for global compiler optimization qualities and restrictions, limiting effects of subsequent
optimizeproclamations and calls tosb-ext:restrict-compiler-policyto the dynamic scope ofbody.If
overrideis false, specifiedpolicyis merged with current global policy. Ifoverrideis true, current global policy, including any restrictions, is discarded in favor of the specifiedpolicy.Supplying
policynilis equivalent to the option not being supplied at all, ie. dynamic scoping of policy does not take place.This option is an SBCL-specific experimental extension: Interface subject to change.
:source-plistPlist-Form- Attaches the value returned by the Plist-Form to internal debug-source information of functions compiled in within the dynamic extent of
body.Primarily for use by development environments, in order to eg. associate function definitions with editor-buffers. Can be accessed using
sb-introspect:definition-source-plist.If an outer
with-compilation-unitform also provide asource-plist, it is appended to the end of the providedsource-plist. Unaffected by:override.This is an SBCL-specific extension.
Examples:
;; Prevent proclamations from the file leaking, and restrict ;; SAFETY to 3 -- otherwise uses the current global policy. (with-compilation-unit (:policy '(optimize)) (restrict-compiler-policy 'safety 3) (load "foo.lisp")) ;; Using default policy instead of the current global one, ;; except for DEBUG 3. (with-compilation-unit (:policy '(optimize debug) :override t) (load "foo.lisp")) ;; Same as if :POLICY had not been specified at all: SAFETY 3 ;; proclamation leaks out from WITH-COMPILATION-UNIT. (with-compilation-unit (:policy nil) (declaim (optimize safety)) (load "foo.lisp"))
[1] A deprecated
extension sb-ext:inhibit-warnings is still supported, but
liable to go away at any time.