about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-07-09 01:13:49 +0000
committerbors <bors@rust-lang.org>2021-07-09 01:13:49 +0000
commitfdfe819580062a441024d713b49340cd3f7d7efc (patch)
treef4ad5b6bb8942d60b9ab296bbf4c2ce98cf03e94 /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
parent8b87e85394aa583b01e53aef06343dd0749a3324 (diff)
parent38dcae2cda85916d91d727ffe08a944e69ee3162 (diff)
downloadrust-fdfe819580062a441024d713b49340cd3f7d7efc.tar.gz
rust-fdfe819580062a441024d713b49340cd3f7d7efc.zip
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`
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions