-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix 5707 #7346
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
fix 5707 #7346
Conversation
r? @giraffate (rust-highfive has picked a reviewer for you, use r? to override) |
H |
41053bf
to
883e073
Compare
I won't get to this for the next three weeks |
can you add a test showing this?
you already mentioned feeding &mut into function calls and getting something out. A similar situation occurs with deref projections. Dereferencing a raw pointer can subvert any checks we could possibly make. The implementation of this PR lgtm as far as in "is an improvement to the status quo", as you're rejecting more code and now allowing anything that wasn't allowed before. I will merge it, but I think we (wg-mir-opt) should figure out how to make writing and analyzing mir optimizations better. One of my main worries with this lint (and other mir analyses) is that it is hard to reason about their behaviour at the source level. We generate and track a lot of information, but we cannot "visualize" (textually or otherwise) this information and thus analyze it in detail. While there are such visualizations for specific analyses, we should figure out something generalizeable. |
Clippy dogfood is failing, and likely it would be good to rebase this PR first. After that r=me |
883e073
to
7e31363
Compare
Thanks for reviewing such a longthy pr!
Newly added test:
I'd like to help it. You can appoint specific job for me. I can make a try. |
You still have the dogfood test failure (running clippy on clippy) to address before we can merge this.
Let's talk about this in https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/debugging.20tools.20for.20dataflow.20and.20mir.20opts |
7e31363
to
c4a1554
Compare
c4a1554
to
1091002
Compare
@bors r+ Thanks! |
📌 Commit 1091002 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
changelog:
[`redundant_clone`]
, fix #5707Root problem of #5707 :
generate PossibleBorrower(_2,_1) and PossibleBorrower(_3,_1).
However, it misses PossibleBorrower(_3,_2).
My solution to #5707 :
When meet a function call, we should:
For example:
we need to build
return value with parameter(current implementataion)
PossibleBorrower(_2,_1)
PossibleBorrower(_3,_1)
PossibleBorrower(_4,_1)
PossibleBorrower(_5,_1)
between mutable borrow and immutable borrow
PossibleBorrower(_4,_2)
PossibleBorrower(_5,_2)
PossibleBorrower(_4,_3)
PossibleBorrower(_5,_3)
between mutable borrow and mutable borrow
PossibleBorrower(_3,_2)
PossibleBorrower(_2,_3)
But that's not enough.
Modification to _2 actually apply to _22.
So I write a
PossibleBorrowed
visitor, which tracks (borrower => possible borrowed) relation.For example (_2 => _22).
However, a lot of problems exist here.
Known Problems:
&mut
's origin are collected.I'm not sure how to deal with
&mut
when meet a function call, so I didn't do it currently.Also, my implement is not flow sensitive, so it's not accurate.
This pr doesn't count _3 as origin of _2.
foo(_2, _3)
will emit PossibleBorrower(_3,_2) in this pr, but _3 and _2 may not have relation.Clippy may feel that _3 is still in use because of _2, but actually, _3 is on longer needed and can be moved.
Insight
The key problem is determine where every
&mut
come from accurately.I think Polonius is an elegant solution to it. Polonius is flow sensitive and accurate.
But I'm uncertain about whether we can import Polonius in rust-clippy currently.
This pr actually is part of Polonius' functionality, I think.
TODO
cargo test
can't pass yet due to similar variable name