use a more efficient vtable representation

[TyDesc, ... methods] -> [destructor, ... methods]
This commit is contained in:
Daniel Micay 2014-01-29 10:59:47 -05:00
parent 50bee30459
commit 383e3fd13b
3 changed files with 7 additions and 15 deletions
src/librustc/middle/trans

@ -367,17 +367,9 @@ fn make_drop_glue<'a>(bcx: &'a Block<'a>, v0: ValueRef, t: ty::t) -> &'a Block<'
let lluniquevalue = GEPi(bcx, v0, [0, abi::trt_field_box]);
// Only drop the value when it is non-null
with_cond(bcx, IsNotNull(bcx, Load(bcx, lluniquevalue)), |bcx| {
let llvtable = Load(bcx, GEPi(bcx, v0, [0, abi::trt_field_vtable]));
// Cast the vtable to a pointer to a pointer to a tydesc.
let llvtable = PointerCast(bcx, llvtable,
ccx.tydesc_type.ptr_to().ptr_to());
let lltydesc = Load(bcx, llvtable);
call_tydesc_glue_full(bcx,
lluniquevalue,
lltydesc,
abi::tydesc_field_drop_glue,
None);
let lldtor_ptr = Load(bcx, GEPi(bcx, v0, [0, abi::trt_field_vtable]));
let lldtor = Load(bcx, lldtor_ptr);
Call(bcx, lldtor, [PointerCast(bcx, lluniquevalue, Type::i8p())], []);
bcx
})
}

@ -498,7 +498,7 @@ pub fn make_vtable(ccx: &CrateContext,
unsafe {
let _icx = push_ctxt("meth::make_vtable");
let mut components = ~[ tydesc.tydesc ];
let mut components = ~[tydesc.drop_glue.get().unwrap()];
for &ptr in ptrs.iter() {
components.push(ptr)
}

@ -180,7 +180,7 @@ impl Type {
}
pub fn vtable() -> Type {
Type::array(&Type::i8().ptr_to(), 1)
Type::array(&Type::i8p().ptr_to(), 1)
}
pub fn generic_glue_fn(cx: &CrateContext) -> Type {
@ -246,13 +246,13 @@ impl Type {
}
pub fn opaque_trait(ctx: &CrateContext, store: ty::TraitStore) -> Type {
let tydesc_ptr = ctx.tydesc_type.ptr_to();
let vtable = Type::glue_fn(Type::i8p()).ptr_to().ptr_to();
let box_ty = match store {
ty::BoxTraitStore => Type::at_box(ctx, Type::i8()),
ty::UniqTraitStore => Type::i8(),
ty::RegionTraitStore(..) => Type::i8()
};
Type::struct_([tydesc_ptr, box_ty.ptr_to()], false)
Type::struct_([vtable, box_ty.ptr_to()], false)
}
pub fn kind(&self) -> TypeKind {