Skip to content

Commit bdb84e7

Browse files
author
Eric Holk
committed
Merge branch 'master' of github.com:graydon/rust
2 parents 0e70332 + ae33120 commit bdb84e7

File tree

9 files changed

+163
-71
lines changed

9 files changed

+163
-71
lines changed

src/comp/back/abi.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,21 @@ const vec_elt_pad: int = 3;
4747
const vec_elt_data: int = 4;
4848

4949
const tydesc_field_first_param: int = 0;
50-
5150
const tydesc_field_size: int = 1;
52-
5351
const tydesc_field_align: int = 2;
54-
5552
const tydesc_field_copy_glue: int = 3;
56-
5753
const tydesc_field_drop_glue: int = 4;
58-
5954
const tydesc_field_free_glue: int = 5;
60-
6155
const tydesc_field_sever_glue: int = 6;
62-
6356
const tydesc_field_mark_glue: int = 7;
64-
65-
6657
// FIXME no longer used in rustc, drop when rustboot is gone
6758
const tydesc_field_obj_drop_glue: int = 8;
68-
6959
const tydesc_field_is_stateful: int = 9;
70-
7160
const tydesc_field_cmp_glue: int = 10;
72-
73-
const n_tydesc_fields: int = 11;
61+
const tydesc_field_shape: int = 11;
62+
const tydesc_field_shape_tables: int = 12;
63+
const tydesc_field_n_params: int = 13;
64+
const n_tydesc_fields: int = 14;
7465

7566
const cmp_glue_op_eq: uint = 0u;
7667

src/comp/middle/trans.rs

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,8 @@ fn linearize_ty_params(cx: &@block_ctxt, t: &ty::t) ->
895895

896896
fn trans_stack_local_derived_tydesc(cx: &@block_ctxt, llsz: ValueRef,
897897
llalign: ValueRef, llroottydesc: ValueRef,
898-
llparamtydescs: ValueRef) -> ValueRef {
898+
llparamtydescs: ValueRef,
899+
n_params: uint) -> ValueRef {
899900
let llmyroottydesc = alloca(cx, bcx_ccx(cx).tydesc_type);
900901
// By convention, desc 0 is the root descriptor.
901902

@@ -904,11 +905,14 @@ fn trans_stack_local_derived_tydesc(cx: &@block_ctxt, llsz: ValueRef,
904905
// Store a pointer to the rest of the descriptors.
905906

906907
let llfirstparam = cx.build.GEP(llparamtydescs, ~[C_int(0), C_int(0)]);
907-
cx.build.Store(llfirstparam,
908-
cx.build.GEP(llmyroottydesc, ~[C_int(0), C_int(0)]));
909-
cx.build.Store(llsz, cx.build.GEP(llmyroottydesc, ~[C_int(0), C_int(1)]));
910-
cx.build.Store(llalign,
911-
cx.build.GEP(llmyroottydesc, ~[C_int(0), C_int(2)]));
908+
store_inbounds(cx, llfirstparam, llmyroottydesc,
909+
~[C_int(0), C_int(abi::tydesc_field_first_param)]);
910+
store_inbounds(cx, C_uint(n_params), llmyroottydesc,
911+
~[C_int(0), C_int(abi::tydesc_field_n_params)]);
912+
store_inbounds(cx, llsz, llmyroottydesc,
913+
~[C_int(0), C_int(abi::tydesc_field_size)]);
914+
store_inbounds(cx, llalign, llmyroottydesc,
915+
~[C_int(0), C_int(abi::tydesc_field_align)]);
912916
ret llmyroottydesc;
913917
}
914918

@@ -964,7 +968,8 @@ fn get_derived_tydesc(cx: &@block_ctxt, t: &ty::t, escapes: bool,
964968
v = td_val;
965969
} else {
966970
let llparamtydescs =
967-
alloca(bcx, T_array(T_ptr(bcx_ccx(bcx).tydesc_type), n_params));
971+
alloca(bcx, T_array(T_ptr(bcx_ccx(bcx).tydesc_type),
972+
n_params + 1u));
968973
let i = 0;
969974
for td: ValueRef in tys.descs {
970975
let tdp = bcx.build.GEP(llparamtydescs, ~[C_int(0), C_int(i)]);
@@ -973,7 +978,7 @@ fn get_derived_tydesc(cx: &@block_ctxt, t: &ty::t, escapes: bool,
973978
}
974979
v =
975980
trans_stack_local_derived_tydesc(bcx, sz.val, align.val, root,
976-
llparamtydescs);
981+
llparamtydescs, n_params);
977982
}
978983
bcx.fcx.derived_tydescs.insert(t, {lltydesc: v, escapes: escapes});
979984
ret rslt(cx, v);
@@ -1191,20 +1196,28 @@ fn emit_tydescs(ccx: &@crate_ctxt) {
11911196
none. { ccx.stats.n_null_glues += 1u; C_null(cmp_fn_ty) }
11921197
some(v) { ccx.stats.n_real_glues += 1u; v }
11931198
};
1194-
let // copy_glue
1195-
// drop_glue
1196-
// free_glue
1197-
// sever_glue
1198-
// mark_glue
1199-
// obj_drop_glue
1200-
// is_stateful
1201-
tydesc =
1199+
1200+
let shape = shape::shape_of(ccx, pair.key);
1201+
let shape_tables =
1202+
llvm::LLVMConstPointerCast(ccx.shape_cx.llshapetables,
1203+
T_ptr(T_i8()));
1204+
1205+
let tydesc =
12021206
C_named_struct(ccx.tydesc_type,
1203-
~[C_null(T_ptr(T_ptr(ccx.tydesc_type))), ti.size,
1204-
ti.align, copy_glue, drop_glue, free_glue,
1205-
C_null(glue_fn_ty), C_null(glue_fn_ty),
1206-
C_null(glue_fn_ty), C_null(glue_fn_ty),
1207-
cmp_glue]); // cmp_glue
1207+
~[C_null(T_ptr(T_ptr(ccx.tydesc_type))),
1208+
ti.size, // size
1209+
ti.align, // align
1210+
copy_glue, // copy_glue
1211+
drop_glue, // drop_glue
1212+
free_glue, // free_glue
1213+
C_null(glue_fn_ty), // sever_glue
1214+
C_null(glue_fn_ty), // mark_glue
1215+
C_null(glue_fn_ty), // obj_drop_glue
1216+
C_null(glue_fn_ty), // is_stateful
1217+
cmp_glue, // cmp_glue
1218+
C_shape(ccx, shape), // shape
1219+
shape_tables, // shape_tables
1220+
C_int(0)]); // n_params
12081221

