]> git.proxmox.com Git - rustc.git/blame - src/test/mir-opt/README.md
New upstream version 1.23.0+dfsg1
[rustc.git] / src / test / mir-opt / README.md
CommitLineData
5bcae85e
SL
1This folder contains tests for MIR optimizations.
2
3The 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
abe05a73 10// (lines or elision)
5bcae85e
SL
11// $expected_line_N
12// END $file_name_of_some_mir_dump_0
abe05a73 13// (lines or elision)
5bcae85e
SL
14// START $file_name_of_some_mir_dump_N
15// $expected_line_0
abe05a73 16// (lines or elision)
5bcae85e
SL
17// $expected_line_N
18// END $file_name_of_some_mir_dump_N
19```
20
21All the test information is in comments so the test is runnable.
22
23For each $file_name, compiletest expects [$expected_line_0, ...,
24$expected_line_N] to appear in the dumped MIR in order. Currently it allows
abe05a73
XL
25other non-matched lines before and after, but not between $expected_lines,
26should you want to skip lines, you must include an elision comment, of the form
27(as a regex) `//\s*...\s*`. The lines will be skipped lazily, that is, if there
28are two identical lines in the output that match the line after the elision
29comment, the first one wil be matched.
30
31Examples:
32
33The following blocks will not match the one after it.
041b39d2
XL
34
35```
36bb0: {
37 StorageLive(_1);
38 _1 = const true;
39 StorageDead(_1);
40}
41```
42
041b39d2
XL
43```
44bb0: {
45 StorageLive(_1);
46 _1 = const true;
47 goto -> bb1
48}
49bb1: {
50 StorageDead(_1);
51 return;
52}
53```
5bcae85e 54
abe05a73
XL
55But this will match the one above,
56
57```
58bb0: {
59 StorageLive(_1);
60 _1 = const true;
61 ...
62 StorageDead(_1);
63 ...
64}
65```
66
5bcae85e
SL
67Lines match ignoring whitespace, and the prefix "//" is removed.
68
69It also currently strips trailing comments -- partly because the full file path
70in "scope comments" is unpredictable and partly because tidy complains about
71the lines being too long.
72
73compiletest handles dumping the MIR before and after every pass for you. The
74test writer only has to specify the file names of the dumped files (not the
3b2f2976 75full path to the file) and what lines to expect. There is an option to rustc
5bcae85e 76that tells it to dump the mir into some directly (rather then always dumping to
3b2f2976 77the current directory).