Skip to content

Commit

Permalink
Auto merge of #34290 - arielb1:short-ladder, r=eddyb
Browse files Browse the repository at this point in the history
don't generate drop ladder steps for fields that don't need dropping

cc @eddyb

This should help with #34166
  • Loading branch information
bors authored Jun 16, 2016
2 parents 7339eca + 68129a6 commit a479a6a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
21 changes: 15 additions & 6 deletions src/librustc_borrowck/borrowck/mir/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,17 +548,26 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
/// ELAB(drop location.2 [target=`c.unwind])
fn drop_ladder<'a>(&mut self,
c: &DropCtxt<'a, 'tcx>,
fields: &[(Lvalue<'tcx>, Option<MovePathIndex>)])
fields: Vec<(Lvalue<'tcx>, Option<MovePathIndex>)>)
-> BasicBlock
{
debug!("drop_ladder({:?}, {:?})", c, fields);

let mut fields = fields;
fields.retain(|&(ref lvalue, _)| {
let ty = self.mir.lvalue_ty(self.tcx, lvalue).to_ty(self.tcx);
self.tcx.type_needs_drop_given_env(ty, self.param_env())
});

debug!("drop_ladder - fields needing drop: {:?}", fields);

let unwind_ladder = if c.is_cleanup {
None
} else {
Some(self.drop_halfladder(c, None, c.unwind.unwrap(), &fields, true))
};

self.drop_halfladder(c, unwind_ladder, c.succ, fields, c.is_cleanup)
self.drop_halfladder(c, unwind_ladder, c.succ, &fields, c.is_cleanup)
.last().cloned().unwrap_or(c.succ)
}

Expand All @@ -567,7 +576,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
{
debug!("open_drop_for_tuple({:?}, {:?})", c, tys);

let fields: Vec<_> = tys.iter().enumerate().map(|(i, &ty)| {
let fields = tys.iter().enumerate().map(|(i, &ty)| {
(c.lvalue.clone().field(Field::new(i), ty),
super::move_path_children_matching(
&self.move_data().move_paths, c.path, |proj| match proj {
Expand All @@ -579,7 +588,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
))
}).collect();

self.drop_ladder(c, &fields)
self.drop_ladder(c, fields)
}

fn open_drop_for_box<'a>(&mut self, c: &DropCtxt<'a, 'tcx>, ty: Ty<'tcx>)
Expand Down Expand Up @@ -634,7 +643,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
variant_path,
&adt.variants[variant_index],
substs);
self.drop_ladder(c, &fields)
self.drop_ladder(c, fields)
} else {
// variant not found - drop the entire enum
if let None = *drop_block {
Expand All @@ -659,7 +668,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
&adt.variants[0],
substs
);
self.drop_ladder(c, &fields)
self.drop_ladder(c, fields)
}
_ => {
let variant_drops : Vec<BasicBlock> =
Expand Down
2 changes: 0 additions & 2 deletions src/test/codegen-units/item-collection/generic-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,3 @@ fn main() {
//~ TRANS_ITEM fn generic_impl::id[0]<generic_impl::Struct[0]<&str>>
let _ = (Struct::new(Struct::new("str")).f)(Struct::new("str"));
}

//~ TRANS_ITEM drop-glue i8

0 comments on commit a479a6a

Please sign in to comment.