Skip to content

Commit 54aa418

Browse files
committedMay 9, 2020
Reduce the number of drop-flag assignments in unwind paths
1 parent 6119885 commit 54aa418

File tree

2 files changed

+12
-39
lines changed

2 files changed

+12
-39
lines changed
 

‎src/librustc_mir/dataflow/move_paths/builder.rs

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

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

‎src/librustc_mir/util/elaborate_drops.rs

+11-35
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ where
163163
.patch_terminator(bb, TerminatorKind::Goto { target: self.succ });
164164
}
165165
DropStyle::Static => {
166-
let loc = self.terminator_loc(bb);
167-
self.elaborator.clear_drop_flag(loc, self.path, DropFlagMode::Deep);
168166
self.elaborator.patch().patch_terminator(
169167
bb,
170168
TerminatorKind::Drop {
@@ -175,9 +173,7 @@ where
175173
);
176174
}
177175
DropStyle::Conditional => {
178-
let unwind = self.unwind; // FIXME(#43234)
179-
let succ = self.succ;
180-
let drop_bb = self.complete_drop(Some(DropFlagMode::Deep), succ, unwind);
176+
let drop_bb = self.complete_drop(self.succ, self.unwind);
181177
self.elaborator
182178
.patch()
183179
.patch_terminator(bb, TerminatorKind::Goto { target: drop_bb });
@@ -249,7 +245,7 @@ where
249245
// our own drop flag.
250246
path: self.path,
251247
}
252-
.complete_drop(None, succ, unwind)
248+
.complete_drop(succ, unwind)
253249
}
254250
}
255251

@@ -278,13 +274,7 @@ where
278274
// Clear the "master" drop flag at the end. This is needed
279275
// because the "master" drop protects the ADT's discriminant,
280276
// which is invalidated after the ADT is dropped.
281-
let (succ, unwind) = (self.succ, self.unwind); // FIXME(#43234)
282-
(
283-
self.drop_flag_reset_block(DropFlagMode::Shallow, succ, unwind),
284-
unwind.map(|unwind| {
285-
self.drop_flag_reset_block(DropFlagMode::Shallow, unwind, Unwind::InCleanup)
286-
}),
287-
)
277+
(self.drop_flag_reset_block(DropFlagMode::Shallow, self.succ, self.unwind), self.unwind)
288278
}
289279

290280
/// Creates a full drop ladder, consisting of 2 connected half-drop-ladders
@@ -820,11 +810,7 @@ where
820810
self.open_drop_for_adt(def, substs)
821811
}
822812
}
823-
ty::Dynamic(..) => {
824-
let unwind = self.unwind; // FIXME(#43234)
825-
let succ = self.succ;
826-
self.complete_drop(Some(DropFlagMode::Deep), succ, unwind)
827-
}
813+
ty::Dynamic(..) => self.complete_drop(self.succ, self.unwind),
828814
ty::Array(ety, size) => {
829815
let size = size.try_eval_usize(self.tcx(), self.elaborator.param_env());
830816
self.open_drop_for_array(ety, size)
@@ -835,20 +821,10 @@ where
835821
}
836822
}
837823

838-
fn complete_drop(
839-
&mut self,
840-
drop_mode: Option<DropFlagMode>,
841-
succ: BasicBlock,
842-
unwind: Unwind,
843-
) -> BasicBlock {
844-
debug!("complete_drop({:?},{:?})", self, drop_mode);
824+
fn complete_drop(&mut self, succ: BasicBlock, unwind: Unwind) -> BasicBlock {
825+
debug!("complete_drop(succ={:?}, unwind={:?})", succ, unwind);
845826

846827
let drop_block = self.drop_block(succ, unwind);
847-
let drop_block = if let Some(mode) = drop_mode {
848-
self.drop_flag_reset_block(mode, drop_block, unwind)
849-
} else {
850-
drop_block
851-
};
852828

853829
self.drop_flag_test_block(drop_block, succ, unwind)
854830
}
@@ -861,6 +837,11 @@ where
861837
) -> BasicBlock {
862838
debug!("drop_flag_reset_block({:?},{:?})", self, mode);
863839

840+
if unwind.is_cleanup() {
841+
// The drop flag isn't read again on the unwind path, so don't
842+
// bother setting it.
843+
return succ;
844+
}
864845
let block = self.new_block(unwind, TerminatorKind::Goto { target: succ });
865846
let block_start = Location { block, statement_index: 0 };
866847
self.elaborator.clear_drop_flag(block_start, self.path, mode);
@@ -969,11 +950,6 @@ where
969950
self.elaborator.patch().new_temp(ty, self.source_info.span)
970951
}
971952

972-
fn terminator_loc(&mut self, bb: BasicBlock) -> Location {
973-
let body = self.elaborator.body();
974-
self.elaborator.patch().terminator_loc(body, bb)
975-
}
976-
977953
fn constant_usize(&self, val: u16) -> Operand<'tcx> {
978954
Operand::Constant(box Constant {
979955
span: self.source_info.span,

0 commit comments

Comments
 (0)
Please sign in to comment.