remove borrow_offset as ~ is now free of headers

This commit is contained in:
Daniel Micay 2014-01-14 16:20:09 -05:00
parent 0e885e42b1
commit 6809b172e0
6 changed files with 3 additions and 50 deletions

View File

@ -45,9 +45,8 @@ pub static tydesc_field_align: uint = 1u;
pub static tydesc_field_take_glue: uint = 2u;
pub static tydesc_field_drop_glue: uint = 3u;
pub static tydesc_field_visit_glue: uint = 4u;
pub static tydesc_field_borrow_offset: uint = 5u;
pub static tydesc_field_name_offset: uint = 6u;
pub static n_tydesc_fields: uint = 7u;
pub static tydesc_field_name_offset: uint = 5u;
pub static n_tydesc_fields: uint = 6u;
// The two halves of a closure: code and environment.
pub static fn_field_code: uint = 0u;

View File

@ -90,7 +90,6 @@ pub struct tydesc_info {
tydesc: ValueRef,
size: ValueRef,
align: ValueRef,
borrow_offset: ValueRef,
name: ValueRef,
take_glue: Cell<Option<ValueRef>>,
drop_glue: Cell<Option<ValueRef>>,

View File

@ -398,29 +398,7 @@ pub fn trans_to_datum<'a>(bcx: &'a Block<'a>, expr: &ast::Expr)
autoderefs));
derefd_datum.to_rptr(bcx).to_value_llval(bcx)
}
ty::UniqTraitStore(..) => {
// For a ~T box, there may or may not be a header,
// depending on whether the type T references managed
// boxes. However, since we do not *know* the type T
// for objects, this presents a hurdle. Our solution is
// to load the "borrow offset" from the type descriptor;
// this value will either be 0 or sizeof(BoxHeader), depending
// on the type T.
let llopaque =
PointerCast(bcx, source_data, Type::opaque().ptr_to());
let lltydesc_ptr_ptr =
PointerCast(bcx, vtable,
bcx.ccx().tydesc_type.ptr_to().ptr_to());
let lltydesc_ptr =
Load(bcx, lltydesc_ptr_ptr);
let borrow_offset_ptr =
GEPi(bcx, lltydesc_ptr,
[0, abi::tydesc_field_borrow_offset]);
let borrow_offset =
Load(bcx, borrow_offset_ptr);
InBoundsGEP(bcx, llopaque, [borrow_offset])
}
ty::RegionTraitStore(..) => {
ty::UniqTraitStore(..) | ty::RegionTraitStore(..) => {
source_data
}
};

View File

@ -546,17 +546,6 @@ pub fn declare_tydesc(ccx: &CrateContext, t: ty::t) -> @tydesc_info {
ppaux::ty_to_str(ccx.tcx, t));
}
let has_header = match ty::get(t).sty {
ty::ty_box(..) => true,
_ => false
};
let borrow_offset = if has_header {
ccx.offsetof_gep(llty, [0u, abi::box_field_body])
} else {
C_uint(ccx, 0)
};
let llsize = llsize_of(ccx, llty);
let llalign = llalign_of(ccx, llty);
let name = mangle_internal_name_by_type_and_seq(ccx, t, "tydesc").to_managed();
@ -575,7 +564,6 @@ pub fn declare_tydesc(ccx: &CrateContext, t: ty::t) -> @tydesc_info {
tydesc: gvar,
size: llsize,
align: llalign,
borrow_offset: borrow_offset,
name: ty_name,
take_glue: Cell::new(None),
drop_glue: Cell::new(None),
@ -685,15 +673,12 @@ pub fn emit_tydescs(ccx: &CrateContext) {
}
};
debug!("ti.borrow_offset: {}", ccx.tn.val_to_str(ti.borrow_offset));
let tydesc = C_named_struct(ccx.tydesc_type,
[ti.size, // size
ti.align, // align
take_glue, // take_glue
drop_glue, // drop_glue
visit_glue, // visit_glue
ti.borrow_offset, // borrow_offset
ti.name]); // name
unsafe {

View File

@ -220,7 +220,6 @@ impl Type {
glue_fn_ty, // take
glue_fn_ty, // drop
glue_fn_ty, // visit
int_ty, // borrow_offset
Type::struct_([Type::i8p(), Type::int(arch)], false)]; // name
tydesc.set_struct_body(elems, false);

View File

@ -98,13 +98,6 @@ pub struct TyDesc {
// Called by reflection visitor to visit a value of type `T`
visit_glue: GlueFn,
// If T represents a box pointer (`@U` or `~U`), then
// `borrow_offset` is the amount that the pointer must be adjusted
// to find the payload. This is always derivable from the type
// `U`, but in the case of `@Trait` or `~Trait` objects, the type
// `U` is unknown.
borrow_offset: uint,
// Name corresponding to the type
name: &'static str
}