]> git.lizzy.rs Git - rust.git/commit - src/tools/miri
Auto merge of #86701 - sexxi-goose:optimization, r=nikomatsakis
authorbors <bors@rust-lang.org>
Fri, 9 Jul 2021 01:13:49 +0000 (01:13 +0000)
committerbors <bors@rust-lang.org>
Fri, 9 Jul 2021 01:13:49 +0000 (01:13 +0000)
commitfdfe819580062a441024d713b49340cd3f7d7efc
treef4ad5b6bb8942d60b9ab296bbf4c2ce98cf03e94
parent8b87e85394aa583b01e53aef06343dd0749a3324
parent38dcae2cda85916d91d727ffe08a944e69ee3162
Auto merge of #86701 - sexxi-goose:optimization, r=nikomatsakis

2229: Reduce the size of closures with `capture_disjoint_fields`

One key observation while going over the closure size profile of rustc
was that we are disjointly capturing one or more fields starting at an
immutable reference.

Disjoint capture over immutable reference doesn't add too much value
because the fields can either be borrowed immutably or copied.

One possible edge case of the optimization is when a fields of a struct
have a longer lifetime than the structure, therefore we can't completely
get rid of all the accesses on top of sharef refs, only the rightmost
one. Here is a possible example:

```rust
struct MyStruct<'a> {
   a: &'static A,
   b: B,
   c: C<'a>,
}

fn foo<'a, 'b>(m: &'a MyStruct<'b>) -> impl FnMut() + 'static {
    let c = || drop(&*m.a.field_of_a);
    // Here we really do want to capture `*m.a` because that outlives `'static`

    // If we capture `m`, then the closure no longer outlives `'static'
    // it is constrained to `'a`
}
```

r? `@nikomatsakis`
compiler/rustc_typeck/src/check/upvar.rs