Skip to content

Commit 15955df

Browse files
trans: Make glue::get_drop_glue_type() independent of CrateContext.
1 parent bf674ec commit 15955df

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

src/librustc_trans/collector.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(ccx: &CrateContext<'a, 'tcx>,
390390
TransItem::Static(node_id) => {
391391
let def_id = ccx.tcx().map.local_def_id(node_id);
392392
let ty = ccx.tcx().lookup_item_type(def_id).ty;
393-
let ty = glue::get_drop_glue_type(ccx, ty);
393+
let ty = glue::get_drop_glue_type(ccx.tcx(), ty);
394394
neighbors.push(TransItem::DropGlue(DropGlueKind::Ty(ty)));
395395
recursion_depth_reset = None;
396396
}
@@ -551,7 +551,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
551551
self.param_substs,
552552
&ty);
553553
let ty = self.ccx.tcx().erase_regions(&ty);
554-
let ty = glue::get_drop_glue_type(self.ccx, ty);
554+
let ty = glue::get_drop_glue_type(self.ccx.tcx(), ty);
555555
self.output.push(TransItem::DropGlue(DropGlueKind::Ty(ty)));
556556
}
557557

@@ -737,7 +737,7 @@ fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
737737
let field_type = monomorphize::apply_param_substs(ccx.tcx(),
738738
substs,
739739
&field.unsubst_ty());
740-
let field_type = glue::get_drop_glue_type(ccx, field_type);
740+
let field_type = glue::get_drop_glue_type(ccx.tcx(), field_type);
741741

742742
if glue::type_needs_drop(ccx.tcx(), field_type) {
743743
output.push(TransItem::DropGlue(DropGlueKind::Ty(field_type)));
@@ -746,22 +746,22 @@ fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
746746
}
747747
ty::TyClosure(_, ref substs) => {
748748
for upvar_ty in &substs.upvar_tys {
749-
let upvar_ty = glue::get_drop_glue_type(ccx, upvar_ty);
749+
let upvar_ty = glue::get_drop_glue_type(ccx.tcx(), upvar_ty);
750750
if glue::type_needs_drop(ccx.tcx(), upvar_ty) {
751751
output.push(TransItem::DropGlue(DropGlueKind::Ty(upvar_ty)));
752752
}
753753
}
754754
}
755755
ty::TyBox(inner_type) |
756756
ty::TyArray(inner_type, _) => {
757-
let inner_type = glue::get_drop_glue_type(ccx, inner_type);
757+
let inner_type = glue::get_drop_glue_type(ccx.tcx(), inner_type);
758758
if glue::type_needs_drop(ccx.tcx(), inner_type) {
759759
output.push(TransItem::DropGlue(DropGlueKind::Ty(inner_type)));
760760
}
761761
}
762762
ty::TyTuple(ref args) => {
763763
for arg in args {
764-
let arg = glue::get_drop_glue_type(ccx, arg);
764+
let arg = glue::get_drop_glue_type(ccx.tcx(), arg);
765765
if glue::type_needs_drop(ccx.tcx(), arg) {
766766
output.push(TransItem::DropGlue(DropGlueKind::Ty(arg)));
767767
}
@@ -1076,7 +1076,7 @@ impl<'b, 'a, 'v> hir_visit::Visitor<'v> for RootCollector<'b, 'a, 'v> {
10761076
def_id_to_string(self.ccx.tcx(),
10771077
self.ccx.tcx().map.local_def_id(item.id)));
10781078

1079-
let ty = glue::get_drop_glue_type(self.ccx, ty);
1079+
let ty = glue::get_drop_glue_type(self.ccx.tcx(), ty);
10801080
self.output.push(TransItem::DropGlue(DropGlueKind::Ty(ty)));
10811081
}
10821082
}