12091222
let gvar = ti.tydesc;
12101223
llvm::LLVMSetInitializer(gvar, tydesc);
@@ -2288,16 +2301,17 @@ fn call_cmp_glue(cx: &@block_ctxt, lhs: ValueRef, rhs: ValueRef, t: &ty::t,
22882301
let ti = none[@tydesc_info];
22892302
let r = get_tydesc(cx, t, false, ti);
22902303
lazily_emit_tydesc_glue(cx, abi::tydesc_field_cmp_glue, ti);
2304+
let lltydesc = r.val;
22912305
let lltydescs =
2292-
r.bcx.build.GEP(r.val,
2306+
r.bcx.build.GEP(lltydesc,
22932307
~[C_int(0), C_int(abi::tydesc_field_first_param)]);
22942308
lltydescs = r.bcx.build.Load(lltydescs);
22952309

22962310
let llfn;
22972311
alt ti {
22982312
none. {
22992313
let llfnptr =
2300-
r.bcx.build.GEP(r.val,
2314+
r.bcx.build.GEP(lltydesc,
23012315
~[C_int(0), C_int(abi::tydesc_field_cmp_glue)]);
23022316
llfn = r.bcx.build.Load(llfnptr);
23032317
}
@@ -2306,7 +2320,7 @@ fn call_cmp_glue(cx: &@block_ctxt, lhs: ValueRef, rhs: ValueRef, t: &ty::t,
23062320

23072321
let llcmpresultptr = alloca(r.bcx, T_i1());
23082322
let llargs: ValueRef[] =
2309-
~[llcmpresultptr, r.bcx.fcx.lltaskptr, C_null(T_ptr(T_nil())),
2323+
~[llcmpresultptr, r.bcx.fcx.lltaskptr, lltydesc,
23102324
lltydescs, llrawlhsptr, llrawrhsptr, llop];
23112325
r.bcx.build.Call(llfn, llargs);
23122326
ret rslt(r.bcx, r.bcx.build.Load(llcmpresultptr));
@@ -2366,7 +2380,7 @@ fn call_memmove(cx: &@block_ctxt, dst: ValueRef, src: ValueRef,
23662380
let src_ptr = cx.build.PointerCast(src, T_ptr(T_i8()));
23672381
let dst_ptr = cx.build.PointerCast(dst, T_ptr(T_i8()));
23682382
let size = cx.build.IntCast(n_bytes, T_i32());
2369-
let align = C_int(0);
2383+
let align = C_int(1);
23702384
let volatile = C_bool(false);
23712385
ret rslt(cx,
23722386
cx.build.Call(memmove,
@@ -2397,7 +2411,12 @@ fn memmove_ty(cx: &@block_ctxt, dst: ValueRef, src: ValueRef, t: &ty::t) ->
23972411
if ty::type_has_dynamic_size(bcx_tcx(cx), t) {
23982412
let llsz = size_of(cx, t);
23992413
ret call_memmove(llsz.bcx, dst, src, llsz.val);
2400-
} else { ret rslt(cx, cx.build.Store(cx.build.Load(src), dst)); }
2414+
} else if ty::type_is_structural(bcx_tcx(cx), t) {
2415+
let llsz = llsize_of(type_of(bcx_ccx(cx), cx.sp, t));
2416+
ret call_memmove(cx, dst, src, llsz);
2417+
} else {
2418+
ret rslt(cx, cx.build.Store(cx.build.Load(src), dst));
2419+
}
24012420
}
24022421

24032422
// Duplicates any heap-owned memory owned by a value of the given type.
@@ -4696,7 +4715,7 @@ fn trans_arg_expr(cx: &@block_ctxt, arg: &ty::arg, lldestty0: TypeRef,
46964715
// - create_llargs_for_fn_args.
46974716
// - new_fn_ctxt
46984717
// - trans_args
4699-
fn trans_args(cx: &@block_ctxt, llenv: ValueRef, llobj: &option::t[ValueRef],
4718+
fn trans_args(cx: &@block_ctxt, llenv: ValueRef,
47004719
gen: &option::t[generic_info], lliterbody: &option::t[ValueRef],
47014720
es: &(@ast::expr)[], fn_ty: &ty::t) ->
47024721
{bcx: @block_ctxt, args: ValueRef[], retslot: ValueRef} {
@@ -4815,8 +4834,7 @@ fn trans_call(cx: &@block_ctxt, f: &@ast::expr,
48154834

48164835
let ret_ty = ty::node_id_to_type(bcx_tcx(cx), id);
48174836
let args_res =
4818-
trans_args(bcx, llenv, f_res.llobj, f_res.generic, lliterbody, args,
4819-
fn_ty);
4837+
trans_args(bcx, llenv, f_res.generic, lliterbody, args, fn_ty);
48204838
bcx = args_res.bcx;
48214839
let llargs = args_res.args;
48224840
let llretslot = args_res.retslot;
@@ -8000,8 +8018,9 @@ fn trans_crate(sess: &session::session, crate: &@ast::crate, tcx: &ty::ctxt,
80008018
trans_mod(cx, crate.node.module);
80018019
create_crate_map(ccx);
80028020
emit_tydescs(ccx);
8003-
// Translate the metadata:
8021+
shape::gen_shape_tables(ccx);
80048022

8023+
// Translate the metadata.
80058024
write_metadata(cx.ccx, crate);
80068025
if ccx.sess.get_opts().stats {
80078026
log_err "--- trans stats ---";

src/comp/middle/trans_alt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ fn trans_alt(cx: &@block_ctxt, expr: &@ast::expr, arms: &ast::arm[],
433433
ret rslt(cx, cx.build.Unreachable());
434434
}
435435
else {
436-
ret rslt(cx, C_nil());
436+
ret er;
437437
}
438438
}
439439

src/comp/middle/trans_common.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -597,22 +597,13 @@ fn T_tydesc(taskptr_type: TypeRef) -> TypeRef {
597597
T_ptr(T_fn(~[T_ptr(T_nil()), taskptr_type, T_ptr(T_nil()), tydescpp,
598598
pvoid], T_void()));
599599
let cmp_glue_fn_ty =
600-
T_ptr(T_fn(~[T_ptr(T_i1()), taskptr_type, T_ptr(T_nil()), tydescpp,
600+
T_ptr(T_fn(~[T_ptr(T_i1()), taskptr_type, T_ptr(tydesc), tydescpp,
601601
pvoid, pvoid, T_i8()], T_void()));
602602

603-
let // first_param
604-
// size
605-
// align
606-
// copy_glue
607-
// drop_glue
608-
// free_glue
609-
// sever_glue
610-
// mark_glue
611-
// obj_drop_glue
612-
// is_stateful
613-
elems =
603+
let elems =
614604
~[tydescpp, T_int(), T_int(), glue_fn_ty, glue_fn_ty, glue_fn_ty,
615-
glue_fn_ty, glue_fn_ty, glue_fn_ty, glue_fn_ty, cmp_glue_fn_ty];
605+
glue_fn_ty, glue_fn_ty, glue_fn_ty, glue_fn_ty, cmp_glue_fn_ty,
606+
T_ptr(T_i8()), T_ptr(T_i8()), T_int()];
616607
set_struct_body(tydesc, elems);
617608
ret tydesc;
618609
}
@@ -874,3 +865,14 @@ fn C_bytes(bytes : &u8[]) -> ValueRef {
874865
ivec::len(bytes), False);
875866
}
876867

868+
fn C_shape(ccx : &@crate_ctxt, bytes : &u8[]) -> ValueRef {
869+
let llshape = C_bytes(bytes);
870+
let llglobal = llvm::LLVMAddGlobal(ccx.llmod, val_ty(llshape),
871+
str::buf(ccx.names.next("shape")));
872+
llvm::LLVMSetInitializer(llglobal, llshape);
873+
llvm::LLVMSetGlobalConstant(llglobal, True);
874+
llvm::LLVMSetLinkage(llglobal,
875+
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
876+
ret llvm::LLVMConstPointerCast(llglobal, T_ptr(T_i8()));
877+
}
878+

0 commit comments

Comments
 (0)