Skip to content

Commit 7cde4ab

Browse files
committed
Revert "Reduce the number of drop-flag assignments in unwind paths"
This reverts commit 54aa418.
1 parent 336d812 commit 7cde4ab

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

src/librustc_mir/dataflow/move_paths/builder.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,17 @@ 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
366365
| TerminatorKind::Resume
367366
| TerminatorKind::Abort
368367
| TerminatorKind::GeneratorDrop
369368
| TerminatorKind::FalseEdges { .. }
370369
| TerminatorKind::FalseUnwind { .. }
371370
| TerminatorKind::Unreachable => {}
372371

372+
TerminatorKind::Return => {
373+
self.gather_move(Place::return_place());
374+
}
375+
373376
TerminatorKind::Assert { ref cond, .. } => {
374377
self.gather_operand(cond);
375378
}

src/librustc_mir/util/elaborate_drops.rs

+35-11
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ where
233233
.patch_terminator(bb, TerminatorKind::Goto { target: self.succ });
234234
}
235235
DropStyle::Static => {
236+
let loc = self.terminator_loc(bb);
237+
self.elaborator.clear_drop_flag(loc, self.path, DropFlagMode::Deep);
236238
self.elaborator.patch().patch_terminator(
237239
bb,
238240
TerminatorKind::Drop {
@@ -243,7 +245,9 @@ where
243245
);
244246
}
245247
DropStyle::Conditional => {
246-
let drop_bb = self.complete_drop(self.succ, self.unwind);
248+
let unwind = self.unwind; // FIXME(#43234)
249+
let succ = self.succ;
250+
let drop_bb = self.complete_drop(Some(DropFlagMode::Deep), succ, unwind);
247251
self.elaborator
248252
.patch()
249253
.patch_terminator(bb, TerminatorKind::Goto { target: drop_bb });
@@ -315,7 +319,7 @@ where
315319
// our own drop flag.
316320
path: self.path,
317321
}
318-
.complete_drop(succ, unwind)
322+
.complete_drop(None, succ, unwind)
319323
}
320324
}
321325

@@ -344,7 +348,13 @@ where
344348
// Clear the "master" drop flag at the end. This is needed
345349
// because the "master" drop protects the ADT's discriminant,
346350
// which is invalidated after the ADT is dropped.
347-
(self.drop_flag_reset_block(DropFlagMode::Shallow, self.succ, self.unwind), self.unwind)
351+
let (succ, unwind) = (self.succ, self.unwind); // FIXME(#43234)
352+
(
353+
self.drop_flag_reset_block(DropFlagMode::Shallow, succ, unwind),
354+
unwind.map(|unwind| {
355+
self.drop_flag_reset_block(DropFlagMode::Shallow, unwind, Unwind::InCleanup)
356+
}),
357+
)
348358
}
349359

350360
/// Creates a full drop ladder, consisting of 2 connected half-drop-ladders
@@ -878,7 +888,11 @@ where
878888
self.open_drop_for_adt(def, substs)
879889
}
880890
}
881-
ty::Dynamic(..) => self.complete_drop(self.succ, self.unwind),
891+
ty::Dynamic(..) => {
892+
let unwind = self.unwind; // FIXME(#43234)
893+
let succ = self.succ;
894+
self.complete_drop(Some(DropFlagMode::Deep), succ, unwind)
895+
}
882896
ty::Array(ety, size) => {
883897
let size = size.try_eval_usize(self.tcx(), self.elaborator.param_env());
884898
self.open_drop_for_array(ety, size)
@@ -889,10 +903,20 @@ where
889903
}
890904
}
891905

892-
fn complete_drop(&mut self, succ: BasicBlock, unwind: Unwind) -> BasicBlock {
893-
debug!("complete_drop(succ={:?}, unwind={:?})", succ, unwind);
906+
fn complete_drop(
907+
&mut self,
908+
drop_mode: Option<DropFlagMode>,
909+
succ: BasicBlock,
910+
unwind: Unwind,
911+
) -> BasicBlock {
912+
debug!("complete_drop({:?},{:?})", self, drop_mode);
894913

895914
let drop_block = self.drop_block(succ, unwind);
915+
let drop_block = if let Some(mode) = drop_mode {
916+
self.drop_flag_reset_block(mode, drop_block, unwind)
917+
} else {
918+
drop_block
919+
};
896920

897921
self.drop_flag_test_block(drop_block, succ, unwind)
898922
}
@@ -907,11 +931,6 @@ where
907931
) -> BasicBlock {
908932
debug!("drop_flag_reset_block({:?},{:?})", self, mode);
909933

910-
if unwind.is_cleanup() {
911-
// The drop flag isn't read again on the unwind path, so don't
912-
// bother setting it.
913-
return succ;
914-
}
915934
let block = self.new_block(unwind, TerminatorKind::Goto { target: succ });
916935
let block_start = Location { block, statement_index: 0 };
917936
self.elaborator.clear_drop_flag(block_start, self.path, mode);
@@ -1028,6 +1047,11 @@ where
10281047
self.elaborator.patch().new_temp(ty, self.source_info.span)
10291048
}
10301049

1050+
fn terminator_loc(&mut self, bb: BasicBlock) -> Location {
1051+
let body = self.elaborator.body();
1052+
self.elaborator.patch().terminator_loc(body, bb)
1053+
}
1054+
10311055
fn constant_usize(&self, val: u16) -> Operand<'tcx> {
10321056
Operand::Constant(box Constant {
10331057
span: self.source_info.span,

0 commit comments

Comments
 (0)