]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/README.md
Rollup merge of #44378 - frehberg:rustdoc, r=dtolnay
[rust.git] / src / test / mir-opt / README.md
1 This folder contains tests for MIR optimizations.
2
3 The test format is:
4
5 ```
6 (arbitrary rust code)
7 // END RUST SOURCE
8 // START $file_name_of_some_mir_dump_0
9 //  $expected_line_0
10 // ...
11 // $expected_line_N
12 // END $file_name_of_some_mir_dump_0
13 // ...
14 // START $file_name_of_some_mir_dump_N
15 //  $expected_line_0
16 // ...
17 // $expected_line_N
18 // END $file_name_of_some_mir_dump_N
19 ```
20
21 All the test information is in comments so the test is runnable.
22
23 For each $file_name, compiletest expects [$expected_line_0, ...,
24 $expected_line_N] to appear in the dumped MIR in order.  Currently it allows
25 other non-matched lines before, after and in-between. Note that this includes
26 lines that end basic blocks or begin new ones; it is good practice
27 in your tests to include the terminator for each of your basic blocks as an
28 internal sanity check guarding against a test like:
29
30 ```
31 bb0: {
32     StorageLive(_1);
33     _1 = const true;
34     StorageDead(_1);
35 }
36 ```
37
38 that will inadvertantly pattern-matching against:
39
40 ```
41 bb0: {
42     StorageLive(_1);
43     _1 = const true;
44     goto -> bb1
45 }
46 bb1: {
47     StorageDead(_1);
48     return;
49 }
50 ```
51
52 Lines match ignoring whitespace, and the prefix "//" is removed.
53
54 It also currently strips trailing comments -- partly because the full file path
55 in "scope comments" is unpredictable and partly because tidy complains about
56 the lines being too long.
57
58 compiletest handles dumping the MIR before and after every pass for you.  The
59 test writer only has to specify the file names of the dumped files (not the
60 full path to the file) and what lines to expect.  There is an option to rustc
61 that tells it to dump the mir into some directly (rather then always dumping to
62 the current directory).