-
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
rewrite liveness
analysis to be based on MIR
#51003
Comments
I'm removing WG-compiler-nll as this isn't really related to NLL, it's just general cleanup. Here are some tips into the code for future reference: The liveness code I am referring to, which ought to be ported: rust/src/librustc/middle/liveness.rs Line 190 in 860d169
The MIR-based liveness computation: rust/src/librustc_mir/util/liveness.rs Line 118 in 860d169
|
Is this issue still relevant? Can I pick it up? |
It's still relevant. Feel free to ping me with questions. |
I looked into this this morning. A few roadblocks remain. For one, the MIR has no record of statements like There's also the issue of associating Finally, I was seeing spurious warnings for variables that were bound in a match arm and only used in a guard. Presumably this will also require some changes to MIR building, but I've not investigated this one yet. Since I don't have a good intuition for incremental compilation or MIR building, I would appreciate any advice on solving either of these problems. @pnkfelix, this was a while ago, but did you consider ignoring |
The only reason |
I think this agrees with what @matthewjasper said, but I want to encourage us not to do anything "clever" around incremental -- that is to say, we should not try to tweak hashing schemes or something (imo), we should hash all the data. If we don't want something to be hashed, the right way is to remove it from the struct itself (which should then prove we don't have a dependency on it). That said, when it comes to spans, we've been talking for some time about a better scheme to handle spans and incremental compilation (see e.g. #47389), which seems related. |
@nikomatsakis FWIW, my plan was to encapsulate this so that it would be clear to both contributors and reviewers when this Regardless, switching |
Is this something I could contribute to with some mentorship? |
I can answer specific questions on anything MIR related, but for the incremental comp stuff we discussed above you'll need to look elsewhere. I never found a solution I was satisfied with. The other big stumbling block I remember was
These two issues are solved in #72164. See this comment for a discussion of the first. It's also worth mentioning that with #91032, there's another big HIR dataflow analysis in addition to liveness. Going from 2 big analyses to 1 might be a less attractive proposition than going from 1 to 0. |
I'm of mixed minds here. I sometimes think that we should do our safety analyses on "THIR" instead of "MIR". MIR currently serves two masters, analysis and optimization -- I think that produces more tension than I anticipated initially. |
For some context I was hoping to work towards #65467. |
I would think that the decision between MIR or THIR (or HIR) for analyses should be based on which one would allow the simplest (or cheapest?) implementation, and that any problems caused with incremental can be solved architecturally. It seems like THIR would allow a simpler implementation than the HIR (especially for #65467), but I don't have enough experience with MIR to comment on how that would compare. My understanding of the "tension" is this: The MIR has insufficient information about the original code to do some analyses/diagnostics. This is fixed by copying more data from HIR to MIR. But that added data tends to break incremental compilation. So then we need to separate "data needed for codegen" from "data needed for analyses" and not hash the latter. This seems resolvable to me in my limited understanding. Though I wonder if the mere size of the "analyses data" needed should be enough to deter us from using the MIR? |
I don't really think this is about incremental compilation, @camsteffen. It's more about what invariants the MIR code must maintain. The simplest example is stripping dead code: it's convenient for MIR to not contain unreachable code, but that also means that any analysis will disregard such code. How smart can MIR be in removing dead code? Can it do CSE? Constant propagation? etc |
Aren't those all optimizations that happen after lowering, and so analyses can happen in between? (thanks for the discussion) |
I believe something like |
The current liveness code does a simple liveness computation (actually a few such things) and tells you when e.g. assignments are dead and that sort of thing. It does this on the HIR. It would be better to do this on the MIR — in fact, the NLL computation is already computing liveness across all of MIR, so we ought to be able to piggy back on those results I imagine.
It may be a good idea to wait though until the MIR borrowck stuff "settles down" a bit before attempting this.
The text was updated successfully, but these errors were encountered: