-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Allow a MIR analysis to perform the state join
directly
#114900
base: master
Are you sure you want to change the base?
Conversation
r? @davidtwco (rustbot has picked a reviewer for you, use r? to override) |
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
The dataflow framework relies on the semi-lattice traits to model the mathematical concept. This is required for correctness and termination. What does it mean for a lattice to depend on a context parameter? Such context must be part of the dataflow analysis |
The context here would be any supplemental data that doesn't change during the analysis. For the specific case it would be the borrow state calculated by a previous analysis. I'm now just realizing that this needs to be a mutable reference anyways for clippy. Specifically this function is needed. Note that To more precisely describe the join, a state such containing the following
is merged with
at which point |
☔ The latest upstream changes (presumably #111555) made this pull request unmergeable. Please resolve the merge conflicts. |
r? @cjgillot |
Upon further work even taking the analysis by mutable reference isn't enough as the location of the join is also needed. The new implementation adds a join function to the analysis with a default implementation using |
This looks like you want a custom version of |
|
@Jarcho do you need more input about the design, here? AFAICS the discussion is progressing for now in rust-clippy#11364. Anyway, reassigning to you as a nudge to resolve conflicts. Feel free to request a review with @rustbot author |
TBH, I'm quite unconvinced by the need for this PR. |
The fundamental abstraction it relies on is: there exists some function I don't know if you looked at this after the last change I made. Current implementation is for the analysis to implement the join. There is a default implementation for the case where the domain implements Some change here is still seems needed. Don't know if you saw this comment: rust-lang/rust-clippy#11364 (comment). |
@Jarcho any updates on this? |
@cjgillot I guess you aren't seeing notifications from the thread in clippy's repo. The last suggestion you had has a small downgrade to the lint's capabilities. |
JoinSemiLattice
join
directly
@rustbot ready This is still waiting on a response. |
…ttice` the default implementation when the join does not require extra context.
Your answer is a PR on clippy repo. I made several comments on that pass, mostly asking to document the design and suggesting to decouple the analysis in several steps. Before we modify the dataflow API, I'd like to understand why it needs to be modified. |
My answer to what question? The only question that could answer is 'What am I working on that needs these changes?".
I have also been responding to all of those.
I'll have to get back to you on that since it's now been several months since I've last worked on this. |
☔ The latest upstream changes (presumably #122182) made this pull request unmergeable. Please resolve the merge conflicts. |
by reading the latest comments, I get the feeling that this PR is waiting on more design work @rustbot author |
Coming back to this again. Since it's been a while I'm going to just repeat some things here. This adds a way to pass additional parameters when performing the join between two states. As a non-exhaustive list this includes things like the MIR body, which block this state is for, precalculated values/tables, and preallocated scratch memory. Basically this is for any additional data needed that's the same for all the values in the graph, and as such, should not be stored per node; or to amortize the cost of doing something as is the case for allocating scratch memory. For the implementation this adds a single new trait, Moving to the clippy analysis, it needs to keep track of three things:
Joining two states consists of merging the two lists (1 & 2) and then merging the set of tracked values. If, when merging, there is a local with two different values then a new value will have to be created and the appropriate entries in the second list need to be added. To get the results we start from a set of all clone calls. While visiting the results Any read from a local in the second list removes the associated clone calls from the set. Anything remaining didn't need to be a clone. Ideally the first list would have a representation like At some point in the future the lint will also be extended to support projections. Field and array index projections don't change things too much other than increasing the number of values being tracked. Deref projections would be a whole other issue though. |
AnalysisJoin
is a separate trait in order for the domain type to provide the join viaJoinSemiLattice
. This also prevents a custom join implementation when using aJoinSemiLattice
type as the domain, but that's probably not useful to do in the first place.This is needed to make
clippy::redundant_clone
an analysis pass. Given the following:To avoid linting on the clone, the join between the two branches needs to be able to see that
x
is borrowed at that point and cannot be moved. Since borrowing is a different analysis pass this needs to be passed into the join somehow.