Skip to content

Commit 09ad0cd

Browse files
committed
add type name to the tydesc
Closes #8926
1 parent 58decdd commit 09ad0cd

File tree

6 files changed

+20
-5
lines changed

6 files changed

+20
-5
lines changed

src/librustc/back/abi.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ pub static tydesc_field_drop_glue: uint = 3u;
4747
pub static tydesc_field_free_glue: uint = 4u;
4848
pub static tydesc_field_visit_glue: uint = 5u;
4949
pub static tydesc_field_borrow_offset: uint = 6u;
50-
pub static n_tydesc_fields: uint = 7u;
50+
pub static tydesc_field_name_offset: uint = 7u;
51+
pub static n_tydesc_fields: uint = 8u;
5152

5253
// The two halves of a closure: code and environment.
5354
pub static fn_field_code: uint = 0u;

src/librustc/middle/trans/common.rs

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub struct tydesc_info {
5656
size: ValueRef,
5757
align: ValueRef,
5858
borrow_offset: ValueRef,
59+
name: ValueRef,
5960
take_glue: Option<ValueRef>,
6061
drop_glue: Option<ValueRef>,
6162
free_glue: Option<ValueRef>,

src/librustc/middle/trans/glue.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -678,12 +678,16 @@ pub fn declare_tydesc(ccx: &mut CrateContext, t: ty::t) -> @mut tydesc_info {
678678
llvm::LLVMAddGlobal(ccx.llmod, ccx.tydesc_type.to_ref(), buf)
679679
}
680680
};
681+
682+
let ty_name = C_estr_slice(ccx, ppaux::ty_to_str(ccx.tcx, t).to_managed());
683+
681684
let inf = @mut tydesc_info {
682685
ty: t,
683686
tydesc: gvar,
684687
size: llsize,
685688
align: llalign,
686689
borrow_offset: borrow_offset,
690+
name: ty_name,
687691
take_glue: None,
688692
drop_glue: None,
689693
free_glue: None,
@@ -809,14 +813,14 @@ pub fn emit_tydescs(ccx: &mut CrateContext) {
809813
drop_glue, // drop_glue
810814
free_glue, // free_glue
811815
visit_glue, // visit_glue
812-
ti.borrow_offset]); // borrow_offset
816+
ti.borrow_offset, // borrow_offset
817+
ti.name]); // name
813818

814819
unsafe {
815820
let gvar = ti.tydesc;
816821
llvm::LLVMSetInitializer(gvar, tydesc);
817822
llvm::LLVMSetGlobalConstant(gvar, True);
818823
lib::llvm::SetLinkage(gvar, lib::llvm::InternalLinkage);
819-
820824
}
821825
};
822826
}

src/librustc/middle/trans/type_.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ impl Type {
216216
glue_fn_ty, // drop
217217
glue_fn_ty, // free
218218
glue_fn_ty, // visit
219-
int_ty]; // borrow_offset
220-
219+
int_ty, // borrow_offset
220+
Type::struct_([Type::i8p(), Type::int(arch)], false)]; // name
221221
tydesc.set_struct_body(elems, false);
222222

223223
return tydesc;

src/libstd/unstable/intrinsics.rs

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ pub struct TyDesc {
6666
// `U`, but in the case of `@Trait` or `~Trait` objects, the type
6767
// `U` is unknown.
6868
borrow_offset: uint,
69+
70+
// Name corresponding to the type
71+
name: &'static str
6972
}
7073

7174
#[lang="opaque"]

src/rt/rust_type.h

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ static inline void *box_body(rust_opaque_box *box) {
5252
return (void*)(box + 1);
5353
}
5454

55+
struct slice {
56+
void *data;
57+
size_t length;
58+
};
59+
5560
struct type_desc {
5661
size_t size;
5762
size_t align;
@@ -60,6 +65,7 @@ struct type_desc {
6065
glue_fn *free_glue;
6166
glue_fn *visit_glue;
6267
size_t borrow_offset;
68+
slice name;
6369
};
6470

6571
#endif

0 commit comments

Comments
 (0)