Description
The mir-opt testing infrastructure (described here) allows us to write tests that do various "string matches" against the MIR output. The idea is that you can add comments at the end of a test file like this one that will specify output that must appear in the "dump-mir" output. This is an example of such a comment.
The basic structure is like this:
// END RUST SOURCE
// START rustc.node4.SimplifyCfg-initial.after.mir
// line0
// line1
// END rustc.node4.SimplifyCfg-initial.after.mir
The test infrastructure will then check that (a) line0
appears in the given mir file and (b) line1
appears sometime thereafter. However, it also allows for random stuff to appear in the middle. This is intended to make the test robust, but it also makes things quite surprising -- if you look at the tests, you'll see we mostly don't really want that most of the time.
What I think we should do is modify it so that line0
and line1
must appear consecutively. For bonus points, we could allow a special comment like // ...
to be included that would indicate that zero or more lines may be skipped in between.
The code that implements this check can be found in in runtest.rs
. It begins here, with this loop that walks over the .rs
test file, extracting the expected lines. The expected lines are accumulated into a vector. Whenever we reach a // END
comment, we then invoke compare_mir_test_output()
, which will open the relevant file and search for the expected lines.
So the idea would be to detect // ...
and record that in the vector (e.g., we might store a Vec<ExpectedLine>
, where enum ExpectedLine { Ellipsis, Some(String) }
). In compare_mir_test_output()
, we would then skip lines only when an Ellipsis
is found.
We will possibly have to adjust some of the existing tests, I'm not sure, but we should be able to do so readily enough.