-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rustc_mir_transform
cleanups 3
#130175
rustc_mir_transform
cleanups 3
#130175
Changes from all commits
8235af0
48064d4
baa16d2
e26692d
51e1c39
d1c55a3
7023402
8949b44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,37 +27,34 @@ impl<'tcx> crate::MirPass<'tcx> for CopyProp { | |
#[instrument(level = "trace", skip(self, tcx, body))] | ||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { | ||
debug!(def_id = ?body.source.def_id()); | ||
propagate_ssa(tcx, body); | ||
} | ||
} | ||
|
||
fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { | ||
let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id()); | ||
let ssa = SsaLocals::new(tcx, body, param_env); | ||
let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id()); | ||
let ssa = SsaLocals::new(tcx, body, param_env); | ||
|
||
let fully_moved = fully_moved_locals(&ssa, body); | ||
debug!(?fully_moved); | ||
let fully_moved = fully_moved_locals(&ssa, body); | ||
debug!(?fully_moved); | ||
|
||
let mut storage_to_remove = BitSet::new_empty(fully_moved.domain_size()); | ||
for (local, &head) in ssa.copy_classes().iter_enumerated() { | ||
if local != head { | ||
storage_to_remove.insert(head); | ||
let mut storage_to_remove = BitSet::new_empty(fully_moved.domain_size()); | ||
for (local, &head) in ssa.copy_classes().iter_enumerated() { | ||
if local != head { | ||
storage_to_remove.insert(head); | ||
} | ||
} | ||
} | ||
|
||
let any_replacement = ssa.copy_classes().iter_enumerated().any(|(l, &h)| l != h); | ||
let any_replacement = ssa.copy_classes().iter_enumerated().any(|(l, &h)| l != h); | ||
|
||
Replacer { | ||
tcx, | ||
copy_classes: ssa.copy_classes(), | ||
fully_moved, | ||
borrowed_locals: ssa.borrowed_locals(), | ||
storage_to_remove, | ||
} | ||
.visit_body_preserves_cfg(body); | ||
Replacer { | ||
tcx, | ||
copy_classes: ssa.copy_classes(), | ||
fully_moved, | ||
borrowed_locals: ssa.borrowed_locals(), | ||
storage_to_remove, | ||
} | ||
.visit_body_preserves_cfg(body); | ||
|
||
if any_replacement { | ||
crate::simplify::remove_unused_definitions(body); | ||
if any_replacement { | ||
crate::simplify::remove_unused_definitions(body); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -140,7 +137,8 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> { | |
|
||
fn visit_operand(&mut self, operand: &mut Operand<'tcx>, loc: Location) { | ||
if let Operand::Move(place) = *operand | ||
// A move out of a projection of a copy is equivalent to a copy of the original projection. | ||
// A move out of a projection of a copy is equivalent to a copy of the original | ||
// projection. | ||
Comment on lines
+140
to
+141
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: These single-word reflows are a bit awkward. For single-line comments that don't quite fit in 100 columns, I'd consider breaking them even earlier (closer to 80 columns) just so that the second line is a bit longer. (But if you're using automation to do this then maybe it's not worth the extra effort. 🤷♂️) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just reflowed them all to width 100, because that's the closest I could get to the original while observing the "don't exceed 100 chars" rule. I definitely don't want to be thinking about different widths for different comments depending on their contents. One word on a line by itself is fine. |
||
&& !place.is_indirect_first_projection() | ||
&& !self.fully_moved.contains(place.local) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My kingdom for a code review tool that can ignore this diff