Skip to content

Commit 7150036

Browse files
Move TerminatorKind::Drop trans to mir::statement.
1 parent 1702c22 commit 7150036

File tree

2 files changed

+75
-68
lines changed

2 files changed

+75
-68
lines changed

src/librustc_trans/mir/block.rs

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@
99
// except according to those terms.
1010

1111
use llvm::{ValueRef, BasicBlockRef};
12-
use rustc::ty;
1312
use rustc::mir;
1413
use rustc::middle::const_val::ConstInt;
1514
use base::{self, Lifetime};
16-
use callee;
1715
use builder::Builder;
1816
use common::Funclet;
19-
use common::C_uint;
2017
use machine::llalign_of_min;
21-
use meth;
22-
use monomorphize;
23-
use tvec;
2418
use type_::Type;
2519

2620
use rustc_data_structures::indexed_vec::IndexVec;
@@ -198,67 +192,9 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
198192
}
199193

200194
mir::TerminatorKind::Drop { ref location, target, unwind } => {
201-
let ty = location.ty(&self.mir, bcx.tcx()).to_ty(bcx.tcx());
202-
let ty = self.monomorphize(&ty);
203-
let drop_fn = monomorphize::resolve_drop_in_place(bcx.ccx.shared(), ty);
204-
205-
if let ty::InstanceDef::DropGlue(_, None) = drop_fn.def {
206-
// we don't actually need to drop anything.
207-
funclet_br(self, bcx, target);
208-
return
209-
}
210-
211-
let lvalue = self.trans_lvalue(&bcx, location);
212-
let (drop_fn, need_extra) = match ty.sty {
213-
ty::TyDynamic(..) => (meth::DESTRUCTOR.get_fn(&bcx, lvalue.llextra),
214-
false),
215-
ty::TyArray(ety, _) | ty::TySlice(ety) => {
216-
// FIXME: handle panics
217-
let drop_fn = monomorphize::resolve_drop_in_place(
218-
bcx.ccx.shared(), ety);
219-
let drop_fn = callee::get_fn(bcx.ccx, drop_fn);
220-
let bcx = tvec::slice_for_each(
221-
&bcx,
222-
lvalue.project_index(&bcx, C_uint(bcx.ccx, 0u64)),
223-
ety,
224-
lvalue.len(bcx.ccx),
225-
|mut bcx, llval, loop_bb| {
226-
self.set_debug_loc(&bcx, terminator.source_info);
227-
if let Some(unwind) = unwind {
228-
let old_bcx = bcx;
229-
bcx = old_bcx.build_sibling_block("drop-next");
230-
old_bcx.invoke(
231-
drop_fn,
232-
&[llval],
233-
bcx.llbb(),
234-
self.landing_pad_to(unwind),
235-
cleanup_bundle
236-
);
237-
} else {
238-
bcx.call(drop_fn, &[llval], cleanup_bundle);
239-
}
240-
bcx.br(loop_bb);
241-
bcx
242-
});
243-
funclet_br(self, bcx, target);
244-
return
245-
}
246-
_ => (callee::get_fn(bcx.ccx, drop_fn), lvalue.has_extra())
247-
};
248-
let args = &[lvalue.llval, lvalue.llextra][..1 + need_extra as usize];
249-
if let Some(unwind) = unwind {
250-
let old_bcx = bcx;
251-
bcx = old_bcx.build_sibling_block("drop-next");
252-
old_bcx.invoke(
253-
drop_fn,
254-
args,
255-
bcx.llbb(),
256-
self.landing_pad_to(unwind),
257-
cleanup_bundle
258-
);
259-
} else {
260-
bcx.call(drop_fn, args, cleanup_bundle);
261-
}
195+
bcx = self.trans_drop(
196+
bcx, location, unwind, cleanup_bundle, terminator.source_info
197+
);
262198
funclet_br(self, bcx, target);
263199
}
264200

