tiny_httpd/ocaml/Builtin_attributes/index.html
2025-01-30 03:35:54 +00:00

27 lines
20 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>Builtin_attributes (ocaml.Builtin_attributes)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 2.4.4"/><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; Builtin_attributes</nav><header class="odoc-preamble"><h1>Module <code><span>Builtin_attributes</span></code></h1><p>Support for the builtin attributes:</p><ul><li>ocaml.alert</li><li>ocaml.boxed</li><li>ocaml.deprecated</li><li>ocaml.deprecated_mutable</li><li>ocaml.explicit_arity</li><li>ocaml.immediate</li><li>ocaml.immediate64</li><li>ocaml.inline</li><li>ocaml.inlined</li><li>ocaml.noalloc</li><li>ocaml.poll</li><li>ocaml.ppwarning</li><li>ocaml.specialise</li><li>ocaml.specialised</li><li>ocaml.tailcall</li><li>ocaml.tail_mod_cons</li><li>ocaml.unboxed</li><li>ocaml.untagged</li><li>ocaml.unrolled</li><li>ocaml.warnerror</li><li>ocaml.warning</li><li>ocaml.warn_on_literal_pattern</li></ul><p><b>Warning:</b> this module is unstable and part of <span class="xref-unresolved" title="Compiler_libs">compiler-libs</span>.</p></header><nav class="odoc-toc"><ul><li><a href="#attribute-tracking-for-warning-53">Attribute tracking for warning 53</a><ul><li><a href="#warning-53-helpers-for-environment-attributes">Warning 53 helpers for environment attributes</a></li></ul></li><li><a href="#helpers-for-alert-and-warning-attributes">Helpers for alert and warning attributes</a></li><li><a href="#helpers-for-searching-for-particular-attributes">Helpers for searching for particular attributes</a></li></ul></nav><div class="odoc-content"><h3 id="attribute-tracking-for-warning-53"><a href="#attribute-tracking-for-warning-53" class="anchor"></a>Attribute tracking for warning 53</h3><div class="odoc-spec"><div class="spec type anchored" id="type-current_phase"><a href="#type-current_phase" class="anchor"></a><code><span><span class="keyword">type</span> current_phase</span><span> = </span></code><ol><li id="type-current_phase.Parser" class="def variant constructor anchored"><a href="#type-current_phase.Parser" class="anchor"></a><code><span>| </span><span><span class="constructor">Parser</span></span></code></li><li id="type-current_phase.Invariant_check" class="def variant constructor anchored"><a href="#type-current_phase.Invariant_check" class="anchor"></a><code><span>| </span><span><span class="constructor">Invariant_check</span></span></code></li></ol></div><div class="spec-doc"><p><code>register_attr</code> must be called on the locations of all attributes that should be tracked for the purpose of misplaced attribute warnings. In particular, it should be called on all attributes that are present in the source program except those that are contained in the payload of another attribute (because these may be left behind by a ppx and intentionally ignored by the compiler).</p><p>The <code>current_phase</code> argument indicates when this function is being called</p><ul><li>either when an attribute is created in the parser or when we see an attribute while running the check in the <code>Ast_invariants</code> module. This is used to ensure that we track only attributes from the final version of the parse tree: we skip adding attributes seen at parse time if we can see that a ppx will be run later, because the <code>Ast_invariants</code> check is always run on the result of a ppx.</li></ul><p>Note that the <code>Ast_invariants</code> check is also run on parse trees created from marshalled ast files if no ppx is being used, ensuring we don't miss attributes in that case.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-register_attr"><a href="#val-register_attr" class="anchor"></a><code><span><span class="keyword">val</span> register_attr : <span><a href="#type-current_phase">current_phase</a> <span class="arrow">&#45;&gt;</span></span> <span><span>string <a href="../Location/index.html#type-loc">Location.loc</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-mark_payload_attrs_used"><a href="#val-mark_payload_attrs_used" class="anchor"></a><code><span><span class="keyword">val</span> mark_payload_attrs_used : <span><a href="../Parsetree/index.html#type-payload">Parsetree.payload</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Marks the attributes hiding in the payload of another attribute used, for the purposes of misplaced attribute warnings (see comment on <code>current_phase</code> above). In the parser, it's simplest to add these to the table and remove them later, rather than threading through state tracking whether we're in an attribute payload.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-warn_unused"><a href="#val-warn_unused" class="anchor"></a><code><span><span class="keyword">val</span> warn_unused : <span>unit <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Issue misplaced attribute warnings for all attributes created with <code>mk_internal</code> but not yet marked used. Does nothing if compilation is stopped before lambda due to command-line flags.</p></div></div><h4 id="warning-53-helpers-for-environment-attributes"><a href="#warning-53-helpers-for-environment-attributes" class="anchor"></a>Warning 53 helpers for environment attributes</h4><p>Some attributes, like deprecation markers, do not affect the compilation of the definition on which they appear, but rather result in warnings on future uses of that definition. This is implemented by moving the raw attributes into the environment, where they will be noticed on future accesses.</p><p>To make misplaced attribute warnings work appropriately for these attributes, we mark them &quot;used&quot; when they are moved into the environment. This is done with the helper functions in this section.</p><div class="odoc-spec"><div class="spec value anchored" id="val-mark_alert_used"><a href="#val-mark_alert_used" class="anchor"></a><code><span><span class="keyword">val</span> mark_alert_used : <span><a href="../Parsetree/index.html#type-attribute">Parsetree.attribute</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Marks the attribute used for the purposes of misplaced attribute warnings if it is an alert. Call this when moving things allowed to have alert attributes into the environment.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-mark_alerts_used"><a href="#val-mark_alerts_used" class="anchor"></a><code><span><span class="keyword">val</span> mark_alerts_used : <span><a href="../Parsetree/index.html#type-attributes">Parsetree.attributes</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>The same as <code>List.iter mark_alert_used</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-mark_warn_on_literal_pattern_used"><a href="#val-mark_warn_on_literal_pattern_used" class="anchor"></a><code><span><span class="keyword">val</span> mark_warn_on_literal_pattern_used : <span><a href="../Parsetree/index.html#type-attributes">Parsetree.attributes</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Marks &quot;warn_on_literal_pattern&quot; attributes used for the purposes of misplaced attribute warnings. Call this when moving constructors into the environment.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-mark_deprecated_mutable_used"><a href="#val-mark_deprecated_mutable_used" class="anchor"></a><code><span><span class="keyword">val</span> mark_deprecated_mutable_used : <span><a href="../Parsetree/index.html#type-attributes">Parsetree.attributes</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Marks &quot;deprecated_mutable&quot; attributes used for the purposes of misplaced attribute warnings. Call this when moving labels of mutable fields into the environment.</p></div></div><h3 id="helpers-for-alert-and-warning-attributes"><a href="#helpers-for-alert-and-warning-attributes" class="anchor"></a>Helpers for alert and warning attributes</h3><div class="odoc-spec"><div class="spec value anchored" id="val-check_alerts"><a href="#val-check_alerts" class="anchor"></a><code><span><span class="keyword">val</span> check_alerts : <span><a href="../Location/index.html#type-t">Location.t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Parsetree/index.html#type-attributes">Parsetree.attributes</a> <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> unit</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-check_alerts_inclusion"><a href="#val-check_alerts_inclusion" class="anchor"></a><code><span><span class="keyword">val</span> check_alerts_inclusion :
<span><span class="label">def</span>:<a href="../Location/index.html#type-t">Location.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><span class="label">use</span>:<a href="../Location/index.html#type-t">Location.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../Location/index.html#type-t">Location.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../Parsetree/index.html#type-attributes">Parsetree.attributes</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../Parsetree/index.html#type-attributes">Parsetree.attributes</a> <span class="arrow">&#45;&gt;</span></span>
<span>string <span class="arrow">&#45;&gt;</span></span>
unit</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-alerts_of_attrs"><a href="#val-alerts_of_attrs" class="anchor"></a><code><span><span class="keyword">val</span> alerts_of_attrs : <span><a href="../Parsetree/index.html#type-attributes">Parsetree.attributes</a> <span class="arrow">&#45;&gt;</span></span> <a href="../Misc/index.html#type-alerts">Misc.alerts</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-alerts_of_sig"><a href="#val-alerts_of_sig" class="anchor"></a><code><span><span class="keyword">val</span> alerts_of_sig : <span><span class="label">mark</span>:bool <span class="arrow">&#45;&gt;</span></span> <span><a href="../Parsetree/index.html#type-signature">Parsetree.signature</a> <span class="arrow">&#45;&gt;</span></span> <a href="../Misc/index.html#type-alerts">Misc.alerts</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-alerts_of_str"><a href="#val-alerts_of_str" class="anchor"></a><code><span><span class="keyword">val</span> alerts_of_str : <span><span class="label">mark</span>:bool <span class="arrow">&#45;&gt;</span></span> <span><a href="../Parsetree/index.html#type-structure">Parsetree.structure</a> <span class="arrow">&#45;&gt;</span></span> <a href="../Misc/index.html#type-alerts">Misc.alerts</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-check_deprecated_mutable"><a href="#val-check_deprecated_mutable" class="anchor"></a><code><span><span class="keyword">val</span> check_deprecated_mutable :
<span><a href="../Location/index.html#type-t">Location.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../Parsetree/index.html#type-attributes">Parsetree.attributes</a> <span class="arrow">&#45;&gt;</span></span>
<span>string <span class="arrow">&#45;&gt;</span></span>
unit</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-check_deprecated_mutable_inclusion"><a href="#val-check_deprecated_mutable_inclusion" class="anchor"></a><code><span><span class="keyword">val</span> check_deprecated_mutable_inclusion :
<span><span class="label">def</span>:<a href="../Location/index.html#type-t">Location.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><span class="label">use</span>:<a href="../Location/index.html#type-t">Location.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../Location/index.html#type-t">Location.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../Parsetree/index.html#type-attributes">Parsetree.attributes</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../Parsetree/index.html#type-attributes">Parsetree.attributes</a> <span class="arrow">&#45;&gt;</span></span>
<span>string <span class="arrow">&#45;&gt;</span></span>
unit</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-error_of_extension"><a href="#val-error_of_extension" class="anchor"></a><code><span><span class="keyword">val</span> error_of_extension : <span><a href="../Parsetree/index.html#type-extension">Parsetree.extension</a> <span class="arrow">&#45;&gt;</span></span> <a href="../Location/index.html#type-error">Location.error</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-warning_attribute"><a href="#val-warning_attribute" class="anchor"></a><code><span><span class="keyword">val</span> warning_attribute : <span><span class="optlabel">?ppwarning</span>:bool <span class="arrow">&#45;&gt;</span></span> <span><a href="../Parsetree/index.html#type-attribute">Parsetree.attribute</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Apply warning settings from the specified attribute. &quot;ocaml.warning&quot;/&quot;ocaml.warnerror&quot; (and variants without the prefix) are processed and marked used for warning 53. Other attributes are ignored.</p><p>Also implement ocaml.ppwarning (unless ~ppwarning:false is passed).</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-warning_scope"><a href="#val-warning_scope" class="anchor"></a><code><span><span class="keyword">val</span> warning_scope :
<span><span class="optlabel">?ppwarning</span>:bool <span class="arrow">&#45;&gt;</span></span>
<span><a href="../Parsetree/index.html#type-attributes">Parsetree.attributes</a> <span class="arrow">&#45;&gt;</span></span>
<span><span>(<span>unit <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'a</span>)</span> <span class="arrow">&#45;&gt;</span></span>
<span class="type-var">'a</span></span></code></div><div class="spec-doc"><p>Execute a function in a new scope for warning settings. This means that the effect of any call to <code>warning_attribute</code> during the execution of this function will be discarded after execution.</p><p>The function also takes a list of attributes which are processed with <code>warning_attribute</code> in the fresh scope before the function is executed.</p></div></div><h3 id="helpers-for-searching-for-particular-attributes"><a href="#helpers-for-searching-for-particular-attributes" class="anchor"></a>Helpers for searching for particular attributes</h3><div class="odoc-spec"><div class="spec value anchored" id="val-has_attribute"><a href="#val-has_attribute" class="anchor"></a><code><span><span class="keyword">val</span> has_attribute : <span>string <span class="arrow">&#45;&gt;</span></span> <span><a href="../Parsetree/index.html#type-attributes">Parsetree.attributes</a> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>has_attribute name attrs</code> is true if an attribute with name <code>name</code> or <code>&quot;ocaml.&quot; ^ name</code> is present in <code>attrs</code>. It marks that attribute used for the purposes of misplaced attribute warnings.</p></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-attr_action"><a href="#type-attr_action" class="anchor"></a><code><span><span class="keyword">type</span> attr_action</span><span> = </span></code><ol><li id="type-attr_action.Mark_used_only" class="def variant constructor anchored"><a href="#type-attr_action.Mark_used_only" class="anchor"></a><code><span>| </span><span><span class="constructor">Mark_used_only</span></span></code></li><li id="type-attr_action.Return" class="def variant constructor anchored"><a href="#type-attr_action.Return" class="anchor"></a><code><span>| </span><span><span class="constructor">Return</span></span></code></li></ol></div><div class="spec-doc"><p><code>select_attributes actions attrs</code> finds the elements of <code>attrs</code> that appear in <code>actions</code> and either returns them or just marks them used, according to the corresponding <code>attr_action</code>.</p><p>Each element <code>(nm, action)</code> of the <code>actions</code> list is an attribute along with an <code>attr_action</code> specifying what to do with that attribute. The action is used to accommodate different compiler configurations. If an attribute is used only in some compiler configurations, it's important that we still look for it and mark it used when compiling with other configurations. Otherwise, we would issue spurious misplaced attribute warnings.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-select_attributes"><a href="#val-select_attributes" class="anchor"></a><code><span><span class="keyword">val</span> select_attributes :
<span><span><span>(string * <a href="#type-attr_action">attr_action</a>)</span> list</span> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../Parsetree/index.html#type-attributes">Parsetree.attributes</a> <span class="arrow">&#45;&gt;</span></span>
<a href="../Parsetree/index.html#type-attributes">Parsetree.attributes</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_equals_builtin"><a href="#val-attr_equals_builtin" class="anchor"></a><code><span><span class="keyword">val</span> attr_equals_builtin : <span><a href="../Parsetree/index.html#type-attribute">Parsetree.attribute</a> <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>attr_equals_builtin attr s</code> is true if the name of the attribute is <code>s</code> or <code>&quot;ocaml.&quot; ^ s</code>. This is useful for manually inspecting attribute names, but note that doing so will not result in marking the attribute used for the purpose of warning 53, so it is usually preferable to use <code>has_attribute</code> or <code>select_attributes</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-warn_on_literal_pattern"><a href="#val-warn_on_literal_pattern" class="anchor"></a><code><span><span class="keyword">val</span> warn_on_literal_pattern : <span><a href="../Parsetree/index.html#type-attributes">Parsetree.attributes</a> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-explicit_arity"><a href="#val-explicit_arity" class="anchor"></a><code><span><span class="keyword">val</span> explicit_arity : <span><a href="../Parsetree/index.html#type-attributes">Parsetree.attributes</a> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-immediate"><a href="#val-immediate" class="anchor"></a><code><span><span class="keyword">val</span> immediate : <span><a href="../Parsetree/index.html#type-attributes">Parsetree.attributes</a> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-immediate64"><a href="#val-immediate64" class="anchor"></a><code><span><span class="keyword">val</span> immediate64 : <span><a href="../Parsetree/index.html#type-attributes">Parsetree.attributes</a> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-has_unboxed"><a href="#val-has_unboxed" class="anchor"></a><code><span><span class="keyword">val</span> has_unboxed : <span><a href="../Parsetree/index.html#type-attributes">Parsetree.attributes</a> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-has_boxed"><a href="#val-has_boxed" class="anchor"></a><code><span><span class="keyword">val</span> has_boxed : <span><a href="../Parsetree/index.html#type-attributes">Parsetree.attributes</a> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div></div></div></body></html>