Skip to content

Commit 53d33d5

Browse files
committed
---
yaml --- r: 1117 b: refs/heads/master c: a7e9984 h: refs/heads/master i: 1115: 634f93d v: v3
1 parent de226b4 commit 53d33d5

File tree

3 files changed

+55
-28
lines changed

3 files changed

+55
-28
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: ad5e9202763887ec4a0a588c8b3f60fa6e63ddc9
2+
refs/heads/master: a7e9984999121c84c92a3236f29d4edf649e9431

trunk/src/comp/back/abi.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ const int vec_elt_alloc = 1;
2828
const int vec_elt_fill = 2;
2929
const int vec_elt_data = 3;
3030

31+
const int tydesc_field_first_param = 0;
32+
const int tydesc_field_size = 1;
33+
const int tydesc_field_align = 2;
34+
const int tydesc_field_copy_glue_off = 3;
35+
const int tydesc_field_drop_glue_off = 4;
36+
const int tydesc_field_free_glue_off = 5;
37+
const int tydesc_field_sever_glue_off = 6;
38+
const int tydesc_field_mark_glue_off = 7;
39+
const int tydesc_field_obj_drop_glue_off = 8;
40+
const int tydesc_field_is_stateful = 9;
41+
3142

3243
/* Both obj and fn are two-word "bindings": One word points to some static
3344
* dispatch information (vtbl, thunk, callee), and the other points to some

trunk/src/comp/middle/trans.rs

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ state type crate_ctxt = rec(session.session sess,
6868
hashmap[ast.def_id, ValueRef] item_ids,
6969
hashmap[ast.def_id, @ast.item] items,
7070
hashmap[ast.def_id, @tag_info] tags,
71-
hashmap[@typeck.ty, @ty_info] types,
71+
hashmap[@typeck.ty, ValueRef] tydescs,
7272
@glue_fns glues,
7373
namegen names,
7474
str path);
@@ -471,19 +471,6 @@ fn C_struct(vec[ValueRef] elts) -> ValueRef {
471471
False);
472472
}
473473

474-
fn C_tydesc(TypeRef t) -> ValueRef {
475-
ret C_struct(vec(C_null(T_ptr(T_opaque())), // first_param
476-
llvm.LLVMSizeOf(t), // size
477-
llvm.LLVMAlignOf(t), // align
478-
C_null(T_ptr(T_opaque())), // copy_glue_off
479-
C_null(T_ptr(T_opaque())), // drop_glue_off
480-
C_null(T_ptr(T_opaque())), // free_glue_off
481-
C_null(T_ptr(T_opaque())), // sever_glue_off
482-
C_null(T_ptr(T_opaque())), // mark_glue_off
483-
C_null(T_ptr(T_opaque())), // obj_drop_glue_off
484-
C_null(T_ptr(T_opaque())))); // is_stateful
485-
}
486-
487474
fn decl_fn(ModuleRef llmod, str name, uint cc, TypeRef llty) -> ValueRef {
488475
let ValueRef llfn =
489476
llvm.LLVMAddFunction(llmod, _str.buf(name), llty);
@@ -576,21 +563,48 @@ fn trans_malloc(@block_ctxt cx, @typeck.ty t) -> result {
576563
}
577564

578565

579-
// Glue and referent count twiddling
566+
// Type descriptor and type glue stuff
567+
568+
// Given a type and a field index into its corresponding type descriptor,
569+
// returns an LLVM ValueRef of that field from the tydesc, generating the
570+
// tydesc if necessary.
571+
fn field_of_tydesc(@block_ctxt cx, @typeck.ty ty, int field) -> ValueRef {
572+
auto tydesc = get_tydesc(cx.fcx.ccx, ty);
573+
ret cx.build.GEP(tydesc, vec(C_int(0), C_int(field)));
574+
}
580575

581-
fn get_ty_info(@crate_ctxt cx, @typeck.ty ty) -> @ty_info {
582-
if (!cx.types.contains_key(ty)) {
583-
make_ty_info(cx, ty);
576+
fn get_tydesc(@crate_ctxt cx, @typeck.ty ty) -> ValueRef {
577+
if (!cx.tydescs.contains_key(ty)) {
578+
make_tydesc(cx, ty);
584579
}
585-
ret cx.types.get(ty);
580+
ret cx.tydescs.get(ty);
586581
}
587582

588-
fn make_ty_info(@crate_ctxt cx, @typeck.ty ty) {
583+
fn make_tydesc(@crate_ctxt cx, @typeck.ty ty) {
589584
auto tg = make_take_glue;
590585
auto take_glue = make_generic_glue(cx, ty, "take", tg);
591586
auto dg = make_drop_glue;
592587
auto drop_glue = make_generic_glue(cx, ty, "drop", dg);
593-
cx.types.insert(ty, @rec(take_glue=take_glue, drop_glue=drop_glue));
588+
589+
auto llty = type_of(cx, ty);
590+
auto pvoid = T_ptr(T_i8());
591+
auto glue_fn_ty = T_ptr(T_fn(vec(T_taskptr(), pvoid), T_void()));
592+
auto tydesc = C_struct(vec(C_null(pvoid),
593+
llvm.LLVMSizeOf(llty),
594+
llvm.LLVMAlignOf(llty),
595+
take_glue, // copy_glue_off
596+
drop_glue, // drop_glue_off
597+
C_null(glue_fn_ty), // free_glue_off
598+
C_null(glue_fn_ty), // sever_glue_off
599+
C_null(glue_fn_ty), // mark_glue_off
600+
C_null(glue_fn_ty), // obj_drop_glue_off
601+
C_null(glue_fn_ty))); // is_stateful
602+
603+
auto name = sanitize(cx.names.next("tydesc_" + typeck.ty_to_str(ty)));
604+
auto gvar = llvm.LLVMAddGlobal(cx.llmod, val_ty(tydesc), _str.buf(name));
605+
llvm.LLVMSetInitializer(gvar, tydesc);
606+
llvm.LLVMSetGlobalConstant(gvar, True);
607+
cx.tydescs.insert(ty, gvar);
594608
}
595609

596610
fn make_generic_glue(@crate_ctxt cx, @typeck.ty t, str name,
@@ -970,8 +984,9 @@ fn incr_all_refcnts(@block_ctxt cx,
970984
@typeck.ty t) -> result {
971985
if (!typeck.type_is_scalar(t)) {
972986
auto llrawptr = cx.build.BitCast(v, T_ptr(T_i8()));
973-
cx.build.FastCall(get_ty_info(cx.fcx.ccx, t).take_glue,
974-
vec(cx.fcx.lltaskptr, llrawptr));
987+
auto llfnptr = field_of_tydesc(cx, t, abi.tydesc_field_copy_glue_off);
988+
auto llfn = cx.build.Load(llfnptr);
989+
cx.build.FastCall(llfn, vec(cx.fcx.lltaskptr, llrawptr));
975990
}
976991
ret res(cx, C_nil());
977992
}
@@ -993,8 +1008,9 @@ fn drop_ty(@block_ctxt cx,
9931008
@typeck.ty t) -> result {
9941009
if (!typeck.type_is_scalar(t)) {
9951010
auto llrawptr = cx.build.BitCast(v, T_ptr(T_i8()));
996-
cx.build.FastCall(get_ty_info(cx.fcx.ccx, t).drop_glue,
997-
vec(cx.fcx.lltaskptr, llrawptr));
1011+
auto llfnptr = field_of_tydesc(cx, t, abi.tydesc_field_drop_glue_off);
1012+
auto llfn = cx.build.Load(llfnptr);
1013+
cx.build.FastCall(llfn, vec(cx.fcx.lltaskptr, llrawptr));
9981014
}
9991015
ret res(cx, C_nil());
10001016
}
@@ -2833,7 +2849,7 @@ fn trans_crate(session.session sess, @ast.crate crate, str output) {
28332849
auto glues = make_glues(llmod);
28342850
auto hasher = typeck.hash_ty;
28352851
auto eqer = typeck.eq_ty;
2836-
auto types = map.mk_hashmap[@typeck.ty,@ty_info](hasher, eqer);
2852+
auto tydescs = map.mk_hashmap[@typeck.ty,ValueRef](hasher, eqer);
28372853

28382854
auto cx = @rec(sess = sess,
28392855
llmod = llmod,
@@ -2844,7 +2860,7 @@ fn trans_crate(session.session sess, @ast.crate crate, str output) {
28442860
item_ids = new_def_hash[ValueRef](),
28452861
items = new_def_hash[@ast.item](),
28462862
tags = new_def_hash[@tag_info](),
2847-
types = types,
2863+
tydescs = tydescs,
28482864
glues = glues,
28492865
names = namegen(0),
28502866
path = "_rust");

0 commit comments

Comments
 (0)