From 43e53d64ca34ef7dd6b7f135114c72c9b39b399e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Sat, 15 Oct 2011 17:34:48 +0200 Subject: [PATCH] doc: Mention the partial evaluator next to `define-inlinable'. * doc/ref/api-procedures.texi (Inlinable Procedures): Mention inlining performed by the partial evaluator. --- doc/ref/api-procedures.texi | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/doc/ref/api-procedures.texi b/doc/ref/api-procedures.texi index 5c6d38024..f1861a54a 100644 --- a/doc/ref/api-procedures.texi +++ b/doc/ref/api-procedures.texi @@ -801,11 +801,31 @@ setter or an operator struct. @node Inlinable Procedures @subsection Inlinable Procedures +@cindex inlining +@cindex procedure inlining You can define an @dfn{inlinable procedure} by using @code{define-inlinable} instead of @code{define}. An inlinable procedure behaves the same as a regular procedure, but direct calls will 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} inlined, at all direct call sites. This eliminates function call overhead at the expense of an increase in code size. Additionally, the