Skip to content

reduce code bloat by reducing TyDesc usage #11909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ pub fn malloc_raw_dyn<'a>(

// Get the tydesc for the body:
let static_ti = get_tydesc(ccx, t);
glue::lazily_emit_all_tydesc_glue(ccx, static_ti);
glue::lazily_emit_tydesc_glue(ccx, abi::tydesc_field_drop_glue, static_ti);

// Allocate space:
let tydesc = PointerCast(bcx, static_ti.tydesc, Type::i8p());
Expand Down
16 changes: 4 additions & 12 deletions src/librustc/middle/trans/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn simplified_glue_type(tcx: ty::ctxt, field: uint, t: ty::t) -> ty::t {
t
}

fn lazily_emit_tydesc_glue(ccx: @CrateContext, field: uint, ti: @tydesc_info) {
pub fn lazily_emit_tydesc_glue(ccx: @CrateContext, field: uint, ti: @tydesc_info) {
let _icx = push_ctxt("lazily_emit_tydesc_glue");

let simpl = simplified_glue_type(ccx.tcx, field, ti.ty);
Expand Down Expand Up @@ -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
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/meth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ pub fn get_vtable(bcx: &Block,

// Generate a type descriptor for the vtable.
let tydesc = get_tydesc(ccx, self_ty);
glue::lazily_emit_all_tydesc_glue(ccx, tydesc);
glue::lazily_emit_tydesc_glue(ccx, abi::tydesc_field_drop_glue, tydesc);

let vtable = make_vtable(ccx, tydesc, methods);

Expand All @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/trans/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down