From 09ad0cd362204e3da92cfa6bc8116299516e8275 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Tue, 3 Sep 2013 04:44:47 -0400 Subject: [PATCH] add type name to the tydesc Closes #8926 --- src/librustc/back/abi.rs | 3 ++- src/librustc/middle/trans/common.rs | 1 + src/librustc/middle/trans/glue.rs | 8 ++++++-- src/librustc/middle/trans/type_.rs | 4 ++-- src/libstd/unstable/intrinsics.rs | 3 +++ src/rt/rust_type.h | 6 ++++++ 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/librustc/back/abi.rs b/src/librustc/back/abi.rs index dae0ceed22d..2d5a4b4edb7 100644 --- a/src/librustc/back/abi.rs +++ b/src/librustc/back/abi.rs @@ -47,7 +47,8 @@ pub static tydesc_field_drop_glue: uint = 3u; pub static tydesc_field_free_glue: uint = 4u; pub static tydesc_field_visit_glue: uint = 5u; pub static tydesc_field_borrow_offset: uint = 6u; -pub static n_tydesc_fields: uint = 7u; +pub static tydesc_field_name_offset: uint = 7u; +pub static n_tydesc_fields: uint = 8u; // The two halves of a closure: code and environment. pub static fn_field_code: uint = 0u; diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 9b608d12669..b619085ee84 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -56,6 +56,7 @@ pub struct tydesc_info { size: ValueRef, align: ValueRef, borrow_offset: ValueRef, + name: ValueRef, take_glue: Option, drop_glue: Option, free_glue: Option, diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index 9acc3018046..9856758990a 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -678,12 +678,16 @@ pub fn declare_tydesc(ccx: &mut CrateContext, t: ty::t) -> @mut tydesc_info { llvm::LLVMAddGlobal(ccx.llmod, ccx.tydesc_type.to_ref(), buf) } }; + + let ty_name = C_estr_slice(ccx, ppaux::ty_to_str(ccx.tcx, t).to_managed()); + let inf = @mut tydesc_info { ty: t, tydesc: gvar, size: llsize, align: llalign, borrow_offset: borrow_offset, + name: ty_name, take_glue: None, drop_glue: None, free_glue: None, @@ -809,14 +813,14 @@ pub fn emit_tydescs(ccx: &mut CrateContext) { drop_glue, // drop_glue free_glue, // free_glue visit_glue, // visit_glue - ti.borrow_offset]); // borrow_offset + ti.borrow_offset, // borrow_offset + ti.name]); // name unsafe { let gvar = ti.tydesc; llvm::LLVMSetInitializer(gvar, tydesc); llvm::LLVMSetGlobalConstant(gvar, True); lib::llvm::SetLinkage(gvar, lib::llvm::InternalLinkage); - } }; } diff --git a/src/librustc/middle/trans/type_.rs b/src/librustc/middle/trans/type_.rs index f8f6f7b87ec..281c047641c 100644 --- a/src/librustc/middle/trans/type_.rs +++ b/src/librustc/middle/trans/type_.rs @@ -216,8 +216,8 @@ impl Type { glue_fn_ty, // drop glue_fn_ty, // free glue_fn_ty, // visit - int_ty]; // borrow_offset - + int_ty, // borrow_offset + Type::struct_([Type::i8p(), Type::int(arch)], false)]; // name tydesc.set_struct_body(elems, false); return tydesc; diff --git a/src/libstd/unstable/intrinsics.rs b/src/libstd/unstable/intrinsics.rs index fbd5bdaf587..c3791d18b38 100644 --- a/src/libstd/unstable/intrinsics.rs +++ b/src/libstd/unstable/intrinsics.rs @@ -66,6 +66,9 @@ pub struct TyDesc { // `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 } #[lang="opaque"] diff --git a/src/rt/rust_type.h b/src/rt/rust_type.h index 0ac9bc6abff..fe3c946a40b 100644 --- a/src/rt/rust_type.h +++ b/src/rt/rust_type.h @@ -52,6 +52,11 @@ static inline void *box_body(rust_opaque_box *box) { return (void*)(box + 1); } +struct slice { + void *data; + size_t length; +}; + struct type_desc { size_t size; size_t align; @@ -60,6 +65,7 @@ struct type_desc { glue_fn *free_glue; glue_fn *visit_glue; size_t borrow_offset; + slice name; }; #endif