Skip to content

Commit f810e60

Browse files
matthewjasperAaron1011
authored andcommitted
Reduce the number of drop-flag assignments in unwind paths
1 parent fa3e2fc commit f810e60

File tree

2 files changed

+12
-39
lines changed

2 files changed

+12
-39
lines changed

compiler/rustc_mir/src/dataflow/move_paths/builder.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -362,17 +362,14 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
362362
fn gather_terminator(&mut self, term: &Terminator<'tcx>) {
363363
match term.kind {
364364
TerminatorKind::Goto { target: _ }
365+
| TerminatorKind::Return
365366
| TerminatorKind::Resume
366367
| TerminatorKind::Abort
367368
| TerminatorKind::GeneratorDrop
368369
| TerminatorKind::FalseEdge { .. }
369370
| TerminatorKind::FalseUnwind { .. }
370371
| TerminatorKind::Unreachable => {}
371372

372-
TerminatorKind::Return => {
373-
self.gather_move(Place::return_place());
374-
}
375-
376373
TerminatorKind::Assert { ref cond, .. } => {
377374
self.gather_operand(cond);
378375
}

compiler/rustc_mir/src/util/elaborate_drops.rs

+11-35
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,6 @@ where
231231
.patch_terminator(bb, TerminatorKind::Goto { target: self.succ });
232232
}
233233
DropStyle::Static => {
234-
let loc = self.terminator_loc(bb);
235-
self.elaborator.clear_drop_flag(loc, self.path, DropFlagMode::Deep);
236234
self.elaborator.patch().patch_terminator(
237235
bb,
238236
TerminatorKind::Drop {
@@ -243,9 +241,7 @@ where
243241
);
244242
}
245243
DropStyle::Conditional => {
246-
let unwind = self.unwind; // FIXME(#43234)
247-
let succ = self.succ;
248-
let drop_bb = self.complete_drop(Some(DropFlagMode::Deep), succ, unwind);
244+
let drop_bb = self.complete_drop(self.succ, self.unwind);
249245
self.elaborator
250246
.patch()
251247
.patch_terminator(bb, TerminatorKind::Goto { target: drop_bb });
@@ -317,7 +313,7 @@ where
317313
// our own drop flag.
318314
path: self.path,
319315
}
320-
.complete_drop(None, succ, unwind)
316+
.complete_drop(succ, unwind)
321317
}
322318
}
323319

@@ -346,13 +342,7 @@ where
346342
// Clear the "master" drop flag at the end. This is needed
347343
// because the "master" drop protects the ADT's discriminant,
348344
// which is invalidated after the ADT is dropped.
349-
let (succ, unwind) = (self.succ, self.unwind); // FIXME(#43234)
350-
(
351-
self.drop_flag_reset_block(DropFlagMode::Shallow, succ, unwind),
352-
unwind.map(|unwind| {
353-
self.drop_flag_reset_block(DropFlagMode::Shallow, unwind, Unwind::InCleanup)
354-
}),
355-
)
345+
(self.drop_flag_reset_block(DropFlagMode::Shallow, self.succ, self.unwind), self.unwind)
356346
}
357347

358348
/// Creates a full drop ladder, consisting of 2 connected half-drop-ladders
@@ -884,11 +874,7 @@ where
884874
self.open_drop_for_adt(def, substs)
885875
}
886876
}
887-
ty::Dynamic(..) => {
888-
let unwind = self.unwind; // FIXME(#43234)
889-
let succ = self.succ;
890-
self.complete_drop(Some(DropFlagMode::Deep), succ, unwind)
891-
}
877+
ty::Dynamic(..) => self.complete_drop(self.succ, self.unwind),
892878
ty::Array(ety, size) => {
893879
let size = size.try_eval_usize(self.tcx(), self.elaborator.param_env());
894880
self.open_drop_for_array(ety, size)
@@ -899,20 +885,10 @@ where
899885
}
900886
}
901887

902-
fn complete_drop(
903-
&mut self,
904-
drop_mode: Option<DropFlagMode>,
905-
succ: BasicBlock,
906-
unwind: Unwind,
907-
) -> BasicBlock {
908-
debug!("complete_drop({:?},{:?})", self, drop_mode);
888+
fn complete_drop(&mut self, succ: BasicBlock, unwind: Unwind) -> BasicBlock {
889+
debug!("complete_drop(succ={:?}, unwind={:?})", succ, unwind);
909890

910891
let drop_block = self.drop_block(succ, unwind);
911-
let drop_block = if let Some(mode) = drop_mode {
912-
self.drop_flag_reset_block(mode, drop_block, unwind)
913-
} else {
914-
drop_block
915-
};
916892

917893
self.drop_flag_test_block(drop_block, succ, unwind)
918894
}
@@ -927,6 +903,11 @@ where
927903
) -> BasicBlock {
928904
debug!("drop_flag_reset_block({:?},{:?})", self, mode);
929905

906+
if unwind.is_cleanup() {
907+
// The drop flag isn't read again on the unwind path, so don't
908+
// bother setting it.
909+
return succ;
910+
}
930911
let block = self.new_block(unwind, TerminatorKind::Goto { target: succ });
931912
let block_start = Location { block, statement_index: 0 };
932913
self.elaborator.clear_drop_flag(block_start, self.path, mode);
@@ -1044,11 +1025,6 @@ where
10441025
self.elaborator.patch().new_temp(ty, self.source_info.span)
10451026
}
10461027

1047-
fn terminator_loc(&mut self, bb: BasicBlock) -> Location {
1048-
let body = self.elaborator.body();
1049-
self.elaborator.patch().terminator_loc(body, bb)
1050-
}
1051-
10521028
fn constant_usize(&self, val: u16) -> Operand<'tcx> {
10531029
Operand::Constant(box Constant {
10541030
span: self.source_info.span,

0 commit comments

Comments
 (0)