-
Notifications
You must be signed in to change notification settings - Fork 224
Add miri support #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
For an arbitrary user coming to the playground, are there any other reasons they would want to run Miri? In the same vein, what's a 1-2 sentence of "marketing copy" that will accompany Miri in the menu: This is all centered around "why should the playground expose Miri in the first place". Our bar has to be a bit higher than "it's cool" or "I like it" just because it's a forward-facing part of the Rust web presence, so I'm doing my due diligence. (Is it OK to capitalize it as "Miri"?) |
Looking at https://github.com/solson/miri/, that seems to be common.
I can't think of another reason. I'm also not good at marketing. ;) Did you plan to put it in the tools menu? Since it's a way to run the program, I figured it'd be in the "run" menu. But I don't know how you are distributing tools over these menus. Maybe something like
Or should it say "to detect undefined behavior"? How strongly do we have to clarify that it cannot detect everything, but also that not every error is UB (it could just be that miri does not support this operation)? We could probably also improve the error message to make it easier to interpret (I just opened rust-lang/miri#417 for that purpose).
Understood and appreciated. I would be willing to let this undergo some kind of process to make sure we have wider consensus. I just have no idea what the process is.^^ |
Yes.
But why would anyone ever want to run their code using Miri? You just stated that the only reason to use Miri is to check for UB. The fact that it runs the code to do so is irrelevant, much like the fact that Clippy uses
It's (always) in the process of being nailed down, of course, but right now anything in the Run menu is "built-in" to the compiler and tools are "add-ons".
Nah, I don't think it needs to be all that. The wrong answer would have been "so I can get bug reports from users", IMO. |
In that realm, the output is really a wall of text, very hard to read. I think if you want people to easily drop in and start using Miri, you might need to pay some mind to that:
|
I don't think it has to be strong, but it should be present.
Does Miri detect non-UB errors? If so, what are some examples?
Based on our discussion, I'd tweak this a bit to:
|
Clippy is static tool. It looks at all code and does its magic. Miri works dynamically. It runs a program and tells you if it sees anything fishy in that execution. So if e.g. To me, that's a fundamental difference. But you are probably the better judge for how users would see this. ;)
Fair enough. Getting more users is always nice, of course, but I think we can actually deliver some value -- as you have seen, out-of-bounds pointer stuff is already handled, as are unaligned accesses. I have some plans for next week to significantly extend the range of things that are checked during execution.
Any advise? This is the stack trace. Maybe everything but the top frame shouldn't be rendered as a span, but just show e.g. function name, file name, line number?
Miri cannot interpret Try
Sounds good! I'll keep you posted when there are more important items to be added to the list. (Violation of data layout invariants is what I want to reliably detect next week.) @oli-obk anything you think should be mentioned already? |
I agree from the implementer side, but from a user side, it doesn't matter much...
Except for this. This means that it's important to convey this to the user — only certain classes of UB will be detected, and only if they actually happen during evaluation of the program. I'd try and cram that in as
I'd normally take this to mean "there is nothing that Miri can interpret", which would mean it's pretty useless 😈 Am I correct in assuming you mean "there are certain types of things that Miri cannot interpret?"
I think this is kind of what I was asking. The thing that's exciting (and scary...?) is that this is pure safe Rust. Is this undefined behavior? I feel like it's not. This seems like we should expand the description to cover whatever this is.
Perhaps. The main thing is that it's very hard for a user to take action on the fact that the call passed through some stdlib things. Likewise, if there's UB in a crate, the average end user isn't going to be able to do much about it. The magical ideal would be to show "just the code that matters", but that's likely up there with the halting problem 😇. |
Right, that's why I think the right verb is to use "execute" or something. I am not sure how many people are familiar with "UB sanitizers", but they work the same way: Compile your program with some extra flags, run it, and then the sanitizers will tell you if this execution does something fishy. It's important we manage to communicate that miri tests an execution for UB, not a program.
oops typo corrected.^^ I meant "miri cannot interpret everything".
Yes it's scary that ptr -> int casts are safe. ;) And no this is not UB. From all we know. The rules around ptr <-> int casts are fuzzy at best and typically unknown. We are relying on de-facto LLVM behavior, because there are things you can do in safe Rust that are UB in C, and LLVM does not document those areas very well.
True, but we could likely do better. ;) E.g. we could try to not show spans in libstd/libcore? Or any other crate than the current one? Not sure. |
For reference based on our IRC discussion:
|
Heh, not installing rust-src gives what seems like reasonable output:
I wonder if "current crate" + "bottommost stack frame" would be useful. |
Well, I'm glad I looked into that. Much smaller now
|
How about
|
The purpose of the xargo step is to get a libstd that includes MIR for all functions. Usually, we only store MIR for generic functions; the others are already sent to LLVM and have their machine code generated so we don't usually need the MIR any more. Except, of course, miri needs it. So, rust-src should not be needed at the end to get miri to work, it'll just mean we cannot show spans in libstd/libcore. Which maybe we do not even want to?
Something along these lines, yes.
Ah, I forgot about the rust-src component, sorry for that. So we are slightly above 100MiB. I am wondering why cargo-miri is so big, it hardly does anything... it's just a wrapper to call rustc or miri, respectively.
👍 |
Discussed briefly on IRC with @shepmaster: It would be great if the playground could run programs in miri. That's a MIR interpreter. One reason why one might want to do this is that miri will stop program execution when there is UB -- the checks are not complete yet, but more are coming. It will never be able to detect all kinds of UB (e.g. relying on how
#[repr(Rust)]
lays out data is hard to detect), but the idea is it should detect e.g. violation of the pointer aliasing rules.Since I don't know how the playground works, I'll just give instructions for how to run miri manually. All of this has to happen with a nightly compiler.
Setup:
git clone https://github.com/solson/miri && cd miri
cargo install xargo
xargo/build.sh
~/.xargo/HOST
.cargo install --all-features --force
Now, when you are in a crate, instead of
cargo run
you would doMIRI_SYSROOT=~/.xargo/HOST cargo miri -- -Zmiri-start-fn
. That's it.The text was updated successfully, but these errors were encountered: