Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up[nll] optimize redundant reborrows #53176
Comments
nikomatsakis
added
T-compiler
A-NLL
WG-compiler-nll
NLL-performant
labels
Aug 7, 2018
nikomatsakis
added this to the Rust 2018 RC milestone
Aug 7, 2018
nikomatsakis
changed the title
[nll] avoid creating borrows for reborrows of shared references
[nll] optimize redundant reborrows
Aug 7, 2018
This comment has been minimized.
This comment has been minimized.
|
Let me leave a few notes here. I'm not 100% sure on what changes are needed, but this is the general vicinity. We compute the "set of all borrows" into this In that data structure, we currently walk over the MIR and identify assignments of borrows (e.g., rust/src/librustc_mir/borrow_check/borrow_set.rs Lines 162 to 164 in ccb550f An 'unsafe place' is something like the deref of a raw pointer: https://github.com/rust-lang/rust/blob/master/src/librustc_mir/borrow_check/place_ext.rs#L27 I think we basically want to rename /// Returns true if we can safely ignore borrows of this place.
/// This is true whenever there is no action that the user can do
/// to the place `self` that would invalidate the borrow. This is true
/// for borrows of raw pointer dereferents as well as shared references.
fn ignore_borrow_of(&self) -> bool {
...
}then we will add [ rust/src/librustc_mir/borrow_check/place_ext.rs Lines 42 to 45 in ccb550f Specifically, |
This comment has been minimized.
This comment has been minimized.
|
So, I couldnt' help myself. I had a few minutes and that changed seemed so easy that I gave it a spin. |
nikomatsakis
referenced this issue
Aug 7, 2018
Merged
optimize redundant borrows and escaping paths in NLL #53177
bors
added a commit
that referenced
this issue
Aug 7, 2018
nikomatsakis
self-assigned this
Aug 8, 2018
bors
added a commit
that referenced
this issue
Aug 10, 2018
bors
added a commit
that referenced
this issue
Aug 10, 2018
bors
added a commit
that referenced
this issue
Aug 10, 2018
bors
added a commit
that referenced
this issue
Aug 10, 2018
bors
added a commit
that referenced
this issue
Aug 10, 2018
This comment has been minimized.
This comment has been minimized.
|
This was completed in #53177 |
nikomatsakis commentedAug 7, 2018
When you have a borrow like this:
where
y: &T, then there is really no reason for the borrow checker to "record" the borrow or figure out its scope. The reason is that there is no action that one can do withythat would invalidatex. (Of course we still want to record the outlives relationship that forcesy's lifetime to outlivex's lifetime.)The old AST borrow checker did this same optimization. It ought to have a huge effect on html5ever: my profile measurements suggest that basically all of its time is spent with these very large borrow sets.