src/librustc_trans/glue.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use llvm;
1919
use llvm::{ValueRef, get_param};
2020
use middle::lang_items::ExchangeFreeFnLangItem;
2121
use rustc::ty::subst::{Substs};
22-
use rustc::traits;
22+
use rustc::{infer, traits};
2323
use rustc::ty::{self, Ty, TyCtxt};
2424
use abi::{Abi, FnType};
2525
use adt;
@@ -92,13 +92,12 @@ pub fn type_needs_drop<'tcx>(tcx: &TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
9292
tcx.type_needs_drop_given_env(ty, &tcx.empty_parameter_environment())
9393
}
9494

95-
pub fn get_drop_glue_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
96-
t: Ty<'tcx>) -> Ty<'tcx> {
97-
let tcx = ccx.tcx();
95+
pub fn get_drop_glue_type<'tcx>(tcx: &TyCtxt<'tcx>,
96+
t: Ty<'tcx>) -> Ty<'tcx> {
9897
// Even if there is no dtor for t, there might be one deeper down and we
9998
// might need to pass in the vtable ptr.
10099
if !type_is_sized(tcx, t) {
101-
return ccx.tcx().erase_regions(&t);
100+
return tcx.erase_regions(&t);
102101
}
103102

104103
// FIXME (#22815): note that type_needs_drop conservatively
@@ -116,15 +115,18 @@ pub fn get_drop_glue_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
116115
match t.sty {
117116
ty::TyBox(typ) if !type_needs_drop(&tcx, typ)
118117
&& type_is_sized(tcx, typ) => {
119-
let llty = sizing_type_of(ccx, typ);
120-
// `Box<ZeroSizeType>` does not allocate.
121-
if llsize_of_alloc(ccx, llty) == 0 {
118+
let infcx = infer::normalizing_infer_ctxt(tcx,
119+
&tcx.tables,
120+
traits::ProjectionMode::Any);
121+
let layout = t.layout(&infcx).unwrap();
122+
if layout.size(&tcx.data_layout).bytes() == 0 {
123+
// `Box<ZeroSizeType>` does not allocate.
122124
tcx.types.i8
123125
} else {
124-
ccx.tcx().erase_regions(&t)
126+
tcx.erase_regions(&t)
125127
}
126128
}
127-
_ => ccx.tcx().erase_regions(&t)
129+
_ => tcx.erase_regions(&t)
128130
}
129131
}
130132

@@ -154,7 +156,7 @@ pub fn drop_ty_core<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
154156
DropGlueKind::Ty(t)
155157
};
156158
let glue = get_drop_glue_core(ccx, g);
157-
let glue_type = get_drop_glue_type(ccx, t);
159+
let glue_type = get_drop_glue_type(ccx.tcx(), t);
158160
let ptr = if glue_type != t {
159161
PointerCast(bcx, v, type_of(ccx, glue_type).ptr_to())
160162
} else {
@@ -231,7 +233,7 @@ impl<'tcx> DropGlueKind<'tcx> {
231233
fn get_drop_glue_core<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
232234
g: DropGlueKind<'tcx>) -> ValueRef {
233235
debug!("make drop glue for {:?}", g);
234-
let g = g.map_ty(|t| get_drop_glue_type(ccx, t));
236+
let g = g.map_ty(|t| get_drop_glue_type(ccx.tcx(), t));
235237
debug!("drop glue type {:?}", g);
236238
match ccx.drop_glues().borrow().get(&g) {
237239
Some(&glue) => return glue,

src/librustc_trans/mir/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
135135
return;
136136
}
137137
let drop_fn = glue::get_drop_glue(bcx.ccx(), ty);
138-
let drop_ty = glue::get_drop_glue_type(bcx.ccx(), ty);
138+
let drop_ty = glue::get_drop_glue_type(bcx.tcx(), ty);
139139
let llvalue = if drop_ty != ty {
140140
bcx.pointercast(lvalue.llval, type_of::type_of(bcx.ccx(), drop_ty).ptr_to())
141141
} else {

0 commit comments

Comments
 (0)