rust/src/test/mir-opt
Björn Steinbrink 0473a4f1d8 Avoid unnecessary copies of arguments that are simple bindings
Initially MIR differentiated between arguments and locals, which
introduced a need to add extra copies assigning the argument to a
local, even for simple bindings. This differentiation no longer exists,
but we're still creating those copies, bloating the MIR and LLVM IR we
emit.

Additionally, the current approach means that we create debug info for
both the incoming argument (marking it as an argument), and then
immediately shadow it a local that goes by the same name. This can be
confusing when using e.g. "info args" in gdb, or when e.g. a debugger
with a GUI displays the function arguments separately from the local
variables, especially when the binding is mutable, because the argument
doesn't change, while the local variable does.
2017-10-26 12:54:34 +02:00
..
basic_assignment.rs rustc_mir::transform::simplify - remove nops first 2017-08-01 00:12:31 +03:00
box_expr.rs Update README and tests for new infrastructure 2017-10-09 23:22:34 -04:00
copy_propagation.rs Avoid unnecessary copies of arguments that are simple bindings 2017-10-26 12:54:34 +02:00
deaggregator_test.rs Avoid unnecessary copies of arguments that are simple bindings 2017-10-26 12:54:34 +02:00
deaggregator_test_enum.rs Avoid unnecessary copies of arguments that are simple bindings 2017-10-26 12:54:34 +02:00
deaggregator_test_enum_2.rs Avoid unnecessary copies of arguments that are simple bindings 2017-10-26 12:54:34 +02:00
deaggregator_test_multiple.rs Avoid unnecessary copies of arguments that are simple bindings 2017-10-26 12:54:34 +02:00
end_region_1.rs Update README and tests for new infrastructure 2017-10-09 23:22:34 -04:00
end_region_2.rs Update README and tests for new infrastructure 2017-10-09 23:22:34 -04:00
end_region_3.rs Update README and tests for new infrastructure 2017-10-09 23:22:34 -04:00
end_region_4.rs Update README and tests for new infrastructure 2017-10-09 23:22:34 -04:00
end_region_5.rs Update README and tests for new infrastructure 2017-10-09 23:22:34 -04:00
end_region_6.rs Update README and tests for new infrastructure 2017-10-09 23:22:34 -04:00
end_region_7.rs Update README and tests for new infrastructure 2017-10-09 23:22:34 -04:00
end_region_8.rs Update README and tests for new infrastructure 2017-10-09 23:22:34 -04:00
end_region_9.rs Update README and tests for new infrastructure 2017-10-09 23:22:34 -04:00
end_region_cyclic.rs Update README and tests for new infrastructure 2017-10-09 23:22:34 -04:00
end_region_destruction_extents_1.rs Test case illustrating some destruction code extent stuff. 2017-09-13 12:55:03 +02:00
issue-38669.rs simplify the MirPass traits and passes dramatically 2017-05-02 14:01:01 -04:00
issue-41110.rs Update README and tests for new infrastructure 2017-10-09 23:22:34 -04:00
issue-41697.rs remove compile-flags 2017-05-15 21:12:40 -04:00
issue-41888.rs move "ADT master drop flag" logic to open_drop_for_adt_contents 2017-05-28 10:43:24 +03:00
issue-43457.rs Update regression test to explicit enable EndRegion emission. 2017-09-05 15:19:55 +02:00
README.md Update README and tests for new infrastructure 2017-10-09 23:22:34 -04:00
return_an_array.rs add mir optimization tests, dump-mir-dir option 2016-07-20 19:41:39 -07:00
simplify_if.rs simplify the MirPass traits and passes dramatically 2017-05-02 14:01:01 -04:00
storage_live_dead_in_statics.rs Update README and tests for new infrastructure 2017-10-09 23:22:34 -04:00
storage_ranges.rs Update README and tests for new infrastructure 2017-10-09 23:22:34 -04:00
validate_1.rs Avoid unnecessary copies of arguments that are simple bindings 2017-10-26 12:54:34 +02:00
validate_2.rs Update README and tests for new infrastructure 2017-10-09 23:22:34 -04:00
validate_3.rs Update README and tests for new infrastructure 2017-10-09 23:22:34 -04:00
validate_4.rs Avoid unnecessary copies of arguments that are simple bindings 2017-10-26 12:54:34 +02:00
validate_5.rs Avoid unnecessary copies of arguments that are simple bindings 2017-10-26 12:54:34 +02:00

This folder contains tests for MIR optimizations.

The test format is:

(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 wil 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).