Repository navigation
Don't emit no-op &T → &T reborrows - #164014
Jules-Bertholet wants to merge 4 commits into
Conversation
|
cc @rust-lang/clippy |
| where | ||
| T: TrivialClone, | ||
| { | ||
| #[inline] |
There was a problem hiding this comment.
To make tests/codegen-llvm/lib-optimizations/append-elements.rs happy. That test is really fragile…
|
@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.
Don't emit no-op `&T` → `&T` reborrows
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (d77c4b4): 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 -2.1%, secondary -2.9%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -2.7%, secondary -4.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.1%, secondary -0.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 486.533s -> 486.402s (-0.03%) |
|
Does this have implications on what Miri can catch? |
It shouldn't. Miri does retags on every typed copy. |
This comment has been minimized.
This comment has been minimized.
9190d54 to
2cbbc14
Compare
This comment has been minimized.
This comment has been minimized.
2cbbc14 to
258e369
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
258e369 to
e8df7c9
Compare
This comment has been minimized.
This comment has been minimized.
e8df7c9 to
2912de4
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Except inside closures, where we need to keep capture inference stable. Gets rid of MIR bloat, and improves diagnostics.
2912de4 to
b6cc682
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. |
| // FIXME: Ideally we would also skip `&mut` -> `&mut` reborrow, | ||
| // and handle that in MIR. | ||
| let can_skip_noop_reborrow = mutbl_b.is_not() | ||
| && if self.tcx.is_closure_like(self.body_def_id.to_def_id()) { |
There was a problem hiding this comment.
style: the large if expr is kinda difficult to read as a conjunction component?
There was a problem hiding this comment.
I've rewritten this if, hopefully it is more clear now.
| // FIXME: Inside a closure, reborrows can affect capture inference. | ||
| // So we have to keep the existing elision behavior stable. | ||
| // Ideally we wouldn't have to do this, it makes lifetime | ||
| // annotations affect codegen |
There was a problem hiding this comment.
A little bit confused here and also about other similar comments.
Immutable reborrow doesn't affect capture inference since they're copy anyway?
There was a problem hiding this comment.
The relevant test is https://github.com/rust-lang/rust/blob/701ce39ddc3b02efdf5146fd76c861b06c52aeb3/tests/ui/coercion/structural_identity_dependent_reborrows.rs.
Consider the following example:
let x: &u8 = &42;
let closure = || some_function(/* Implicit `&*` reborrow here? */ x);If there is no reborrow, we capture x by reference. But if there is one, with edition 2021 precise capturing, we capture *x by reference, which is equivalent to capturing x by value.
View all comments
Except inside closures, where we need to keep capture inference stable. Gets rid of MIR bloat, and improves diagnostics.
See also #163717 (would allow doing this even inside closures), #163494 (would allow doing this for mutable references outside closures).
r? compiler
@rustbot label A-coercions