Skip to content

Commit b766abc

Browse files
committed
Simplify unscheduling of drops after moves
1 parent 2218520 commit b766abc

File tree

1 file changed

+22
-30
lines changed
  • compiler/rustc_mir_build/src/build

1 file changed

+22
-30
lines changed

compiler/rustc_mir_build/src/build/scope.rs

+22-30
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ struct Scope {
121121
/// end of the vector (top of the stack) first.
122122
drops: Vec<DropData>,
123123

124-
moved_locals: Vec<Local>,
125-
126124
/// The drop index that will drop everything in and below this scope on an
127125
/// unwind path.
128126
cached_unwind_block: Option<DropIdx>,
@@ -406,7 +404,6 @@ impl<'tcx> Scopes<'tcx> {
406404
region_scope: region_scope.0,
407405
region_scope_span: region_scope.1.span,
408406
drops: vec![],
409-
moved_locals: vec![],
410407
cached_unwind_block: None,
411408
cached_generator_drop_block: None,
412409
});
@@ -904,29 +901,32 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
904901
return;
905902
}
906903

907-
Some(local_scope) => self
908-
.scopes
909-
.scopes
910-
.iter_mut()
911-
.rfind(|scope| scope.region_scope == local_scope)
912-
.unwrap_or_else(|| bug!("scope {:?} not found in scope list!", local_scope)),
904+
Some(local_scope) => {
905+
let top_scope = self.scopes.scopes.last_mut().unwrap();
906+
assert!(
907+
top_scope.region_scope == local_scope,
908+
"local scope ({:?}) is not the topmost scope!",
909+
local_scope
910+
);
911+
912+
top_scope
913+
}
913914
};
914915

915916
// look for moves of a local variable, like `MOVE(_X)`
916-
let locals_moved = operands.iter().flat_map(|operand| match operand {
917-
Operand::Copy(_) | Operand::Constant(_) => None,
918-
Operand::Move(place) => place.as_local(),
919-
});
917+
let locals_moved = operands
918+
.iter()
919+
.filter_map(|operand| match operand {
920+
Operand::Copy(_) | Operand::Constant(_) => None,
921+
Operand::Move(place) => place.as_local(),
922+
})
923+
.collect::<FxHashSet<_>>();
920924

921-
for local in locals_moved {
922-
// check if we have a Drop for this operand and -- if so
923-
// -- add it to the list of moved operands. Note that this
924-
// local might not have been an operand created for this
925-
// call, it could come from other places too.
926-
if scope.drops.iter().any(|drop| drop.local == local && drop.kind == DropKind::Value) {
927-
scope.moved_locals.push(local);
928-
}
929-
}
925+
// Remove the drops for the moved operands.
926+
scope
927+
.drops
928+
.retain(|drop| drop.kind == DropKind::Storage || !locals_moved.contains(&drop.local));
929+
scope.invalidate_cache();
930930
}
931931

932932
// Other
@@ -1174,14 +1174,6 @@ fn build_scope_drops<'tcx>(
11741174
debug_assert_eq!(unwind_drops.drops[unwind_to].0.kind, drop_data.kind);
11751175
unwind_to = unwind_drops.drops[unwind_to].1;
11761176

1177-
// If the operand has been moved, and we are not on an unwind
1178-
// path, then don't generate the drop. (We only take this into
1179-
// account for non-unwind paths so as not to disturb the
1180-
// caching mechanism.)
1181-
if scope.moved_locals.iter().any(|&o| o == local) {
1182-
continue;
1183-
}
1184-
11851177
unwind_drops.add_entry(block, unwind_to);
11861178

11871179
let next = cfg.start_new_block();

0 commit comments

Comments
 (0)