1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

doc: Mention the partial evaluator next to `define-inlinable'.

* doc/ref/api-procedures.texi (Inlinable Procedures): Mention inlining
  performed by the partial evaluator.
This commit is contained in:
Ludovic Courtès 2011-10-15 17:34:48 +02:00
parent 7c42e426dc
commit 43e53d64ca

View file

@ -801,11 +801,31 @@ setter or an operator struct.
@node Inlinable Procedures @node Inlinable Procedures
@subsection Inlinable Procedures @subsection Inlinable Procedures
@cindex inlining
@cindex procedure inlining
You can define an @dfn{inlinable procedure} by using You can define an @dfn{inlinable procedure} by using
@code{define-inlinable} instead of @code{define}. An inlinable @code{define-inlinable} instead of @code{define}. An inlinable
procedure behaves the same as a regular procedure, but direct calls will procedure behaves the same as a regular procedure, but direct calls will
result in the procedure body being inlined into the caller. result in the procedure body being inlined into the caller.
@cindex partial evaluator
Bear in mind that starting from version 2.0.3, Guile has a partial
evaluator that can inline the body of inner procedures when deemed
appropriate:
@example
scheme@@(guile-user)> ,optimize (define (foo x)
(define (bar) (+ x 3))
(* (bar) 2))
$1 = (define foo
(lambda (#@{x 94@}#) (* (+ #@{x 94@}# 3) 2)))
@end example
@noindent
The partial evaluator does not inline top-level bindings, though, so
this is a situation where you may find it interesting to use
@code{define-inlinable}.
Procedures defined with @code{define-inlinable} are @emph{always} Procedures defined with @code{define-inlinable} are @emph{always}
inlined, at all direct call sites. This eliminates function call inlined, at all direct call sites. This eliminates function call
overhead at the expense of an increase in code size. Additionally, the overhead at the expense of an increase in code size. Additionally, the