-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Avoid Operand::Copy
with &mut T
#72093
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
r? @RalfJung |
This code is entirely unfamiliar to me, sorry... no idea why @petrochenkov thought I might be a good reviewer here. |
@@ -688,7 +688,7 @@ fn build_call_shim<'tcx>( | |||
|
|||
let rcvr = rcvr_adjustment.map(|rcvr_adjustment| match rcvr_adjustment { | |||
Adjustment::Identity => Operand::Move(rcvr_place()), | |||
Adjustment::Deref => Operand::Copy(tcx.mk_place_deref(rcvr_place())), | |||
Adjustment::Deref => Operand::Move(tcx.mk_place_deref(rcvr_place())), // Can't copy `&mut` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a mir-opt test showing this
I think if we're enforcing this invariant, we should have a mir pass that validates the various (I guess we have more) invariants that we want to be upheld. We could have a flag that runs this That said, I am not sure what actual effects cc @rust-lang/wg-mir-opt |
There are ideas about making a EDIT: Here is the issue: rust-lang/unsafe-code-guidelines#188. |
Having |
@jonas-schievink please post details in the issue I linked. So far, any time someone claimed that, a closer look revealed deinit-on- |
Ah, yes, that one is what I meant |
#61849 is very different from rust-lang/unsafe-code-guidelines#188. #61849 is basically Deinit-on- |
☔ The latest upstream changes (presumably #72205) made this pull request unmergeable. Please resolve the merge conflicts. |
I've added a small validation pass and a |
That's awesome, I about about 100 ideas for things this could check.^^ Just talked about that with @eddyb earlier today, in fact. Can we run that pass at least once, say at the beginning and end of |
I ran it on the testsuite already and found nothing. Right now it only checks 2 invariants though ( |
No that was PMs on Zulip. The main other check is: for every assignment, make sure the type of LHS and RHS match. (They are not always fully equal though, just "compatible enough"). We could also check that there is only one |
Good to know that this is true right now, but I'd prefer to make sure it stays that way. :) A check after every pass is probably overkill for that, but some check should IMO be done by default when debug assertions are enabled. |
I agree with running this check once when debug assertions are enabled. Maybe at the end of r=me with that |
@bors r=oli-obk rollup=never |
📌 Commit fe1753a has been approved by |
☀️ Test successful - checks-azure |
@@ -179,6 +191,11 @@ pub fn run_passes( | |||
} | |||
|
|||
body.phase = mir_phase; | |||
|
|||
if mir_phase == MirPhase::Optimized { | |||
validate::Validator { when: format!("end of phase {:?}", mir_phase) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we run it here even without debug assertions? Isn't that expensive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pass does very little work, so it's unlikely to be an issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pass does very little work
That is something I want to change.^^ #72796 does some non-trivial type folding.
…ewjasper MIR sanity check: validate types on assignment This expands the MIR validation added by @jonas-schievink in rust-lang#72093 to also check that on an assignment, the types of both sides match. Cc @eddyb @oli-obk
…ewjasper MIR sanity check: validate types on assignment This expands the MIR validation added by @jonas-schievink in rust-lang#72093 to also check that on an assignment, the types of both sides match. Cc @eddyb @oli-obk
…ewjasper MIR sanity check: validate types on assignment This expands the MIR validation added by @jonas-schievink in rust-lang#72093 to also check that on an assignment, the types of both sides match. Cc @eddyb @oli-obk
This is generally unsound to do, as the copied type is assumed to implement
Copy
.Closes #46420