<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>src/test/ui/mir-dataflow/README.md - fork/rust @ 1.43.1</title>
<meta name="description" content="src/test/ui/mir-dataflow/README.md in fork/rust at 1.43.1.">
<meta property="og:title" content="src/test/ui/mir-dataflow/README.md - fork/rust @ 1.43.1">
<meta property="og:description" content="src/test/ui/mir-dataflow/README.md in fork/rust at 1.43.1.">
<meta property="og:type" content="website">
<meta property="og:site_name" content="git.julia.blue">
<link rel="stylesheet" href="/css/style.css?v=62">
<script type="module" src="/js/main.js?v=62"></script>
</head>
<body>
<main data-ref="1.43.1" data-tip="8d69840ab92ea7f4d323420088dd8c9775f180cd">
<noscript>
  <div class="callout">
    <p>
      hey! this is a static git repo viewer. commit diffs, file history,
      older commits and other revisions won't load without javascript.
    </p>
    <p>
      you are still able to view source files on branch/tag tips,
      but the experience is degraded.
    </p>
  </div>
</noscript>
<header class="repo"><div>
<h1>fork/rust</h1>
</div>
<pre class="clone">git clone https://git.julia.blue/fork/rust</pre>
</header>
<p class="snapshot-commit"><span class="commit-author">bors</span><span class="commit-message" data-commit="8d69840ab92ea7f4d323420088dd8c9775f180cd">Auto merge of #71868 - Mark-Simulacrum:stable-1.43.1, r=pietroalbini</span><span class="snapshot-sha sha" data-commit="8d69840ab92ea7f4d323420088dd8c9775f180cd">8d69840ab92</span><time datetime="2020-05-04T23:45:41+00:00" title="2020-05-04 23:45:41 +0000">2020-05-04</time></p>
<header class="topbar"><details class="switcher"><summary>1.43.1</summary><div class="menu"><strong>branches</strong><a href="/fork/rust/ref/master/">master</a><strong>tags</strong><a href="/fork/rust/ref/1.39.0/">1.39.0</a><a href="/fork/rust/ref/1.40.0/">1.40.0</a><a href="/fork/rust/ref/1.41.0/">1.41.0</a><a href="/fork/rust/ref/1.41.1/">1.41.1</a><a href="/fork/rust/ref/1.42.0/">1.42.0</a><a href="/fork/rust/ref/1.43.0/">1.43.0</a><a class="current" href="/fork/rust/ref/1.43.1/">1.43.1</a><a href="/fork/rust/ref/1.44.0/">1.44.0</a><a class="all" href="/fork/rust/refs">all refs →</a></div></details><nav class="crumbs"><a href="/fork/rust/">rust</a> / <a href="/fork/rust/ref/1.43.1/tree/src/">src</a> / <a href="/fork/rust/ref/1.43.1/tree/src/test/">test</a> / <a href="/fork/rust/ref/1.43.1/tree/src/test/ui/">ui</a> / <a href="/fork/rust/ref/1.43.1/tree/src/test/ui/mir-dataflow/">mir-dataflow</a> / <span class="cur">README.md</span></nav>
<span class="view-stats"><span>2.5 KiB</span><span>53 lines</span></span><span class="actions"><a class="raw" href="/fork/rust/raw/a3ab14b23c7db69edafc5652b919dcb298c77063/src/test/ui/mir-dataflow/README.md">raw</a></span></header>
<div class="markdown-view"><input type="radio" name="markdown-view" id="markdown-rendered" checked><label for="markdown-rendered">rendered</label><input type="radio" name="markdown-view" id="markdown-code"><label for="markdown-code">code</label><section class="readme rendered"><p>This directory contains unit tests for the MIR-based dataflow
analysis.</p>
<p>These unit tests check the dataflow analysis by embedding calls to a
special <code>rustc_peek</code> intrinsic within the code, in tandem with an
attribute <code>#[rustc_mir(rustc_peek_maybe_init)]</code> (*). With that
attribute in place, <code>rustc_peek</code> calls are a signal to the compiler to
lookup the computed dataflow state for the Lvalue corresponding to the
argument expression being fed to <code>rustc_peek</code>. If the dataflow state
for that Lvalue is a 1-bit at that point in the control flow, then no
error is emitted by the compiler at that point; if it is a 0-bit, then
that invocation of <code>rustc_peek</code> will emit an error with the message
"rustc_peek: bit not set".</p>
<p>(*): Or <code>#[rustc_mir(rustc_peek_maybe_uninit)]</code>, and perhaps other
variants in the future.</p>
<p>The end effect is that one can write unit tests for MIR dataflow that
perform simple-queries of the computed dataflow state, and the tests
should be able to be robust in the face of changes to how MIR is
represented or constructed.</p>
<hr />
<p>Sometimes understanding the dataflow results is difficult without
looking at the actual MIR control-flow graph being processed with the
corresponding GEN and KILL sets.</p>
<p>For a graphviz-rendering with dataflow annotations, add the attribute
<code>#[rustc_mir(borrowck_graphviz_postflow="/path/to/suffix.dot")]</code> to
the function in question. (You can change the content of
<code>"suffix.dot"</code> to control the filenames used for the output). This
will generate a separate file for each dataflow analysis, adding a
prefix (corresponding to the name of the analysis) to the filename in
each generated output path.</p>
<ul>
<li>
<p>For example, the above attribute will currently cause two files to
be generated: <code>/path/to/maybe_init_suffix.dot</code> and
<code>/path/to/maybe_uninit_suffix.dot</code>.</p>
</li>
<li>
<p>The generated <code>.dot</code> file shows both the computed dataflow results
on <em>entry</em> to each block, as well as the gen- and kill-sets that
were so-called "transfer functions" summarizing the effect of each
basic block.</p>
</li>
<li>
<p>(In addition to the <code>borrowck_graphviz_postflow</code> attribute-key
noted above, there is also <code>borrowck_graphviz_preflow</code>; it has the
same interface and generates the same set of files, but it renders
the dataflow state after building the gen- and kill-sets but
<em>before</em> running the dataflow analysis itself, so each entry-set is
just the initial default state for that dataflow analysis. This is
less useful for understanding the error message output in these
tests.)</p>
</li>
</ul>
</section><div class="code-panel"><pre class="code src" data-hl="src/test/ui/mir-dataflow/README.md"><span class="code-line"><a class="ln" id="L1" href="#L1">1</a><span class="code-text">This directory contains unit tests for the MIR-based dataflow</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L2" href="#L2">2</a><span class="code-text">analysis.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L3" href="#L3">3</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L4" href="#L4">4</a><span class="code-text">These unit tests check the dataflow analysis by embedding calls to a</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L5" href="#L5">5</a><span class="code-text">special `rustc_peek` intrinsic within the code, in tandem with an</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L6" href="#L6">6</a><span class="code-text">attribute `#[rustc_mir(rustc_peek_maybe_init)]` (\*). With that</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L7" href="#L7">7</a><span class="code-text">attribute in place, `rustc_peek` calls are a signal to the compiler to</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L8" href="#L8">8</a><span class="code-text">lookup the computed dataflow state for the Lvalue corresponding to the</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L9" href="#L9">9</a><span class="code-text">argument expression being fed to `rustc_peek`. If the dataflow state</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L10" href="#L10">10</a><span class="code-text">for that Lvalue is a 1-bit at that point in the control flow, then no</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L11" href="#L11">11</a><span class="code-text">error is emitted by the compiler at that point; if it is a 0-bit, then</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L12" href="#L12">12</a><span class="code-text">that invocation of `rustc_peek` will emit an error with the message</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L13" href="#L13">13</a><span class="code-text">&quot;rustc_peek: bit not set&quot;.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L14" href="#L14">14</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L15" href="#L15">15</a><span class="code-text">(\*): Or `#[rustc_mir(rustc_peek_maybe_uninit)]`, and perhaps other</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L16" href="#L16">16</a><span class="code-text">variants in the future.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L17" href="#L17">17</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L18" href="#L18">18</a><span class="code-text">The end effect is that one can write unit tests for MIR dataflow that</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L19" href="#L19">19</a><span class="code-text">perform simple-queries of the computed dataflow state, and the tests</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L20" href="#L20">20</a><span class="code-text">should be able to be robust in the face of changes to how MIR is</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L21" href="#L21">21</a><span class="code-text">represented or constructed.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L22" href="#L22">22</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L23" href="#L23">23</a><span class="code-text">----</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L24" href="#L24">24</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L25" href="#L25">25</a><span class="code-text">Sometimes understanding the dataflow results is difficult without</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L26" href="#L26">26</a><span class="code-text">looking at the actual MIR control-flow graph being processed with the</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L27" href="#L27">27</a><span class="code-text">corresponding GEN and KILL sets.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L28" href="#L28">28</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L29" href="#L29">29</a><span class="code-text">For a graphviz-rendering with dataflow annotations, add the attribute</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L30" href="#L30">30</a><span class="code-text">`#[rustc_mir(borrowck_graphviz_postflow=&quot;/path/to/suffix.dot&quot;)]` to</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L31" href="#L31">31</a><span class="code-text">the function in question. (You can change the content of</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L32" href="#L32">32</a><span class="code-text">`&quot;suffix.dot&quot;` to control the filenames used for the output). This</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L33" href="#L33">33</a><span class="code-text">will generate a separate file for each dataflow analysis, adding a</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L34" href="#L34">34</a><span class="code-text">prefix (corresponding to the name of the analysis) to the filename in</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L35" href="#L35">35</a><span class="code-text">each generated output path.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L36" href="#L36">36</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L37" href="#L37">37</a><span class="code-text"> * For example, the above attribute will currently cause two files to</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L38" href="#L38">38</a><span class="code-text">   be generated: `/path/to/maybe_init_suffix.dot` and</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L39" href="#L39">39</a><span class="code-text">   `/path/to/maybe_uninit_suffix.dot`.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L40" href="#L40">40</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L41" href="#L41">41</a><span class="code-text"> * The generated `.dot` file shows both the computed dataflow results</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L42" href="#L42">42</a><span class="code-text">   on *entry* to each block, as well as the gen- and kill-sets that</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L43" href="#L43">43</a><span class="code-text">   were so-called &quot;transfer functions&quot; summarizing the effect of each</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L44" href="#L44">44</a><span class="code-text">   basic block.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L45" href="#L45">45</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L46" href="#L46">46</a><span class="code-text"> * (In addition to the `borrowck_graphviz_postflow` attribute-key</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L47" href="#L47">47</a><span class="code-text">   noted above, there is also `borrowck_graphviz_preflow`; it has the</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L48" href="#L48">48</a><span class="code-text">   same interface and generates the same set of files, but it renders</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L49" href="#L49">49</a><span class="code-text">   the dataflow state after building the gen- and kill-sets but</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L50" href="#L50">50</a><span class="code-text">   *before* running the dataflow analysis itself, so each entry-set is</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L51" href="#L51">51</a><span class="code-text">   just the initial default state for that dataflow analysis. This is</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L52" href="#L52">52</a><span class="code-text">   less useful for understanding the error message output in these</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L53" href="#L53">53</a><span class="code-text">   tests.)</span></span></pre></div></div>
</main>
</body>
</html>
