3 ms·
As of today, you can easily install miri on the nightly channel, which is why this is popping up today. $ rustup component add miri —toolchain=nightly You c
by steveklabnik 8y ago
As of today, you can easily install miri on the nightly channel, which is why this is popping up today.
$ rustup component add miri —toolchain=nightly
You can then “cargo +nightly miri test” to run your tests under miri. You probably should “cargo clean” first.
Of course you can skip the explicit nightly flags in those commands if your default toolchain is nightly.
- bluejekyll 8y agoWould it be accurate to say that running Miri against your code might catch some issues in unsafe code that the standard compiler will not?
- steveklabnik 8y agoAbsolutely, that is in fact the point :)
- shepmaster 8y agoPedantically, it's running your code via Miri. Miri is an interpreter, so you have to trigger undefined behavior during a specific run of Miri for it to be reported.
- bluejekyll 8y agoI think that’s a fair point. It sounds like it’s possible with Miri to write unit tests for specific UB concerns, and it’s more likely to catch them than standard unit tests. This will be useful.
- shepmaster 8y agoI haven't put any thought or time into it yet, but I assume you could combine it with a fuzzer. cargo-fuzz [1] already does this with LLVM's sanitizers, but I'm thinking something like proptest [2] could be used to help find those specific inputs and run under miri. It may even be as simple as creating the normal proptest tests and then doing `cargo miri --test` or something similar! [1]: https://github.com/rust-fuzz/cargo-fuzz https://github.com/rust-fuzz/cargo-fuzz [2]: https://crates.io/crates/proptest https://crates.io/crates/proptest
- staticassertion 8y agoFuzzing + miri sounds like it will be incredibly slow. Probably slower than just using asan. The good thing about UB in rust is it's easy to target - you don't need to explore the whole space, just module boundaries that encapsulate that space. So something more fine grained should be fine with miri, and fuzzing can capture more complex errors like panics.
- shepmaster 8y agoYes, that's what I mean about using proptest (if you are unfamiliar, it's akin to QuickCheck). You'd write the proptest functions for your dedicated unsafe section. As an example, I use this with Jetscii [1] in an attempt to throughly test SIMD vs non-SIMD code. If Miri detected errors with SIMD (I don't think it does now), then I could run those tests inside of Miri, having them pull double duty. [1]: https://github.com/shepmaster/jetscii/ https://github.com/shepmaster/jetscii/
- staticassertion 8y agoOh, yes, agreed that proptest is way more viable here and probably a good solution to pair with miri.
- Manishearth 8y agoIt would be very nice if cargo-fuzz targets could be swapped to work with proptest, quickcheck, and miri. It's something I've wanted to do for a while, but I don't have as much time to maintain cargo-fuzz.
- leshow 8y agoThis is giving me an error: > rustup component add miri --toolchain=nightly info: downloading component 'miri' info: installing component 'miri' info: rolling back changes error: component manifest for 'miri' is corrupt If Miri as in interpreter, are there any plans to bring a REPL to Rust? It's one thing I sorely miss.
- steveklabnik 8y agoAre you on the latest nightly? It will only work on the latest nightly, and going forward into the future. There’s another sub-thread on HN about that, check it out :)
- Vinnl 8y agoNamely here, in case they drift apart: https://news.ycombinator.com/item?id=19501277 https://news.ycombinator.com/item?id=19501277 :)
- nmdeadhead 8y agoFWIW, I manually attempt to update to nightly (nightly-x86_64-apple-darwin) once a day, not because I need to, but out of curiosity. I find that clippy often prevents me from updating for a day or two before working again. Today happens to be a day (and I think yesterday was, too) when I get: "error: component 'clippy' for target 'x86_64-apple-darwin' is unavailable for download for channel 'nightly'" and sure enough, I get the misleading "manifest for 'miri' is corrupt" when I try to add miri. Surprisingly, I used "rustup component remove clippy" and still couldn't update to nightly, still with a complaint about clippy. I'm not mentioning any of the above because it bothers me; I expect things to work tomorrow or the next day. I just assume this might be biting a lot of people (perhaps everyone on MacOS).
- Manishearth 8y agoYeah, the tools team is looking into providing a nightly-with-tools experience that's smoother about this stuff.
- 8y ago
- akiselev 8y agoA resource for those trying to install nightly on OSX is the page tracking component status for nightly builds: https://rust-lang.github.io/rustup-components-history/x86_64-apple-darwin.html https://rust-lang.github.io/rustup-components-history/x86_64... (the page also contains links to the status of components for all other platforms) Unfortunately both Clippy and RLS have failed to build since 3/24 but 2019-03-23 should work. rustup install nightly-2019-03-23