Skip to content

[nll] avoid liveness for values that escape into the output when in a static #52713

Closed
@nikomatsakis

Description

@nikomatsakis

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() {
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    NLL-performantWorking towards the "performance is good" goalT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions