-
Notifications
You must be signed in to change notification settings - Fork 13k
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
[nll] avoid liveness for values that escape into the output when in a static #52713
Comments
I might not be able to finish before going on vacation, but I'm looking at this, and will update the Zulip topic with any progress, in case someone wants to pick this up if need be. |
[WIP] avoid computing liveness for locals that escape into statics Fixes #52713 I poked at this on the plane and I think it's working -- but I want to do a bit more investigation and double check. The idea is to identify those local variables where the entire value will "escape" into the return -- for them, we don't need to compute liveness, since we know that the outlives relations from the return type will force those regions to be equal to free regions. This should help with html5ever in particular. r? @pnkfelix cc @lqd
avoid computing liveness for locals that escape into statics Fixes #52713 I poked at this on the plane and I think it's working -- but I want to do a bit more investigation and double check. The idea is to identify those local variables where the entire value will "escape" into the return -- for them, we don't need to compute liveness, since we know that the outlives relations from the return type will force those regions to be equal to free regions. This should help with html5ever in particular. - [x] test performance - [x] verify correctness - [x] add comments r? @pnkfelix cc @lqd
Just realized that while the underlying idea here is sound, the means of implementation is totally flawed. The problem is using union-find, which establishes a bidirectional link. This program for example type-checks now, but should not: #![feature(nll)]
fn foo<'a>(x: &'a mut u32) -> u32 {
let mut x = 22;
let y = &x;
if false {
return x;
}
x += 1;
println!("{}", y);
return 0;
}
fn main() { } |
OK so I opened #53109 to revert my incorrect changes. |
I think that the correct fix is to replace the code that uses union-find with a directed graph. Basically we add an edge In terms of broken example I cited, what is happening is that we have:
Using union-find means that |
Another thought: I think that we can rejigger things so that — by the time we compute liveness — we have the outlives relations at hand. That would in some sense be "ideal" -- we would skip computing liveness precisely when we care, rather than the current code which duplicates some of the logic. On the other hand, analyzing the outlives relationships is a bit more complicated, since we have to look at all the regions in a variable's type. I guess the would be something like this:
Hmm, sounds not that complex, actually -- the main work will be refactoring to push the liveness computation down so that it occurs later (in particular, constructing the liveness map later). Now that I think about it, it is ok if we still add more outlives constraints after computing liveness (which I think we may do in some cases owing to normalization), because adding more constraints would only cause us to skip MORE liveness. |
I was trying to write up mentoring instructions for this but felt like it'd be easier to just implement the dang thing. Hence #53168 |
This was completed in #53177 |
Yes, it was. =) |
As an optimization for large statics like the ones in html5ever and so forth: we tend to spend a ton of time in liveness and elsewhere in these cases, but it seems a bit silly since we know that any references or lifetimes which flow into the result must be
'static
.The idea would be something like this:
Local
values._0 = _1
or_0 = Aggregate { _1 }
or_0 = &_1
, we union together_0
and_1
-- basically, the idea is we union_0
and_1
whenever the type of_0
must contain any of the lifetimes in_1
._0
-- for those variables, we do not have to compute liveness, and can instead just force all of their regions to outlive'static
.I .. think that's sound =)
Example:
The text was updated successfully, but these errors were encountered: