tree: d624007790993a58d27e29b82c4999c569aeabed [path history] [tgz]
  1. basic_assignment/
  2. const-promotion-extern-static/
  3. const_allocation/
  4. const_allocation2/
  5. const_allocation3/
  6. const_prop/
  7. inline/
  8. nll/
  9. simplify-locals-removes-unused-discriminant-reads/
  10. address-of.rs
  11. array-index-is-temporary.rs
  12. basic_assignment.rs
  13. box_expr.rs
  14. byte_slice.rs
  15. combine_array_len.rs
  16. const-promotion-extern-static.rs
  17. const_allocation.rs
  18. const_allocation2.rs
  19. const_allocation3.rs
  20. copy_propagation.rs
  21. copy_propagation_arg.rs
  22. deaggregator_test.rs
  23. deaggregator_test_enum.rs
  24. deaggregator_test_enum_2.rs
  25. deaggregator_test_multiple.rs
  26. exponential-or.rs
  27. generator-drop-cleanup.rs
  28. generator-storage-dead-unwind.rs
  29. generator-tiny.rs
  30. graphviz.rs
  31. issue-38669.rs
  32. issue-41110.rs
  33. issue-41697.rs
  34. issue-41888.rs
  35. issue-49232.rs
  36. issue-62289.rs
  37. loop_test.rs
  38. match-arm-scopes.rs
  39. match_false_edges.rs
  40. match_test.rs
  41. no-drop-for-inactive-variant.rs
  42. no-spurious-drop-after-call.rs
  43. packed-struct-drop-aligned.rs
  44. README.md
  45. remove_fake_borrows.rs
  46. retag.rs
  47. retain-never-const.rs
  48. return_an_array.rs
  49. simple-match.rs
  50. simplify-arm-identity.rs
  51. simplify-locals-removes-unused-consts.rs
  52. simplify-locals-removes-unused-discriminant-reads.rs
  53. simplify_cfg.rs
  54. simplify_if.rs
  55. simplify_match.rs
  56. simplify_try.rs
  57. slice-drop-shim.rs
  58. storage_live_dead_in_statics.rs
  59. storage_ranges.rs
  60. uniform_array_move_out.rs
  61. uninhabited-enum.rs
  62. uninhabited_enum_branching.rs
  63. unreachable.rs
  64. unreachable_asm.rs
  65. unreachable_asm_2.rs
  66. unreachable_diverging.rs
  67. unusual-item-types.rs
  68. while-storage.rs
src/test/mir-opt/README.md

This folder contains tests for MIR optimizations.

There are two test formats. One allows specifying a pattern to look for in the MIR, which also permits leaving placeholders, but requires you to manually change the pattern if anything changes. The other emits MIR to extra files that you can automatically update by specifying --bless on the command line (just like ui tests updating .stderr files).

--blessable test format

By default 32 bit and 64 bit targets use the same dump files, which can be problematic in the presence of pointers in constants or other bit width dependent things. In that case you can add

// EMIT_MIR_FOR_EACH_BIT_WIDTH

to your test, causing separate files to be generated for 32bit and 64bit systems.

Emit a diff of the mir for a specific optimization

This is what you want most often when you want to see how an optimization changes the MIR.

// EMIT_MIR $file_name_of_some_mir_dump.diff

Emit mir after a specific optimization

Use this if you are just interested in the final state after an optimization.

// EMIT_MIR $file_name_of_some_mir_dump.after.mir

Emit mir before a specific optimization

This exists mainly for completeness and is rarely useful.

// EMIT_MIR $file_name_of_some_mir_dump.before.mir

Inline test format

(arbitrary rust code)
// END RUST SOURCE
// START $file_name_of_some_mir_dump_0
//  $expected_line_0
// (lines or elision)
// $expected_line_N
// END $file_name_of_some_mir_dump_0
// (lines or elision)
// START $file_name_of_some_mir_dump_N
//  $expected_line_0
// (lines or elision)
// $expected_line_N
// END $file_name_of_some_mir_dump_N

All the test information is in comments so the test is runnable.

For each $file_name, compiletest expects [$expected_line_0, ..., $expected_line_N] to appear in the dumped MIR in order. Currently it allows other non-matched lines before and after, but not between $expected_lines, should you want to skip lines, you must include an elision comment, of the form (as a regex) //\s*...\s*. The lines will be skipped lazily, that is, if there are two identical lines in the output that match the line after the elision comment, the first one will be matched.

Examples:

The following blocks will not match the one after it.

bb0: {
    StorageLive(_1);
    _1 = const true;
    StorageDead(_1);
}
bb0: {
    StorageLive(_1);
    _1 = const true;
    goto -> bb1
}
bb1: {
    StorageDead(_1);
    return;
}

But this will match the one above,

bb0: {
    StorageLive(_1);
    _1 = const true;
    ...
    StorageDead(_1);
    ...
}

Lines match ignoring whitespace, and the prefix “//” is removed.

It also currently strips trailing comments -- partly because the full file path in “scope comments” is unpredictable and partly because tidy complains about the lines being too long.

compiletest handles dumping the MIR before and after every pass for you. The test writer only has to specify the file names of the dumped files (not the full path to the file) and what lines to expect. There is an option to rustc that tells it to dump the mir into some directly (rather then always dumping to the current directory).