src/librustc_trans/mir/statement.rs

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ use rustc::middle::lang_items;
1616

1717
use base;
1818
use asm;
19-
use common::{self, C_bool, C_str_slice, C_u32, C_struct, C_undef};
19+
use common::{self, C_bool, C_str_slice, C_u32, C_struct, C_undef, C_uint};
2020
use builder::Builder;
2121
use syntax::symbol::Symbol;
2222
use machine::llalign_of_min;
2323
use consts;
2424
use callee;
2525
use monomorphize;
2626
use meth;
27+
use tvec;
2728
use abi::{Abi, FnType, ArgType};
2829
use type_::Type;
2930
use type_of::{self, align_of};
@@ -251,6 +252,76 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
251252
success_block
252253
}
253254

255+
pub fn trans_drop(
256+
&mut self,
257+
mut bcx: Builder<'a, 'tcx>,
258+
location: &mir::Lvalue<'tcx>,
259+
unwind: Option<mir::Block>,
260+
cleanup_bundle: Option<&OperandBundleDef>,
261+
source_info: mir::SourceInfo,
262+
) -> Builder<'a, 'tcx> {
263+
let ty = location.ty(&self.mir, bcx.tcx()).to_ty(bcx.tcx());
264+
let ty = self.monomorphize(&ty);
265+
let drop_fn = monomorphize::resolve_drop_in_place(bcx.ccx.shared(), ty);
266+
267+
if let ty::InstanceDef::DropGlue(_, None) = drop_fn.def {
268+
// we don't actually need to drop anything.
269+
return bcx;
270+
}
271+
272+
let lvalue = self.trans_lvalue(&bcx, location);
273+
let (drop_fn, need_extra) = match ty.sty {
274+
ty::TyDynamic(..) => (meth::DESTRUCTOR.get_fn(&bcx, lvalue.llextra),
275+
false),
276+
ty::TyArray(ety, _) | ty::TySlice(ety) => {
277+
// FIXME: handle panics
278+
let drop_fn = monomorphize::resolve_drop_in_place(
279+
bcx.ccx.shared(), ety);
280+
let drop_fn = callee::get_fn(bcx.ccx, drop_fn);
281+
return tvec::slice_for_each(
282+
&bcx,
283+
lvalue.project_index(&bcx, C_uint(bcx.ccx, 0u64)),
284+
ety,
285+
lvalue.len(bcx.ccx),
286+
|mut bcx, llval, loop_bb| {
287+
self.set_debug_loc(&bcx, source_info);
288+
if let Some(unwind) = unwind {
289+
let old_bcx = bcx;
290+
bcx = old_bcx.build_sibling_block("drop-next");
291+
old_bcx.invoke(
292+
drop_fn,
293+
&[llval],
294+
bcx.llbb(),
295+
self.landing_pad_to(unwind),
296+
cleanup_bundle
297+
);
298+
} else {
299+
bcx.call(drop_fn, &[llval], cleanup_bundle);
300+
}
301+
bcx.br(loop_bb);
302+
bcx
303+
});
304+
}
305+
_ => (callee::get_fn(bcx.ccx, drop_fn), lvalue.has_extra())
306+
};
307+
let args = &[lvalue.llval, lvalue.llextra][..1 + need_extra as usize];
308+
if let Some(unwind) = unwind {
309+
let old_bcx = bcx;
310+
bcx = old_bcx.build_sibling_block("drop-next");
311+
old_bcx.invoke(
312+
drop_fn,
313+
args,
314+
bcx.llbb(),
315+
self.landing_pad_to(unwind),
316+
cleanup_bundle
317+
);
318+
} else {
319+
bcx.call(drop_fn, args, cleanup_bundle);
320+
}
321+
322+
bcx
323+
}
324+
254325
pub fn trans_call(
255326
&mut self,
256327
mut bcx: Builder<'a, 'tcx>,

0 commit comments

Comments
 (0)