Skip to content

Commit 905e968

Browse files
committed
Once we found a use of the head that is maybe dead, don't check it again
1 parent d24d035 commit 905e968

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

compiler/rustc_mir_transform/src/copy_prop.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,14 @@ struct StorageChecker<'a, 'tcx> {
212212

213213
impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> {
214214
fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) {
215-
let head = self.copy_classes[local];
215+
if !context.is_use() {
216+
return;
217+
}
216218

217-
if context.is_use() && self.head_storage_to_check.contains(head) {
219+
let head = self.copy_classes[local];
220+
if self.head_storage_to_check.contains(head) {
218221
self.maybe_storage_dead.seek_after_primary_effect(location);
222+
219223
if self.maybe_storage_dead.get().contains(head) {
220224
debug!(
221225
?location,
@@ -224,6 +228,9 @@ impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> {
224228
"found use of local with head at a location in which head is maybe dead, marking head for storage removal"
225229
);
226230
self.storage_to_remove.insert(head);
231+
232+
// Once we found a use of the head that is maybe dead, we do not need to check it again.
233+
self.head_storage_to_check.remove(head);
227234
}
228235
}
229236
}

0 commit comments

Comments
 (0)