fix(reborrow): recursive implementation - #159103
Conversation
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @vakaras Some changes occurred to the CTFE machinery Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri Some changes occurred to constck cc @fee1-dead This PR changes rustc_public |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
cc @bjorn3
cc @rust-lang/clippy |
This comment has been minimized.
This comment has been minimized.
c74824e to
4ac1ece
Compare
This comment has been minimized.
This comment has been minimized.
aebdf5d to
b845ed2
Compare
This comment has been minimized.
This comment has been minimized.
b845ed2 to
549d21b
Compare
This comment has been minimized.
This comment has been minimized.
|
Reminder, once the PR becomes ready for a review, use |
44ad71e to
2c3a3fa
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
2c3a3fa to
d815250
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
If Reborrow finds '&'a mut T' fields then it inserts a Deref and borrow of the T, and likewise if it finds a 'T: Reborrow' field then the field type is recursed into. This makes Reborrow always produce the correct borrow checking logic at the cost of most probably being inconsiderately expensive. The thinking is that performance will be a followup consideration.
Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
d815250 to
c289b88
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
| /// producing a borrow on an indirect place, producing a value that can be returned from the | ||
| /// function since it does not capture any local place. If no such field exists, then | ||
| /// reborrowing the type must dereference the type itself to find an indirect place, but | ||
| /// generally such types will not implements `Deref`. Therefore, in borrow checking we instead |
There was a problem hiding this comment.
| /// generally such types will not implements `Deref`. Therefore, in borrow checking we instead | |
| /// generally such types will not implement `Deref`. Therefore, in borrow checking we instead |
| @@ -0,0 +1,17 @@ | |||
| //@ check-fail | |||
There was a problem hiding this comment.
this is the default setting for ui tests and redundant (also more of those below)
| } | ||
| } | ||
| if !did_reborrow { | ||
| // If source contained no reference, perform a phantom dereference. |
There was a problem hiding this comment.
Ah this is the key point here: we need the rest of borrowck to act as if there is a deref here 🤔
| // The reason why we do this obligation here (again: it's already done in THIR) is | ||
| // because we'd want to catch impls like `CoerceShared<Target<'static>> for Source<'a>` | ||
| // and, in those cases, correctly generate a `'a: 'static` bound. | ||
| // | ||
| // I'm not sure what would be the right way to resolve this conundrum. |
There was a problem hiding this comment.
this is exactly what you need to do in borrowck's "typeck". You redo the ops, this time with lifetimes, and ICE on any type conflicts.
I think what you should be doing (instead of manually running an ocx), is to use the usual fully_perform actions, but otherwise this is exactly The Right Thing ™️
|
@bors delegate+ r=me with remaining things resolved |
View all comments
If Reborrow finds '&'a mut T' fields where 'a is the Reborrowed type's first lifetime parameter (currently the only lifetime that is allowed to reborrow) then it inserts a Deref and borrow of the T, and likewise if it finds a 'T: Reborrow' field then the field type is recursed into.
This makes Reborrow always produce the correct borrow checking logic at the cost of most probably being inconsiderately expensive. The thinking is that performance will be a followup consideration.
r? @oli-obk