]> git.lizzy.rs Git - rust.git/blob - tests/mir-opt/README.md
Rollup merge of #106664 - chenyukang:yukang/fix-106597-remove-lseek, r=cuviper
[rust.git] / tests / mir-opt / README.md
1 This folder contains tests for MIR optimizations.
2
3 The `mir-opt` test format emits MIR to extra files that you can automatically update by specifying
4 `--bless` on the command line (just like `ui` tests updating `.stderr` files).
5
6 # `--bless`able test format
7
8 By default 32 bit and 64 bit targets use the same dump files, which can be problematic in the
9 presence of pointers in constants or other bit width dependent things. In that case you can add
10
11 ```
12 // EMIT_MIR_FOR_EACH_BIT_WIDTH
13 ```
14
15 to your test, causing separate files to be generated for 32bit and 64bit systems.
16
17 ## Unit testing
18
19 If you are only testing the behavior of a particular mir-opt pass on some specific input (as is
20 usually the case), you should add
21
22 ```
23 // unit-test: PassName
24 ```
25
26 to the top of the file. This makes sure that other passes don't run which means you'll get the input
27 you expected and your test won't break when other code changes.
28
29 ## Emit a diff of the mir for a specific optimization
30
31 This is what you want most often when you want to see how an optimization changes the MIR.
32
33 ```
34 // EMIT_MIR $file_name_of_some_mir_dump.diff
35 ```
36
37 ## Emit mir after a specific optimization
38
39 Use this if you are just interested in the final state after an optimization.
40
41 ```
42 // EMIT_MIR $file_name_of_some_mir_dump.after.mir
43 ```
44
45 ## Emit mir before a specific optimization
46
47 This exists mainly for completeness and is rarely useful.
48
49 ```
50 // EMIT_MIR $file_name_of_some_mir_dump.before.mir
51 ```