Skip to content

Commit ec5c5a7

Browse files
committed
rustc: Rework the API for trans_malloc() to be generic-aware and so that clients don't need to call trans_malloc_inner()
1 parent dddeba1 commit ec5c5a7

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/comp/middle/trans.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,22 +1060,26 @@ fn GEP_tup_like(@block_ctxt cx, @ty.t t,
10601060
}
10611061

10621062

1063-
fn trans_malloc_inner(@block_ctxt cx, TypeRef llptr_ty) -> result {
1064-
auto llbody_ty = lib.llvm.llvm.LLVMGetElementType(llptr_ty);
1063+
fn trans_raw_malloc(@block_ctxt cx, TypeRef llptr_ty, ValueRef llsize)
1064+
-> result {
10651065
// FIXME: need a table to collect tydesc globals.
10661066
auto tydesc = C_int(0);
1067-
auto sz = llsize_of(llbody_ty);
1068-
auto sub = trans_upcall(cx, "upcall_malloc", vec(sz, tydesc));
1069-
sub.val = vi2p(sub.bcx, sub.val, llptr_ty);
1070-
ret sub;
1067+
auto rslt = trans_upcall(cx, "upcall_malloc", vec(llsize, tydesc));
1068+
rslt = res(rslt.bcx, vi2p(cx, rslt.val, llptr_ty));
1069+
ret rslt;
1070+
}
1071+
1072+
fn trans_malloc_without_cleanup(@block_ctxt cx, @ty.t t) -> result {
1073+
auto llty = type_of(cx.fcx.ccx, t);
1074+
auto rslt = size_of(cx, t);
1075+
ret trans_raw_malloc(rslt.bcx, llty, rslt.val);
10711076
}
10721077

10731078
fn trans_malloc(@block_ctxt cx, @ty.t t) -> result {
10741079
auto scope_cx = find_scope_cx(cx);
1075-
auto llptr_ty = type_of(cx.fcx.ccx, t);
1076-
auto sub = trans_malloc_inner(cx, llptr_ty);
1077-
scope_cx.cleanups += clean(bind drop_ty(_, sub.val, t));
1078-
ret sub;
1080+
auto rslt = trans_malloc_without_cleanup(cx, t);
1081+
scope_cx.cleanups += clean(bind drop_ty(_, rslt.val, t));
1082+
ret rslt;
10791083
}
10801084

10811085

@@ -3216,7 +3220,9 @@ fn trans_bind(@block_ctxt cx, @ast.expr f,
32163220
ty_param_count);
32173221

32183222
// Malloc a box for the body.
3219-
auto r = trans_malloc_inner(bcx, llclosure_ty);
3223+
// FIXME: this isn't generic-safe
3224+
auto r = trans_raw_malloc(bcx, llclosure_ty,
3225+
llsize_of(llvm.LLVMGetElementType(llclosure_ty)));
32203226
auto box = r.val;
32213227
bcx = r.bcx;
32223228
auto rc = bcx.build.GEP(box,
@@ -4453,7 +4459,8 @@ fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
44534459
let TypeRef llboxed_body_ty = type_of(cx, boxed_body_ty);
44544460

44554461
// Malloc a box for the body.
4456-
auto box = trans_malloc_inner(bcx, llboxed_body_ty);
4462+
auto box = trans_raw_malloc(bcx, llboxed_body_ty,
4463+
llsize_of(llvm.LLVMGetElementType(llboxed_body_ty)));
44574464
bcx = box.bcx;
44584465
auto rc = GEP_tup_like(bcx, boxed_body_ty, box.val,
44594466
vec(0, abi.box_rc_field_refcnt));

0 commit comments

Comments
 (0)