Previous: Semi-Inline Expansion, Up: Inline Expansion [Contents][Index]
The extensions:maybe-inline
declaration is a CMUCL
extension. It is similar to inline
, but indicates that inline
expansion may sometimes be desirable, rather than saying that inline
expansion should almost always be done. When used in a global
declaration, extensions:maybe-inline
causes the expansion for
the named functions to be recorded, but the functions aren’t actually
inline expanded unless space
is 0
or the function is
eventually (perhaps locally) declared inline
.
Use of the extensions:maybe-inline
declaration followed by the
defun
is preferable to the standard idiom of:
(proclaim '(inline myfun)) (defun myfun () ...) (proclaim '(notinline myfun)) ;;; Any calls tomyfun
here are not inline expanded. (defun somefun () (declare (inline myfun)) ;; ;; Calls tomyfun
here are inline expanded. ...)
The problem with using notinline
in this way is that in
Common Lisp it does more than just suppress inline expansion, it also
forbids the compiler to use any knowledge of myfun
until a
later inline
declaration overrides the notinline
. This
prevents compiler warnings about incorrect calls to the function, and
also prevents block compilation.
The extensions:maybe-inline
declaration is used like this:
(proclaim '(extensions:maybe-inline myfun)) (defun myfun () ...) ;;; Any calls tomyfun
here are not inline expanded. (defun somefun () (declare (inline myfun)) ;; ;; Calls tomyfun
here are inline expanded. ...) (defun someotherfun () (declare (optimize (space 0))) ;; ;; Calls tomyfun
here are expanded semi-inline. ...)
In this example, the use of extensions:maybe-inline
causes the
expansion to be recorded when the defun
for somefun
is
compiled, and doesn’t waste space through doing inline expansion by
default. Unlike notinline
, this declaration still allows the
compiler to assume that the known definition really is the one that
will be called when giving compiler warnings, and also allows the
compiler to do semi-inline expansion when the policy is appropriate.
When the goal is merely to control whether inline expansion is done by
default, it is preferable to use extensions:maybe-inline
rather
than notinline
. The notinline
declaration should be
reserved for those special occasions when a function may be redefined
at run-time, so the compiler must be told that the obvious definition
of a function is not necessarily the one that will be in effect at the
time of the call.
Previous: Semi-Inline Expansion, Up: Inline Expansion [Contents][Index]