You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 with y that would invalidate x. (Of course we still want to record the outlives relationship that forces y's lifetime to outlive x'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.
In that data structure, we currently walk over the MIR and identify assignments of borrows (e.g., X = &<place>). For each of those, we allocate a borrow index... well, almost each of them. For some borrows, we don't bother -- in particular, borrows of "unsafe places":
I think we basically want to rename is_unsafe_place to something like ignore_borrow_of, and update the command like so:
/// 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.fnignore_borrow_of(&self) -> bool{
...}
Activity
[-][nll] avoid creating borrows for reborrows of shared references[/-][+][nll] optimize redundant reborrows[/+]nikomatsakis commentedon Aug 7, 2018
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
BorrowSetdata structure:rust/src/librustc_mir/borrow_check/borrow_set.rs
Line 23 in ccb550f
In that data structure, we currently walk over the MIR and identify assignments of borrows (e.g.,
X = &<place>). For each of those, we allocate a borrow index... well, almost each of them. For some borrows, we don't bother -- in particular, borrows of "unsafe places":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
is_unsafe_placeto something likeignore_borrow_of, and update the command like so:then we will add [
TyRef](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/enum.TypeVariants.html#variant.TyRef to this match here:rust/src/librustc_mir/borrow_check/place_ext.rs
Lines 42 to 45 in ccb550f
Specifically,
TyRefwhen the Mutability isMutImmutable.nikomatsakis commentedon Aug 7, 2018
So, I couldnt' help myself. I had a few minutes and that changed seemed so easy that I gave it a spin.
lqd commentedon Aug 16, 2018
This was completed in #53177