INLINE(3cl)

Common Lisp Reference

INLINE(3cl)

 

NAME

inline – indicate desirability of code integration into calling routine (declaration)    

SYNOPSIS

 

( inline { function-name }* )

(
notinline { function-name }* )
 

ARGUMENTS and VALUES

function-name —a function name     

VALID CONTEXT

declaration or proclamation  

BINDING TYPES AFFECTED

function   

DESCRIPTION

inline specifies that it is desirable for the compiler to produce inline calls to the functions named by function-names; that is, the code for a specified function-name should be integrated into the calling routine, appearing “in line” in place of a procedure call. A compiler is free to ignore this declaration. inline declarations never apply to variable bindings.

If one of the functions mentioned has a lexically apparent local definition (as made by flet or labels), then the declaration applies to that local definition and not to the global function definition.

While no conforming implementation is required to perform inline expansion of user-defined functions, those implementations that do attempt to recognize the following paradigm:

To define a function f that is not inline by default but for which (declare (inline f)) will make f be locally inlined, the proper definition sequence is:
   (declaim (inline f))  
   
(defun f ...)  
   
(declaim (notinline f))    

The inline proclamation preceding the defun form ensures that the compiler has the opportunity save the information necessary for inline expansion, and the notinline proclamation following the defun form prevents f from being expanded inline everywhere.

notinline specifies that it is undesirable to compile the functions named by function-names inline. A compiler is not free to ignore this declaration; calls to the specified functions must be implemented as out-of-line subroutine calls.

In the presence of a compiler macro definition for function-name, a notinline declaration prevents that compiler macro from being used. An inline declaration may be used to encourage use of compiler macro definitions. inline and notinline declarations otherwise have no effect when the lexically visible definition of function-name is a macro definition.  

inline and notinline declarations can be free declarations or bound declarations. inline and notinline declarations of functions that appear before the body of a flet or labels form that defines that function are bound declarations. Such declarations in other contexts are free declarations.  

AFFECTED BY

(none)    

EXCEPTIONAL SITUATIONS

(none)     

NOTES

(none)  

EXAMPLES

 
;; The globally defined function DISPATCH should be open-coded,
;; if the implementation supports inlining, unless a NOTINLINE
;; declaration overrides this effect.

( declaim ( inline dispatch ))
( defun dispatch ( x ) ( funcall ( get ( car x ) ’ dispatch ) x ))

;; Here is an example where inlining would be encouraged.
( defun top-level-1 () ( dispatch ( read-command )))

;; Here is an example where inlining would be prohibited.
( defun top-level-2 ()
   
( declare ( notinline dispatch ))
   
( dispatch ( read-command )))  

;; Here is an example where inlining would be prohibited.  
( declaim ( notinline dispatch ))  
( defun top-level-3 () ( dispatch ( read-command )))

;; Here is an example where inlining would be encouraged.
(defun top-level-4 ()
   (declare (inline dispatch))  
   
(dispatch (read-command)))         

SEE ALSO

declare(3cl), declaim(3cl), proclaim(3cl)    

AUTHOR and COPYRIGHT

Substantial portions of this page are taken from draft proposed American National Standard for Information Systems—Programming Language—Common Lisp, X3J13/94-101R, Version 15.17R, Fri 12-Aug-1994 6:35pm EDT; no copyright indicated.

Additional clarification and comments by Michael Marking <marking@tatanka.com>, http://www.tatanka.com/software/cl-manpages/; alternatively, https://github.com/wakinyantanka/cl-manpages/. Copyright 2017 Michael Marking as both an original and a derivative work.

Licensed under Creative Commons Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0).

This page last revised Sunday 26 February 2017.