Mop up cases of s/copy/take/, remove 'binding' terminology, whitespace police, and make obj/fn structural.

This commit is contained in:
Graydon Hoare 2010-12-20 16:23:49 -08:00
parent e70c695ab9
commit 86188da348
3 changed files with 37 additions and 41 deletions

View File

@ -31,7 +31,7 @@ const int vec_elt_data = 3;
const int tydesc_field_first_param = 0; const int tydesc_field_first_param = 0;
const int tydesc_field_size = 1; const int tydesc_field_size = 1;
const int tydesc_field_align = 2; const int tydesc_field_align = 2;
const int tydesc_field_copy_glue_off = 3; const int tydesc_field_take_glue_off = 3;
const int tydesc_field_drop_glue_off = 4; const int tydesc_field_drop_glue_off = 4;
const int tydesc_field_free_glue_off = 5; const int tydesc_field_free_glue_off = 5;
const int tydesc_field_sever_glue_off = 6; const int tydesc_field_sever_glue_off = 6;
@ -40,22 +40,14 @@ const int tydesc_field_obj_drop_glue_off = 8;
const int tydesc_field_is_stateful = 9; const int tydesc_field_is_stateful = 9;
/* Both obj and fn are two-word "bindings": One word points to some static const int obj_field_vtbl = 0;
* dispatch information (vtbl, thunk, callee), and the other points to some const int obj_field_box = 1;
* box of bound data (object-body or closure).
*/
const int binding_field_dispatch = 0;
const int binding_field_bound_data = 1;
const int obj_field_vtbl = binding_field_dispatch;
const int obj_field_box = binding_field_bound_data;
const int obj_body_elt_tydesc = 0; const int obj_body_elt_tydesc = 0;
const int obj_body_elt_fields = 1; const int obj_body_elt_fields = 1;
const int fn_field_code = binding_field_dispatch; const int fn_field_code = 0;
const int fn_field_box = binding_field_bound_data; const int fn_field_box = 1;
const int worst_case_glue_call_args = 7; const int worst_case_glue_call_args = 7;

View File

