Open Coding and Inline Expansion - SBCL 1.0.31 User Manual
Description: SBCL 1.0.31 User Manual

Next: Interpreter, Previous: Compiler Errors, Up: Compiler

### 4.5 Open Coding and Inline Expansion

Since Common Lisp forbids the redefinition of standard functions, the compiler can have special knowledge of these standard functions embedded in it. This special knowledge is used in various ways (open coding, inline expansion, source transformation), but the implications to the user are basically the same:

- Attempts to redefine standard functions may be frustrated, since the function may never be called. Although it is technically illegal to redefine standard functions, users sometimes want to implicitly redefine these functions when they are debugging using the `trace` macro. Special-casing of standard functions can be inhibited using the `notinline` declaration, but even then some phases of analysis such as type inferencing are applied by the compiler.
- The compiler can have multiple alternate implementations of standard functions that implement different trade-offs of speed, space and safety. This selection is based on the compiler policy, Compiler Policy.

When a function call is open coded, inline code whose effect is equivalent to the function call is substituted for that function call. When a function call is closed coded, it is usually left as is, although it might be turned into a call to a different function with different arguments. As an example, if `nthcdr` were to be open coded, then

         (nthcdr 4 foobar)

might turn into

         (cdr (cdr (cdr (cdr foobar))))

or even

         (do ((i 0 (1+ i))
           (list foobar (cdr foobar)))
           ((= i 4) list))

If `nth` is closed coded, then

         (nth x l)

might stay the same, or turn into something like

         (car (nthcdr x l))

In general, open coding sacrifices space for speed, but some functions (such as `car`) are so simple that they are always open-coded. Even when not open-coded, a call to a standard function may be transformed into a different function call (as in the last example) or compiled as static call. Static function call uses a more efficient calling convention that forbids redefinition.