moonpool/dev/ocaml/Inlining_transforms/index.html
2023-08-28 17:11:38 +00:00

32 lines
No EOL
7.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Inlining_transforms (ocaml.Inlining_transforms)</title><link rel="stylesheet" href="../../_odoc-theme/odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 2.2.1"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> <a href="../index.html">ocaml</a> &#x00BB; Inlining_transforms</nav><header class="odoc-preamble"><h1>Module <code><span>Inlining_transforms</span></code></h1><p>Source code transformations used during inlining.</p></header><div class="odoc-content"><div class="odoc-spec"><div class="spec value anchored" id="val-inline_by_copying_function_body"><a href="#val-inline_by_copying_function_body" class="anchor"></a><code><span><span class="keyword">val</span> inline_by_copying_function_body :
<span>env:<a href="../Inline_and_simplify_aux/Env/index.html#type-t">Inline_and_simplify_aux.Env.t</a> <span class="arrow">&#45;&gt;</span></span>
<span>r:<a href="../Inline_and_simplify_aux/Result/index.html#type-t">Inline_and_simplify_aux.Result.t</a> <span class="arrow">&#45;&gt;</span></span>
<span>lhs_of_application:<a href="../Variable/index.html#type-t">Variable.t</a> <span class="arrow">&#45;&gt;</span></span>
<span>inline_requested:<a href="../Lambda/index.html#type-inline_attribute">Lambda.inline_attribute</a> <span class="arrow">&#45;&gt;</span></span>
<span>specialise_requested:<a href="../Lambda/index.html#type-specialise_attribute">Lambda.specialise_attribute</a> <span class="arrow">&#45;&gt;</span></span>
<span>closure_id_being_applied:<a href="../Closure_id/index.html#type-t">Closure_id.t</a> <span class="arrow">&#45;&gt;</span></span>
<span>function_decl:<a href="../Simple_value_approx/index.html#type-function_declaration">Simple_value_approx.function_declaration</a> <span class="arrow">&#45;&gt;</span></span>
<span>function_body:<a href="../Simple_value_approx/index.html#type-function_body">Simple_value_approx.function_body</a> <span class="arrow">&#45;&gt;</span></span>
<span>fun_vars:<a href="../Variable/Set/index.html#type-t">Variable.Set.t</a> <span class="arrow">&#45;&gt;</span></span>
<span>args:<span><a href="../Variable/index.html#type-t">Variable.t</a> list</span> <span class="arrow">&#45;&gt;</span></span>
<span>dbg:<a href="../Debuginfo/index.html#type-t">Debuginfo.t</a> <span class="arrow">&#45;&gt;</span></span>
<span>simplify:<a href="../Inlining_decision_intf/index.html#type-simplify">Inlining_decision_intf.simplify</a> <span class="arrow">&#45;&gt;</span></span>
<a href="../Flambda/index.html#type-t">Flambda.t</a> * <a href="../Inline_and_simplify_aux/Result/index.html#type-t">Inline_and_simplify_aux.Result.t</a></span></code></div><div class="spec-doc"><p>Inline a function by substituting its body (which may be subject to further transformation) at a call site. The function's declaration is not copied.</p><p>This transformation is used when:</p><ul><li>inlining a call to a non-recursive function;</li><li>inlining a call, within a recursive or mutually-recursive function, to the same or another function being defined simultaneously (&quot;unrolling&quot;). The maximum depth of unrolling is bounded (see <code>E.unrolling_allowed</code>).</li></ul><p>In both cases, the body of the function is copied, within a sequence of <code>let</code>s that bind the function parameters, the variables &quot;bound by the closure&quot; (see flambda.mli), and any function identifiers introduced by the set of closures. These stages are delimited below by comments.</p><p>As an example, suppose we are inlining the following function:</p><p>let f x = x + y ... let p = f, f in (fst p) 42</p><p>The call site <code> (fst p) 42</code> will be transformed to:</p><p>let clos_id = fst p in (* must eventually yield a closure *) let y = &lt;access to <code>y</code> in <code>clos_id</code>&gt; in let x' = 42 in let x = x' in x + y</p><p>When unrolling a recursive function we rename the arguments to the recursive call in order to avoid clashes with existing bindings. For example, suppose we are inlining the following call to <code>f</code>, which lies within its own declaration:</p><p>let rec f x y = f (fst x) (y + snd x)</p><p>This will be transformed to:</p><p>let rec f x y = let clos_id = f in (* not used this time, since <code>f</code> has no free vars *) let x' = fst x in let y' = y + snd x in f (fst x') (y' + snd x') (* body of <code>f</code> with parameters freshened *)</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-inline_by_copying_function_declaration"><a href="#val-inline_by_copying_function_declaration" class="anchor"></a><code><span><span class="keyword">val</span> inline_by_copying_function_declaration :
<span>env:<a href="../Inline_and_simplify_aux/Env/index.html#type-t">Inline_and_simplify_aux.Env.t</a> <span class="arrow">&#45;&gt;</span></span>
<span>r:<a href="../Inline_and_simplify_aux/Result/index.html#type-t">Inline_and_simplify_aux.Result.t</a> <span class="arrow">&#45;&gt;</span></span>
<span>function_decls:<a href="../Simple_value_approx/index.html#type-function_declarations">Simple_value_approx.function_declarations</a> <span class="arrow">&#45;&gt;</span></span>
<span>lhs_of_application:<a href="../Variable/index.html#type-t">Variable.t</a> <span class="arrow">&#45;&gt;</span></span>
<span>inline_requested:<a href="../Lambda/index.html#type-inline_attribute">Lambda.inline_attribute</a> <span class="arrow">&#45;&gt;</span></span>
<span>closure_id_being_applied:<a href="../Closure_id/index.html#type-t">Closure_id.t</a> <span class="arrow">&#45;&gt;</span></span>
<span>function_decl:<a href="../Simple_value_approx/index.html#type-function_declaration">Simple_value_approx.function_declaration</a> <span class="arrow">&#45;&gt;</span></span>
<span>args:<span><a href="../Variable/index.html#type-t">Variable.t</a> list</span> <span class="arrow">&#45;&gt;</span></span>
<span>args_approxs:<span><a href="../Simple_value_approx/index.html#type-t">Simple_value_approx.t</a> list</span> <span class="arrow">&#45;&gt;</span></span>
<span>invariant_params:<span><span><a href="../Variable/Set/index.html#type-t">Variable.Set.t</a> <a href="../Variable/Map/index.html#type-t">Variable.Map.t</a></span> lazy_t</span> <span class="arrow">&#45;&gt;</span></span>
<span>specialised_args:<span><a href="../Flambda/index.html#type-specialised_to">Flambda.specialised_to</a> <a href="../Variable/Map/index.html#type-t">Variable.Map.t</a></span> <span class="arrow">&#45;&gt;</span></span>
<span>free_vars:<span><a href="../Flambda/index.html#type-specialised_to">Flambda.specialised_to</a> <a href="../Variable/Map/index.html#type-t">Variable.Map.t</a></span> <span class="arrow">&#45;&gt;</span></span>
<span>direct_call_surrogates:<span><a href="../Closure_id/index.html#type-t">Closure_id.t</a> <a href="../Closure_id/Map/index.html#type-t">Closure_id.Map.t</a></span> <span class="arrow">&#45;&gt;</span></span>
<span>dbg:<a href="../Debuginfo/index.html#type-t">Debuginfo.t</a> <span class="arrow">&#45;&gt;</span></span>
<span>simplify:<a href="../Inlining_decision_intf/index.html#type-simplify">Inlining_decision_intf.simplify</a> <span class="arrow">&#45;&gt;</span></span>
<span><span>(<a href="../Flambda/index.html#type-t">Flambda.t</a> * <a href="../Inline_and_simplify_aux/Result/index.html#type-t">Inline_and_simplify_aux.Result.t</a>)</span> option</span></span></code></div><div class="spec-doc"><p>Inlining of recursive function(s) yields a copy of the functions' definitions (not just their bodies, unlike the non-recursive case) and a direct application of the new body. Note: the function really does need to be recursive (but possibly only via some mutual recursion) to end up in here; a simultaneous binding <code>that is
non-recursive</code> is not sufficient.</p></div></div></div></body></html>