• Home
Name Date Size #Lines LOC

..--

README.mdD22-Oct-20252.5 KiB5444

def-inits-1.rsD22-Oct-20251.2 KiB5229

def-inits-1.stderrD22-Oct-2025560 2922

inits-1.rsD22-Oct-20251.2 KiB5429

inits-1.stderrD22-Oct-2025431 2317

liveness-enum.rsD22-Oct-2025426 2312

liveness-enum.stderrD22-Oct-2025205 117

liveness-projection.rsD22-Oct-2025764 3321

liveness-projection.stderrD22-Oct-2025394 1712

liveness-ptr.rsD22-Oct-2025520 2916

liveness-ptr.stderrD22-Oct-2025204 117

uninits-1.rsD22-Oct-20251.2 KiB5229

uninits-1.stderrD22-Oct-2025667 3527

uninits-2.rsD22-Oct-2025554 2514

uninits-2.stderrD22-Oct-2025203 117

README.md

1This directory contains unit tests for the MIR-based dataflow
2analysis.
3
4These unit tests check the dataflow analysis by embedding calls to a
5special `rustc_peek` intrinsic within the code, in tandem with an
6attribute `#[rustc_mir(rustc_peek_maybe_init)]` (\*). With that
7attribute in place, `rustc_peek` calls are a signal to the compiler to
8lookup the computed dataflow state for the Lvalue corresponding to the
9argument expression being fed to `rustc_peek`. If the dataflow state
10for that Lvalue is a 1-bit at that point in the control flow, then no
11error is emitted by the compiler at that point; if it is a 0-bit, then
12that invocation of `rustc_peek` will emit an error with the message
13"rustc_peek: bit not set".
14
15(\*): Or `#[rustc_mir(rustc_peek_maybe_uninit)]`, and perhaps other
16variants in the future.
17
18The end effect is that one can write unit tests for MIR dataflow that
19perform simple-queries of the computed dataflow state, and the tests
20should be able to be robust in the face of changes to how MIR is
21represented or constructed.
22
23----
24
25Sometimes understanding the dataflow results is difficult without
26looking at the actual MIR control-flow graph being processed with the
27corresponding GEN and KILL sets.
28
29For a graphviz-rendering with dataflow annotations, add the attribute
30`#[rustc_mir(borrowck_graphviz_postflow="/path/to/suffix.dot")]` to
31the function in question. (You can change the content of
32`"suffix.dot"` to control the filenames used for the output). This
33will generate a separate file for each dataflow analysis, adding a
34prefix (corresponding to the name of the analysis) to the filename in
35each generated output path.
36
37 * For example, the above attribute will currently cause two files to
38   be generated: `/path/to/maybe_init_suffix.dot` and
39   `/path/to/maybe_uninit_suffix.dot`.
40
41 * The generated `.dot` file shows both the computed dataflow results
42   on *entry* to each block, as well as the gen- and kill-sets that
43   were so-called "transfer functions" summarizing the effect of each
44   basic block.
45
46 * (In addition to the `borrowck_graphviz_postflow` attribute-key
47   noted above, there is also `borrowck_graphviz_preflow`; it has the
48   same interface and generates the same set of files, but it renders
49   the dataflow state after building the gen- and kill-sets but
50   *before* running the dataflow analysis itself, so each entry-set is
51   just the initial default state for that dataflow analysis. This is
52   less useful for understanding the error message output in these
53   tests.)
54