-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add MIR Validate statement #43403
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
Add MIR Validate statement #43403
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
Tidy fails due to lines longer than 100 chars |
Yeah I find it very hard to follow that requirement. Always feel like I have to make my code ugly to comply. Seems like I missed some places. :/ |
Ideally I'd like to run AddValidation before ElaborateDrops and after EraseRegions. For this to work, I need to move ElaborateDrops up, but RalfJung@3eb4141 fails badly -- many tests now report "Broken MIR: moving out of lvalue". @arielb1 I suppose just naively moving the pass around doesn't work.^^ Anything else I should try? EDIT: Also I wasn't sure about the comments saying what cannot be done starting where. Those are probably wrong in my patch. |
With some more help from @arielb1 I managed to reorder the passes without breaking everything (well, the test suite still passes). They also advised me to change |
This relies on #43512, which however is already r+'ed so it should land soon-ish. |
5a26f2c
to
95105af
Compare
☔ The latest upstream changes (presumably #43324) made this pull request unmergeable. Please resolve the merge conflicts. |
I rebased to resolve the merge conflict. |
…ribe when we can rely on them being locked in memory
This matters if the lvalues that is suspended involves Deref'ing a reference -- that reference's lifetime will then not be in the type any more
… different Lvalue type
Still failing to build libstd with the flag turned on:
I am at loss here. Struct ctors are functions that have their own MIR...? |
Yes they are. The MIR is created by https://github.com/rust-lang/rust/blob/master/src/librustc_mir/shim.rs |
I see. I fixed the code to handle that, but now I get
I suppose defaulted trait methods are yet another category that needs separate handling. |
Okay, now I am seeing really strange behavior... I thought by returning
I also just realized that closures in an unsafe fn probably can use unsafe features as well, so I will have to extend my scan into the closure environment accordingly. |
Okay, it seems to all work now. This is ready to be merged from my side. I hope I got all this HIR code right. I would really like to test whether closures are correctly detected to be unsafe, but unfortunately, mir-opt tests are not suited for this: Closures contain the filename in their type and name, which shows up in the lines we would like to test for. |
Ah dang it, I got another ICE in miri's test suite...
|
Fixed that as well (thanks @eddyb) |
Thanks :) So, what has to happen now to get r+? |
@bors r+ |
📌 Commit 7d8dc7a has been approved by |
Add MIR Validate statement This adds statements to MIR that express when types are to be validated (following [Types as Contracts](https://internals.rust-lang.org/t/types-as-contracts/5562)). Obviously nothing is stabilized, and in fact a `-Z` flag has to be passed for behavior to even change at all. This is meant to make experimentation with Types as Contracts in miri possible. The design is definitely not final. Cc @nikomatsakis @aturon
☀️ Test successful - status-appveyor, status-travis |
It looks like this PR regressed a number of benchmarks 5-7% on perf.rust-lang.org, @RalfJung do you know if this could perhaps cause a performance impact when not enabled? |
A more clear way to see this regression is perhaps here |
Is this compile tune or run time? I guess compile time, but it's not entirely clear to me. That is strange, the new pass does nothing when not enabled. There is a slight chance that more @arielb1 could reordering the passes have a bad effect on performance? |
@RalfJung Compile time. In particular it seems to be the LLVM pass that takes longer time. Trans time is also increasing but the contribution to increased total time is small. |
Ok I'll open a dedicated issue for this in that case! |
This adds statements to MIR that express when types are to be validated (following Types as Contracts). Obviously nothing is stabilized, and in fact a
-Z
flag has to be passed for behavior to even change at all.This is meant to make experimentation with Types as Contracts in miri possible. The design is definitely not final.
Cc @nikomatsakis @aturon