mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2026-01-22 01:06:41 -05:00
6 lines
15 KiB
HTML
6 lines
15 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Shape (ocaml.Shape)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 3.0.0"/><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">Index</a> » <a href="../index.html">ocaml</a> » Shape</nav><header class="odoc-preamble"><h1>Module <code><span>Shape</span></code></h1><p>Shapes are an abstract representation of modules' implementations which allow the tracking of definitions through functor applications and other module-level operations.</p><p>The Shape of a compilation unit is elaborated during typing, partially reduced (without loading external shapes) and written to the <code>cmt</code> file.</p><p>External tools can retrieve the definition of any value (or type, or module, etc) by following this procedure:</p><ul><li>Build the Shape corresponding to the value's path: <code>let shape = Env.shape_of_path ~namespace env path</code></li></ul><ul><li>Instantiate the <code>Shape_reduce.Make</code> functor with a way to load shapes from external units and to looks for shapes in the environment (usually using <code>Env.shape_of_path</code>).</li></ul><ul><li>Completely reduce the shape: <code>let shape = My_reduce.(weak_)reduce env shape</code></li></ul><ul><li>The <code>Uid.t</code> stored in the reduced shape should be the one of the definition. However, if the <code>approximate</code> field of the reduced shape is <code>true</code> then the <code>Uid.t</code> will not correspond to the definition, but to the closest parent module's uid. This happens when Shape reduction gets stuck, for example when hitting first-class modules.</li></ul><ul><li>The location of the definition can be easily found with the <code>cmt_format.cmt_uid_to_decl</code> table of the corresponding compilation unit.</li></ul><p>See:</p><ul><li><a href="https://icfp22.sigplan.org/details/mlfamilyworkshop-2022-papers/10/Module-Shapes-for-Modern-Tooling">the design document</a></li><li><a href="https://www.lix.polytechnique.fr/Labo/Gabriel.Scherer/research/shapes/2022-ml-workshop-shapes-talk.pdf">a talk about the reduction strategy </a></li></ul></header><div class="odoc-content"><div class="odoc-spec"><div class="spec module anchored" id="module-Uid"><a href="#module-Uid" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Uid/index.html">Uid</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>A <code>Uid.t</code> is associated to every declaration in signatures and implementations. They uniquely identify bindings in the program. When associated with these bindings' locations they are useful to external tools when trying to jump to an identifier's declaration or definition. They are stored to that effect in the <code>uid_to_decl</code> table of cmt files.</p></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-Sig_component_kind"><a href="#module-Sig_component_kind" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Sig_component_kind/index.html">Sig_component_kind</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-Item"><a href="#module-Item" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Item/index.html">Item</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>Shape's items are elements of a structure or, in the case of constructors and labels, elements of a record or variants definition seen as a structure. These structures model module components and nested types' constructors and labels.</p></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-var"><a href="#type-var" class="anchor"></a><code><span><span class="keyword">type</span> var</span><span> = <a href="../Ident/index.html#type-t">Ident.t</a></span></code></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-t"><a href="#type-t" class="anchor"></a><code><span><span class="keyword">type</span> t</span><span> = </span><span>{</span></code><ol><li id="type-t.uid" class="def record field anchored"><a href="#type-t.uid" class="anchor"></a><code><span>uid : <span><a href="Uid/index.html#type-t">Uid.t</a> option</span>;</span></code></li><li id="type-t.desc" class="def record field anchored"><a href="#type-t.desc" class="anchor"></a><code><span>desc : <a href="#type-desc">desc</a>;</span></code></li><li id="type-t.approximated" class="def record field anchored"><a href="#type-t.approximated" class="anchor"></a><code><span>approximated : bool;</span></code></li></ol><code><span>}</span></code></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-desc"><a href="#type-desc" class="anchor"></a><code><span><span class="keyword">and</span> desc</span><span> = </span></code><ol><li id="type-desc.Var" class="def variant constructor anchored"><a href="#type-desc.Var" class="anchor"></a><code><span>| </span><span><span class="constructor">Var</span> <span class="keyword">of</span> <a href="#type-var">var</a></span></code></li><li id="type-desc.Abs" class="def variant constructor anchored"><a href="#type-desc.Abs" class="anchor"></a><code><span>| </span><span><span class="constructor">Abs</span> <span class="keyword">of</span> <a href="#type-var">var</a> * <a href="#type-t">t</a></span></code></li><li id="type-desc.App" class="def variant constructor anchored"><a href="#type-desc.App" class="anchor"></a><code><span>| </span><span><span class="constructor">App</span> <span class="keyword">of</span> <a href="#type-t">t</a> * <a href="#type-t">t</a></span></code></li><li id="type-desc.Struct" class="def variant constructor anchored"><a href="#type-desc.Struct" class="anchor"></a><code><span>| </span><span><span class="constructor">Struct</span> <span class="keyword">of</span> <span><a href="#type-t">t</a> <a href="Item/Map/index.html#type-t">Item.Map.t</a></span></span></code></li><li id="type-desc.Alias" class="def variant constructor anchored"><a href="#type-desc.Alias" class="anchor"></a><code><span>| </span><span><span class="constructor">Alias</span> <span class="keyword">of</span> <a href="#type-t">t</a></span></code></li><li id="type-desc.Leaf" class="def variant constructor anchored"><a href="#type-desc.Leaf" class="anchor"></a><code><span>| </span><span><span class="constructor">Leaf</span></span></code></li><li id="type-desc.Proj" class="def variant constructor anchored"><a href="#type-desc.Proj" class="anchor"></a><code><span>| </span><span><span class="constructor">Proj</span> <span class="keyword">of</span> <a href="#type-t">t</a> * <a href="Item/index.html#type-t">Item.t</a></span></code></li><li id="type-desc.Comp_unit" class="def variant constructor anchored"><a href="#type-desc.Comp_unit" class="anchor"></a><code><span>| </span><span><span class="constructor">Comp_unit</span> <span class="keyword">of</span> string</span></code></li><li id="type-desc.Error" class="def variant constructor anchored"><a href="#type-desc.Error" class="anchor"></a><code><span>| </span><span><span class="constructor">Error</span> <span class="keyword">of</span> string</span></code></li></ol></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-print"><a href="#val-print" class="anchor"></a><code><span><span class="keyword">val</span> print : <span><a href="../Stdlib/Format/index.html#type-formatter">Stdlib.Format.formatter</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> unit</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-strip_head_aliases"><a href="#val-strip_head_aliases" class="anchor"></a><code><span><span class="keyword">val</span> strip_head_aliases : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-for_unnamed_functor_param"><a href="#val-for_unnamed_functor_param" class="anchor"></a><code><span><span class="keyword">val</span> for_unnamed_functor_param : <a href="#type-var">var</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-fresh_var"><a href="#val-fresh_var" class="anchor"></a><code><span><span class="keyword">val</span> fresh_var : <span><span class="optlabel">?name</span>:string <span class="arrow">-></span></span> <span><a href="Uid/index.html#type-t">Uid.t</a> <span class="arrow">-></span></span> <a href="#type-var">var</a> * <a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-var"><a href="#val-var" class="anchor"></a><code><span><span class="keyword">val</span> var : <span><a href="Uid/index.html#type-t">Uid.t</a> <span class="arrow">-></span></span> <span><a href="../Ident/index.html#type-t">Ident.t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-abs"><a href="#val-abs" class="anchor"></a><code><span><span class="keyword">val</span> abs : <span><span class="optlabel">?uid</span>:<a href="Uid/index.html#type-t">Uid.t</a> <span class="arrow">-></span></span> <span><a href="#type-var">var</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-app"><a href="#val-app" class="anchor"></a><code><span><span class="keyword">val</span> app : <span><span class="optlabel">?uid</span>:<a href="Uid/index.html#type-t">Uid.t</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><span class="label">arg</span>:<a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-str"><a href="#val-str" class="anchor"></a><code><span><span class="keyword">val</span> str : <span><span class="optlabel">?uid</span>:<a href="Uid/index.html#type-t">Uid.t</a> <span class="arrow">-></span></span> <span><span><a href="#type-t">t</a> <a href="Item/Map/index.html#type-t">Item.Map.t</a></span> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-alias"><a href="#val-alias" class="anchor"></a><code><span><span class="keyword">val</span> alias : <span><span class="optlabel">?uid</span>:<a href="Uid/index.html#type-t">Uid.t</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-proj"><a href="#val-proj" class="anchor"></a><code><span><span class="keyword">val</span> proj : <span><span class="optlabel">?uid</span>:<a href="Uid/index.html#type-t">Uid.t</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><a href="Item/index.html#type-t">Item.t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-leaf"><a href="#val-leaf" class="anchor"></a><code><span><span class="keyword">val</span> leaf : <span><a href="Uid/index.html#type-t">Uid.t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-decompose_abs"><a href="#val-decompose_abs" class="anchor"></a><code><span><span class="keyword">val</span> decompose_abs : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><span>(<a href="#type-var">var</a> * <a href="#type-t">t</a>)</span> option</span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-for_persistent_unit"><a href="#val-for_persistent_unit" class="anchor"></a><code><span><span class="keyword">val</span> for_persistent_unit : <span>string <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-leaf_for_unpack"><a href="#val-leaf_for_unpack" class="anchor"></a><code><span><span class="keyword">val</span> leaf_for_unpack : <a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-Map"><a href="#module-Map" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Map/index.html">Map</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-dummy_mod"><a href="#val-dummy_mod" class="anchor"></a><code><span><span class="keyword">val</span> dummy_mod : <a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_path"><a href="#val-of_path" class="anchor"></a><code><span><span class="keyword">val</span> of_path :
|
||
<span><span class="label">find_shape</span>:<span>(<span><a href="Sig_component_kind/index.html#type-t">Sig_component_kind.t</a> <span class="arrow">-></span></span> <span><a href="../Ident/index.html#type-t">Ident.t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a>)</span> <span class="arrow">-></span></span>
|
||
<span><span class="label">namespace</span>:<a href="Sig_component_kind/index.html#type-t">Sig_component_kind.t</a> <span class="arrow">-></span></span>
|
||
<span><a href="../Path/index.html#type-t">Path.t</a> <span class="arrow">-></span></span>
|
||
<a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>This function returns the shape corresponding to a given path. It requires a callback to find shapes in the environment. It is generally more useful to rely directly on the <code>Env.shape_of_path</code> function to get the shape associated with a given path.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-set_uid_if_none"><a href="#val-set_uid_if_none" class="anchor"></a><code><span><span class="keyword">val</span> set_uid_if_none : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><a href="Uid/index.html#type-t">Uid.t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div></div></div></body></html>
|