Next: , Previous: Handling of Types, Up: Compiler


4.3 Compiler Policy

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.

— Function: sb-ext:describe-compiler-policy &optional spec

Print all global optimization settings, augmented by spec.

— Function: sb-ext:restrict-compiler-policy &optional quality min

Assing a minimum value to an optimization quality. quality is the name of the optimization quality to restrict, and min (defaulting to zero) is the minimum allowed value.

Returns the alist describing the current policy restrictions.

If quality is nil or not given, nothing is done.

Otherwise, if min is zero or not given, any existing restrictions of quality are removed. If min is 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 then min behave as if the value was min instead.

This is intended to be used interactively, to facilitate recompiling large bodies of code with eg. a known minimum safety.

See also :policy option in with-compilation-unit.

experimental interface: Subject to change.

— Macro: cl:with-compilation-unit options &body body

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:

:override Boolean-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 override is nil (the default), then the outermost with-compilation-unit form grabs the undefined warnings. Specifying override true causes that form to grab any enclosed warnings, even if it is enclosed by another with-compilation-unit.
:policy Optimize-Declaration-Form
Provides dynamic scoping for global compiler optimization qualities and restrictions, limiting effects of subsequent optimize proclamations and calls to sb-ext:restrict-compiler-policy to the dynamic scope of body.

If override is false, specified policy is merged with current global policy. If override is true, current global policy, including any restrictions, is discarded in favor of the specified policy.

Supplying policy nil is 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-plist Plist-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-unit form also provide a source-plist, it is appended to the end of the provided source-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"))

Footnotes

[1] A deprecated extension sb-ext:inhibit-warnings is still supported, but liable to go away at any time.