about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
diff options
context:
space:
mode:
authorAman Arora <me@aman-arora.com>2021-06-27 21:19:39 -0400
committerAman Arora <me@aman-arora.com>2021-06-29 03:16:43 -0400
commit23c0334fd3549c1e3a701c2669babbe272504251 (patch)
treeb66a512b079fbd338aecd229d57bbdab65026863 /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
parentfecc65a19763364b8dafbbf1d23be562268bd387 (diff)
downloadrust-23c0334fd3549c1e3a701c2669babbe272504251.tar.gz
rust-23c0334fd3549c1e3a701c2669babbe272504251.zip
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`
}
```
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions