Reborrow &mut on every move - #163494
Reborrow &mut on every move#163494Jules-Bertholet wants to merge 20 commits into
&mut on every move#163494Conversation
66da32c to
d4271ff
Compare
would that work without changing closure upvar inference to match? e.g. I think this closure captures fn main() {
let x = &mut ();
let mut f = || {
let _y: &mut _ = x;
};
f();
f();
}without the annotation, it captures edit: oh, of course, this makes the MIR for constructing the closure do the reborrow since it uses edit 2: but it'd still be inferred to be a |
This comment has been minimized.
This comment has been minimized.
|
Some changes occurred in match lowering cc @Nadrieril |
|
r? @adwinwhite rustbot has assigned @adwinwhite. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
#163494 (comment): I don't understand MIR optimizations, don't feel confident touching these tests. Someone who knows more than I do will need to take a look |
This comment has been minimized.
This comment has been minimized.
|
@rustbot label F-reborrow |
19e0c43 to
a1b8771
Compare
a1b8771 to
ebd28ba
Compare
|
This PR changes a file inside |
This comment has been minimized.
This comment has been minimized.
Hopefully cuts down on MIR bloat
This reverts commit 94d40ae.
|
Some changes occurred in cc @BoxyUwU Some changes occurred in match checking cc @Nadrieril |
This comment has been minimized.
This comment has been minimized.
11f5a77 to
a18db39
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I am trying to fix the remaining mir-opt regression, but it's a little tough. If I improve |
|
Hmm, so it looks like all the optimizations that are lost in CopyProp get recovered in ReferencePropagation. So there is only an actual optimization regression in opt-level=0 builds (where ReferencePropagation is not enabled). So maybe this is fine? |
This comment has been minimized.
This comment has been minimized.
We don't need these anymore, now that the reborrows get inserted in MIR. We still need some trace in HIR for closure capture inference, so use `FakeMutReborrow` for that.
This appears to be a strict optimization.
b6b4f2f to
ab910d7
Compare
|
This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @vakaras |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Reborrow `&mut` on every move
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (c842e75): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. @bors rollup=never rustc-perf Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.1%, secondary -1.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 4.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 489.203s -> 490.429s (0.25%) |
|
@rustbot label I-lang-nominated |
| /// CoerceShared. These may be end up implemented as multiple MIR operations. | ||
| /// | ||
| /// This is produced by the [`ExprKind::Reborrow`]. | ||
| /// This is produced by the [`ExprKind::CoerceShared`], |
There was a problem hiding this comment.
| /// This is produced by the [`ExprKind::CoerceShared`], | |
| /// This is produced by [`ExprKind::CoerceShared`], |
(I know this is pre-existing, but you're touching this comment anyway)
View all comments
From the Reference:
This PR adds one exception to the above rules: if the type of the value is an
&mut _mutable reference, the value will now always be reborrowed instead of moved.This allows the following to compile:
Unfortunately, the following continues to not compile:
This last case is unfortunately very difficult to fix at present. See #47478 for discussion.
When
# is enabled, we also insert reborrows for concrete types implementingReborrow.@rustbot label A-MIR A-borrow-checker T-lang needs-fcp