Change more of trans to rely on tydescs when dealing with generics.

This commit is contained in:
Graydon Hoare 2011-02-10 15:00:16 -08:00
parent 140d6fd964
commit c958eebf5d

View file

@ -2704,7 +2704,10 @@ fn trans_args(@block_ctxt cx,
// Arg 0: Output pointer. // Arg 0: Output pointer.
auto retty = ty.ty_fn_ret(fn_ty); auto retty = ty.ty_fn_ret(fn_ty);
auto llretslot = cx.build.Alloca(type_of(cx.fcx.ccx, retty)); auto llretslot_res = alloc_ty(bcx, retty);
bcx = llretslot_res.bcx;
auto llretslot = llretslot_res.val;
alt (gen) { alt (gen) {
case (some[generic_info](?g)) { case (some[generic_info](?g)) {
lltydescs = g.tydescs; lltydescs = g.tydescs;
@ -2715,7 +2718,7 @@ fn trans_args(@block_ctxt cx,
} }
} }
if (ty.type_has_dynamic_size(retty)) { if (ty.type_has_dynamic_size(retty)) {
llargs += cx.build.PointerCast(llretslot, T_typaram_ptr()); llargs += bcx.build.PointerCast(llretslot, T_typaram_ptr());
} else if (ty.count_ty_params(retty) != 0u) { } else if (ty.count_ty_params(retty) != 0u) {
// It's possible that the callee has some generic-ness somewhere in // It's possible that the callee has some generic-ness somewhere in
// its return value -- say a method signature within an obj or a fn // its return value -- say a method signature within an obj or a fn
@ -2723,14 +2726,14 @@ fn trans_args(@block_ctxt cx,
// of. If so, cast the caller's view of the restlot to the callee's // of. If so, cast the caller's view of the restlot to the callee's
// view, for the sake of making a type-compatible call. // view, for the sake of making a type-compatible call.
llargs += cx.build.PointerCast(llretslot, llargs += cx.build.PointerCast(llretslot,
T_ptr(type_of(cx.fcx.ccx, retty))); T_ptr(type_of(bcx.fcx.ccx, retty)));
} else { } else {
llargs += llretslot; llargs += llretslot;
} }
// Arg 1: Task pointer. // Arg 1: Task pointer.
llargs += cx.fcx.lltaskptr; llargs += bcx.fcx.lltaskptr;
// Arg 2: Env (closure-bindings / self-obj) // Arg 2: Env (closure-bindings / self-obj)
alt (llobj) { alt (llobj) {
@ -2738,7 +2741,7 @@ fn trans_args(@block_ctxt cx,
// Every object is always found in memory, // Every object is always found in memory,
// and not-yet-loaded (as part of an lval x.y // and not-yet-loaded (as part of an lval x.y
// doted method-call). // doted method-call).
llargs += cx.build.Load(ob); llargs += bcx.build.Load(ob);
} }
case (_) { case (_) {
llargs += llenv; llargs += llenv;
@ -2848,25 +2851,32 @@ fn trans_call(@block_ctxt cx, @ast.expr f,
find_scope_cx(cx).cleanups += clean(bind drop_ty(_, retval, ret_ty)); find_scope_cx(cx).cleanups += clean(bind drop_ty(_, retval, ret_ty));
} }
// log "call-result type: " + val_str(retval);
ret res(bcx, retval); ret res(bcx, retval);
} }
fn trans_tup(@block_ctxt cx, vec[ast.elt] elts, fn trans_tup(@block_ctxt cx, vec[ast.elt] elts,
&ast.ann ann) -> result { &ast.ann ann) -> result {
auto t = node_ann_type(cx.fcx.ccx, ann); auto bcx = cx;
auto llty = type_of(cx.fcx.ccx, t); auto t = node_ann_type(bcx.fcx.ccx, ann);
auto tup_val = cx.build.Alloca(llty); auto llty = type_of(bcx.fcx.ccx, t);
auto tup_res = alloc_ty(bcx, t);
auto tup_val = tup_res.val;
bcx = tup_res.bcx;
find_scope_cx(cx).cleanups += clean(bind drop_ty(_, tup_val, t)); find_scope_cx(cx).cleanups += clean(bind drop_ty(_, tup_val, t));
let int i = 0; let int i = 0;
auto r = res(cx, C_nil());
for (ast.elt e in elts) { for (ast.elt e in elts) {
auto t = ty.expr_ty(e.expr); auto e_ty = ty.expr_ty(e.expr);
auto src_res = trans_expr(r.bcx, e.expr); auto src_res = trans_expr(bcx, e.expr);
auto dst_elt = r.bcx.build.GEP(tup_val, vec(C_int(0), C_int(i))); bcx = src_res.bcx;
r = copy_ty(src_res.bcx, INIT, dst_elt, src_res.val, t); auto dst_res = GEP_tup_like(bcx, t, tup_val, vec(0, i));
bcx = dst_res.bcx;
bcx = copy_ty(src_res.bcx, INIT, dst_res.val, src_res.val, e_ty).bcx;
i += 1; i += 1;
} }
ret res(r.bcx, tup_val); ret res(bcx, tup_val);
} }
fn trans_vec(@block_ctxt cx, vec[@ast.expr] args, fn trans_vec(@block_ctxt cx, vec[@ast.expr] args,
@ -2891,44 +2901,58 @@ fn trans_vec(@block_ctxt cx, vec[@ast.expr] args,
// FIXME: pass tydesc properly. // FIXME: pass tydesc properly.
auto sub = trans_upcall(bcx, "upcall_new_vec", vec(data_sz, C_int(0))); auto sub = trans_upcall(bcx, "upcall_new_vec", vec(data_sz, C_int(0)));
bcx = sub.bcx;
auto llty = type_of(bcx.fcx.ccx, t); auto llty = type_of(bcx.fcx.ccx, t);
auto vec_val = sub.bcx.build.IntToPtr(sub.val, llty); auto vec_val = bcx.build.IntToPtr(sub.val, llty);
find_scope_cx(bcx).cleanups += clean(bind drop_ty(_, vec_val, t)); find_scope_cx(bcx).cleanups += clean(bind drop_ty(_, vec_val, t));
auto body = sub.bcx.build.GEP(vec_val, vec(C_int(0), auto body = bcx.build.GEP(vec_val, vec(C_int(0),
C_int(abi.vec_elt_data))); C_int(abi.vec_elt_data)));
auto pseudo_tup_ty =
plain_ty(ty.ty_tup(_vec.init_elt[@ty.t](unit_ty,
_vec.len[@ast.expr](args))));
let int i = 0; let int i = 0;
for (@ast.expr e in args) { for (@ast.expr e in args) {
auto src_res = trans_expr(sub.bcx, e); auto src_res = trans_expr(bcx, e);
auto dst_elt = sub.bcx.build.GEP(body, vec(C_int(0), C_int(i))); bcx = src_res.bcx;
sub = copy_ty(src_res.bcx, INIT, dst_elt, src_res.val, unit_ty); auto dst_res = GEP_tup_like(bcx, pseudo_tup_ty, body, vec(0, i));
bcx = dst_res.bcx;
bcx = copy_ty(bcx, INIT, dst_res.val, src_res.val, unit_ty).bcx;
i += 1; i += 1;
} }
auto fill = sub.bcx.build.GEP(vec_val, auto fill = bcx.build.GEP(vec_val,
vec(C_int(0), C_int(abi.vec_elt_fill))); vec(C_int(0), C_int(abi.vec_elt_fill)));
sub.bcx.build.Store(data_sz, fill); bcx.build.Store(data_sz, fill);
ret res(sub.bcx, vec_val); ret res(bcx, vec_val);
} }
fn trans_rec(@block_ctxt cx, vec[ast.field] fields, fn trans_rec(@block_ctxt cx, vec[ast.field] fields,
&ast.ann ann) -> result { &ast.ann ann) -> result {
auto t = node_ann_type(cx.fcx.ccx, ann);
auto llty = type_of(cx.fcx.ccx, t); auto bcx = cx;
auto rec_val = cx.build.Alloca(llty); auto t = node_ann_type(bcx.fcx.ccx, ann);
auto llty = type_of(bcx.fcx.ccx, t);
auto rec_res = alloc_ty(bcx, t);
auto rec_val = rec_res.val;
bcx = rec_res.bcx;
find_scope_cx(cx).cleanups += clean(bind drop_ty(_, rec_val, t)); find_scope_cx(cx).cleanups += clean(bind drop_ty(_, rec_val, t));
let int i = 0; let int i = 0;
auto r = res(cx, C_nil());
for (ast.field f in fields) { for (ast.field f in fields) {
auto t = ty.expr_ty(f.expr); auto e_ty = ty.expr_ty(f.expr);
auto src_res = trans_expr(r.bcx, f.expr); auto src_res = trans_expr(bcx, f.expr);
auto dst_elt = r.bcx.build.GEP(rec_val, vec(C_int(0), C_int(i))); bcx = src_res.bcx;
// FIXME: calculate copy init-ness in typestate. auto dst_res = GEP_tup_like(bcx, t, rec_val, vec(0, i));
r = copy_ty(src_res.bcx, INIT, dst_elt, src_res.val, t); bcx = dst_res.bcx;
bcx = copy_ty(src_res.bcx, INIT, dst_res.val, src_res.val, e_ty).bcx;
i += 1; i += 1;
} }
ret res(r.bcx, rec_val); ret res(bcx, rec_val);
} }
@ -3300,8 +3324,7 @@ iter block_locals(&ast.block b) -> @ast.local {
} }
} }
fn alloc_local(@block_ctxt cx, @ast.local local) -> result { fn alloc_ty(@block_ctxt cx, @ty.t t) -> result {
auto t = node_ann_type(cx.fcx.ccx, local.ann);
auto val = C_int(0); auto val = C_int(0);
auto bcx = cx; auto bcx = cx;
if (ty.type_has_dynamic_size(t)) { if (ty.type_has_dynamic_size(t)) {
@ -3311,10 +3334,16 @@ fn alloc_local(@block_ctxt cx, @ast.local local) -> result {
} else { } else {
val = bcx.build.Alloca(type_of(cx.fcx.ccx, t)); val = bcx.build.Alloca(type_of(cx.fcx.ccx, t));
} }
bcx.fcx.lllocals.insert(local.id, val);
ret res(bcx, val); ret res(bcx, val);
} }
fn alloc_local(@block_ctxt cx, @ast.local local) -> result {
auto t = node_ann_type(cx.fcx.ccx, local.ann);
auto r = alloc_ty(cx, t);
r.bcx.fcx.lllocals.insert(local.id, r.val);
ret r;
}
fn trans_block(@block_ctxt cx, &ast.block b) -> result { fn trans_block(@block_ctxt cx, &ast.block b) -> result {
auto bcx = cx; auto bcx = cx;