Closed
Description
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:
- Before computing liveness, we do a pass over the MIR.
- We create a union-find set of
Local
values. - Whenever we see a statement like
_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
. - Then at the end we check which things are union'd with
_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:
#![feature(nll)]
pub struct Map<K: 'static, V: 'static> {
pub key: u64,
pub disps: Slice<(u32, u32)>,
pub entries: Slice<(K, V)>,
}
pub enum Slice<T: 'static> {
Static(&'static [T]),
}
pub static NAMED_ENTITIES: Map<&'static str, (u32, u32)> = Map {
key: 1897749892740154578,
disps: Slice::Static(&[
(1, 4),
(1, 4),
(1, 4),
(1, 4),
(1, 4),
(1, 4),
(1, 4),
]),
entries: Slice::Static(&[
("GreaterSlan", (0, 0)),
("GreaterSlan", (0, 0)),
("GreaterSlan", (0, 0)),
("GreaterSlan", (0, 0)),
("GreaterSlan", (0, 0)),
("GreaterSlan", (0, 0)),
("GreaterSlan", (0, 0)),
]),
};
fn main() {
}