1
0
Fork 0
cl-sites/guile.html_node/Inlinable-Procedures.html
2024-12-17 12:49:28 +01:00

113 lines
5.3 KiB
HTML

<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This manual documents Guile version 3.0.10.
Copyright (C) 1996-1997, 2000-2005, 2009-2023 Free Software Foundation,
Inc.
Copyright (C) 2021 Maxime Devos
Copyright (C) 2024 Tomas Volf
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
copy of the license is included in the section entitled "GNU Free
Documentation License." -->
<title>Inlinable Procedures (Guile Reference Manual)</title>
<meta name="description" content="Inlinable Procedures (Guile Reference Manual)">
<meta name="keywords" content="Inlinable Procedures (Guile Reference Manual)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content=".texi2any-real">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Procedures.html" rel="up" title="Procedures">
<link href="Procedures-with-Setters.html" rel="prev" title="Procedures with Setters">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
-->
</style>
<link rel="stylesheet" type="text/css" href="https://www.gnu.org/software/gnulib/manual.css">
</head>
<body lang="en">
<div class="subsection-level-extent" id="Inlinable-Procedures">
<div class="nav-panel">
<p>
Previous: <a href="Procedures-with-Setters.html" accesskey="p" rel="prev">Procedures with Setters</a>, Up: <a href="Procedures.html" accesskey="u" rel="up">Procedures</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsection" id="Inlinable-Procedures-1"><span>6.7.9 Inlinable Procedures<a class="copiable-link" href="#Inlinable-Procedures-1"> &para;</a></span></h4>
<a class="index-entry-id" id="index-inlining"></a>
<a class="index-entry-id" id="index-procedure-inlining"></a>
<p>You can define an <em class="dfn">inlinable procedure</em> by using
<code class="code">define-inlinable</code> instead of <code class="code">define</code>. An inlinable
procedure behaves the same as a regular procedure, but direct calls will
result in the procedure body being inlined into the caller.
</p>
<a class="index-entry-id" id="index-partial-evaluator"></a>
<p>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:
</p>
<div class="example">
<pre class="example-preformatted">scheme@(guile-user)&gt; ,optimize (define (foo x)
(define (bar) (+ x 3))
(* (bar) 2))
$1 = (define foo
(lambda (#{x 94}#) (* (+ #{x 94}# 3) 2)))
</pre></div>
<p>The partial evaluator does not inline top-level bindings, though, so
this is a situation where you may find it interesting to use
<code class="code">define-inlinable</code>.
</p>
<p>Procedures defined with <code class="code">define-inlinable</code> are <em class="emph">always</em>
inlined, at all direct call sites. This eliminates function call
overhead at the expense of an increase in code size. Additionally, the
caller will not transparently use the new definition if the inline
procedure is redefined. It is not possible to trace an inlined
procedures or install a breakpoint in it (see <a class="pxref" href="Traps.html">Traps</a>). For these
reasons, you should not make a procedure inlinable unless it
demonstrably improves performance in a crucial way.
</p>
<p>In general, only small procedures should be considered for inlining, as
making large procedures inlinable will probably result in an increase in
code size. Additionally, the elimination of the call overhead rarely
matters for large procedures.
</p>
<dl class="first-deffn">
<dt class="deffn" id="index-define_002dinlinable"><span class="category-def">Scheme Syntax: </span><span><strong class="def-name">define-inlinable</strong> <var class="def-var-arguments">(name parameter &hellip;) body1 body2 &hellip;</var><a class="copiable-link" href="#index-define_002dinlinable"> &para;</a></span></dt>
<dd><p>Define <var class="var">name</var> as a procedure with parameters <var class="var">parameter</var>s and
bodies <var class="var">body1</var>, <var class="var">body2</var>, <small class="enddots">...</small>.
</p></dd></dl>
</div>
<hr>
<div class="nav-panel">
<p>
Previous: <a href="Procedures-with-Setters.html">Procedures with Setters</a>, Up: <a href="Procedures.html">Procedures</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>