Skip to content

Commit a5a286d

Browse files
Rollup merge of #154297 - RalfJung:mir-opt-comments, r=dianqk
fix/extend some mir-opt comments Looks like CopyProp was refactored without updating that comment. And for GVN, I think this is what you had in mind @cjgillot but would be great if you could have a look.
2 parents fad2a35 + fb2b003 commit a5a286d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

compiler/rustc_mir_transform/src/copy_prop.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ impl<'tcx> crate::MirPass<'tcx> for CopyProp {
5858
}
5959
}
6060

61-
/// Utility to help performing substitution of `*pattern` by `target`.
61+
/// Utility to help performing substitution: for all key-value pairs in `copy_classes`,
62+
/// all occurrences of the key get replaced by the value.
6263
struct Replacer<'a, 'tcx> {
6364
tcx: TyCtxt<'tcx>,
6465
unified: DenseBitSet<Local>,

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,15 @@
4848
//! # Handling of references
4949
//!
5050
//! We handle references by assigning a different "provenance" index to each Ref/RawPtr rvalue.
51-
//! This ensure that we do not spuriously merge borrows that should not be merged. Meanwhile, we
52-
//! consider all the derefs of an immutable reference to a freeze type to give the same value:
51+
//! This ensure that we do not spuriously merge borrows that should not be merged. For instance:
52+
//! ```ignore (MIR)
53+
//! _x = &_a;
54+
//! _a = 0;
55+
//! _y = &_a; // cannot be turned into `_y = _x`!
56+
//! ```
57+
//!
58+
//! On top of that, we consider all the derefs of an immutable reference to a freeze type to give
59+
//! the same value:
5360
//! ```ignore (MIR)
5461
//! _a = *_b // _b is &Freeze
5562
//! _c = *_b // replaced by _c = _a

0 commit comments

Comments
 (0)