@ -57,8 +57,6 @@ type tag_info = rec(type_handle th,
mutable vec[tup(ast.def_id,arity)] variants, mutable vec[tup(ast.def_id,arity)] variants,
mutable uint size); mutable uint size);
type ty_info = rec(ValueRef take_glue, ValueRef drop_glue);
state type crate_ctxt = rec(session.session sess, state type crate_ctxt = rec(session.session sess,
ModuleRef llmod, ModuleRef llmod,
target_data td, target_data td,
@ -222,7 +220,7 @@ fn T_tydesc() -> TypeRef {
ret T_struct(vec(pvoid, // first_param ret T_struct(vec(pvoid, // first_param
T_int(), // size T_int(), // size
T_int(), // align T_int(), // align
glue_fn_ty, // copy_glue_off glue_fn_ty, // take_glue_off
glue_fn_ty, // drop_glue_off glue_fn_ty, // drop_glue_off
glue_fn_ty, // free_glue_off glue_fn_ty, // free_glue_off
glue_fn_ty, // sever_glue_off glue_fn_ty, // sever_glue_off
@ -375,7 +373,7 @@ fn type_of_inner(@crate_ctxt cx, @typeck.ty t) -> TypeRef {
let TypeRef vtbl = T_struct(mtys); let TypeRef vtbl = T_struct(mtys);
let TypeRef pair = let TypeRef pair =
T_struct(vec(T_ptr(vtbl), T_struct(vec(T_ptr(vtbl),
T_ptr(T_box(T_opaque())))); T_ptr(T_box(T_nil()))));
ret pair; ret pair;
} }
case (typeck.ty_var(_)) { case (typeck.ty_var(_)) {
@ -614,7 +612,7 @@ fn make_tydesc(@crate_ctxt cx, @typeck.ty ty) {
auto tydesc = C_struct(vec(C_null(pvoid), auto tydesc = C_struct(vec(C_null(pvoid),
size_of(llty), size_of(llty),
align_of(llty), align_of(llty),
take_glue, // copy_glue_off take_glue, // take_glue_off
drop_glue, // drop_glue_off drop_glue, // drop_glue_off
C_null(glue_fn_ty), // free_glue_off C_null(glue_fn_ty), // free_glue_off
C_null(glue_fn_ty), // sever_glue_off C_null(glue_fn_ty), // sever_glue_off
@ -665,9 +663,6 @@ fn make_take_glue(@block_ctxt cx, ValueRef v, @typeck.ty t) -> result {
if (typeck.type_is_boxed(t)) { if (typeck.type_is_boxed(t)) {
ret incr_refcnt_of_boxed(cx, v); ret incr_refcnt_of_boxed(cx, v);
} else if (typeck.type_is_binding(t)) {
cx.fcx.ccx.sess.unimpl("binding type in trans.incr_all_refcnts");
} else if (typeck.type_is_structural(t)) { } else if (typeck.type_is_structural(t)) {
ret iter_structural_ty(cx, v, t, ret iter_structural_ty(cx, v, t,
bind incr_all_refcnts(_, _, _)); bind incr_all_refcnts(_, _, _));
@ -739,10 +734,6 @@ fn make_drop_glue(@block_ctxt cx, ValueRef v, @typeck.ty t) -> result {
ret iter_structural_ty(cx, v, t, ret iter_structural_ty(cx, v, t,
bind drop_ty(_, _, _)); bind drop_ty(_, _, _));
} else if (typeck.type_is_binding(t)) {
cx.fcx.ccx.sess.unimpl("binding type in " +
"trans.make_drop_glue_inner");
} else if (typeck.type_is_scalar(t) || } else if (typeck.type_is_scalar(t) ||
typeck.type_is_nil(t)) { typeck.type_is_nil(t)) {
ret res(cx, C_nil()); ret res(cx, C_nil());
@ -813,13 +804,14 @@ fn type_of_variant(@crate_ctxt cx, &ast.variant v) -> TypeRef {
type val_and_ty_fn = type val_and_ty_fn =
fn(@block_ctxt cx, ValueRef v, @typeck.ty t) -> result; fn(@block_ctxt cx, ValueRef v, @typeck.ty t) -> result;
// Iterates through the elements of a box, tup, rec or tag. // Iterates through the elements of a structural type.
fn iter_structural_ty(@block_ctxt cx, fn iter_structural_ty(@block_ctxt cx,
ValueRef v, ValueRef v,
@typeck.ty t, @typeck.ty t,
val_and_ty_fn f) val_and_ty_fn f)
-> result { -> result {
let result r = res(cx, C_nil()); let result r = res(cx, C_nil());
alt (t.struct) { alt (t.struct) {
case (typeck.ty_tup(?args)) { case (typeck.ty_tup(?args)) {
let int i = 0; let int i = 0;
@ -922,6 +914,26 @@ fn iter_structural_ty(@block_ctxt cx,
ret res(next_cx, C_nil()); ret res(next_cx, C_nil());
} }
case (typeck.ty_fn(_,_)) {
auto box_cell =
cx.build.GEP(v,
vec(C_int(0),
C_int(abi.fn_field_box)));
auto box_ptr = cx.build.Load(box_cell);
auto tnil = typeck.plain_ty(typeck.ty_nil);
auto tbox = typeck.plain_ty(typeck.ty_box(tnil));
ret f(cx, box_ptr, tbox);
}
case (typeck.ty_obj(_)) {
auto box_cell =
cx.build.GEP(v,
vec(C_int(0),
C_int(abi.obj_field_box)));
auto box_ptr = cx.build.Load(box_cell);
auto tnil = typeck.plain_ty(typeck.ty_nil);
auto tbox = typeck.plain_ty(typeck.ty_box(tnil));
ret f(cx, box_ptr, tbox);
}
case (_) { case (_) {
cx.fcx.ccx.sess.unimpl("type in iter_structural_ty"); cx.fcx.ccx.sess.unimpl("type in iter_structural_ty");
} }
@ -1004,9 +1016,10 @@ fn iter_sequence(@block_ctxt cx,
fn incr_all_refcnts(@block_ctxt cx, fn incr_all_refcnts(@block_ctxt cx,
ValueRef v, ValueRef v,
@typeck.ty t) -> result { @typeck.ty t) -> result {
if (!typeck.type_is_scalar(t)) { if (!typeck.type_is_scalar(t)) {
auto llrawptr = cx.build.BitCast(v, T_ptr(T_i8())); auto llrawptr = cx.build.BitCast(v, T_ptr(T_i8()));
auto llfnptr = field_of_tydesc(cx, t, abi.tydesc_field_copy_glue_off); auto llfnptr = field_of_tydesc(cx, t, abi.tydesc_field_take_glue_off);
auto llfn = cx.build.Load(llfnptr); auto llfn = cx.build.Load(llfnptr);
cx.build.FastCall(llfn, vec(cx.fcx.lltaskptr, llrawptr)); cx.build.FastCall(llfn, vec(cx.fcx.lltaskptr, llrawptr));
} }
@ -1028,6 +1041,7 @@ fn drop_slot(@block_ctxt cx,
fn drop_ty(@block_ctxt cx, fn drop_ty(@block_ctxt cx,
ValueRef v, ValueRef v,
@typeck.ty t) -> result { @typeck.ty t) -> result {
if (!typeck.type_is_scalar(t)) { if (!typeck.type_is_scalar(t)) {
auto llrawptr = cx.build.BitCast(v, T_ptr(T_i8())); auto llrawptr = cx.build.BitCast(v, T_ptr(T_i8()));
auto llfnptr = field_of_tydesc(cx, t, abi.tydesc_field_drop_glue_off); auto llfnptr = field_of_tydesc(cx, t, abi.tydesc_field_drop_glue_off);
@ -1072,9 +1086,6 @@ fn copy_ty(@block_ctxt cx,
} else if (typeck.type_is_nil(t)) { } else if (typeck.type_is_nil(t)) {
ret res(cx, C_nil()); ret res(cx, C_nil());
} else if (typeck.type_is_binding(t)) {
cx.fcx.ccx.sess.unimpl("binding type in trans.copy_ty");
} else if (typeck.type_is_boxed(t)) { } else if (typeck.type_is_boxed(t)) {
auto r = incr_all_refcnts(cx, src, t); auto r = incr_all_refcnts(cx, src, t);
if (! is_init) { if (! is_init) {
@ -1452,7 +1463,7 @@ impure fn trans_pat_match(@block_ctxt cx, @ast.pat pat, ValueRef llval,
case (ast.pat_tag(?id, ?subpats, ?vdef_opt, ?ann)) { case (ast.pat_tag(?id, ?subpats, ?vdef_opt, ?ann)) {
auto lltagptr = cx.build.GEP(llval, vec(C_int(0), C_int(0))); auto lltagptr = cx.build.GEP(llval, vec(C_int(0), C_int(0)));
auto lltag = cx.build.Load(lltagptr); auto lltag = cx.build.Load(lltagptr);
auto vdef = option.get[ast.variant_def](vdef_opt); auto vdef = option.get[ast.variant_def](vdef_opt);
auto variant_id = vdef._1; auto variant_id = vdef._1;
auto tinfo = cx.fcx.ccx.tags.get(vdef._0); auto tinfo = cx.fcx.ccx.tags.get(vdef._0);
@ -2423,7 +2434,7 @@ impure fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
vec(C_int(0), vec(C_int(0),
C_int(abi.obj_field_vtbl))); C_int(abi.obj_field_vtbl)));
bcx.build.Store(vtbl, pair_vtbl); bcx.build.Store(vtbl, pair_vtbl);
bcx.build.Ret(pair); bcx.build.Ret(bcx.build.Load(pair));
} }
fn trans_tag_variant(@crate_ctxt cx, ast.def_id tag_id, fn trans_tag_variant(@crate_ctxt cx, ast.def_id tag_id,

View File

@ -861,15 +861,8 @@ fn type_is_structural(@ty t) -> bool {
case (ty_tup(_)) { ret true; } case (ty_tup(_)) { ret true; }
case (ty_rec(_)) { ret true; } case (ty_rec(_)) { ret true; }
case (ty_tag(_)) { ret true; } case (ty_tag(_)) { ret true; }
case (_) { ret false; }
}
fail;
}
fn type_is_binding(@ty t) -> bool {
alt (t.struct) {
// FIXME: cover obj when we support it.
case (ty_fn(_,_)) { ret true; } case (ty_fn(_,_)) { ret true; }
case (ty_obj(_)) { ret true; }
case (_) { ret false; } case (_) { ret false; }
} }
fail; fail;
@ -1007,7 +1000,7 @@ fn count_ty_params(@ty t) -> uint {
ret t; ret t;
} }
} }
let vec[ast.def_id] param_ids_inner = vec(); let vec[ast.def_id] param_ids_inner = vec();
let @mutable vec[ast.def_id] param_ids = @mutable param_ids_inner; let @mutable vec[ast.def_id] param_ids = @mutable param_ids_inner;
fold_ty(ty_param_counter(param_ids), t); fold_ty(ty_param_counter(param_ids), t);