Skip to content

Commit 80244c9

Browse files
committed
---
yaml --- r: 1124 b: refs/heads/master c: 86188da h: refs/heads/master v: v3
1 parent 296984c commit 80244c9

File tree

4 files changed

+38
-42
lines changed

4 files changed

+38
-42
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: e70c695ab9a910f4079088c439a2efbf5ab9c447
2+
refs/heads/master: 86188da3483b35ffd3d118600d55437c5233438c

trunk/src/comp/back/abi.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const int vec_elt_data = 3;
3131
const int tydesc_field_first_param = 0;
3232
const int tydesc_field_size = 1;
3333
const int tydesc_field_align = 2;
34-
const int tydesc_field_copy_glue_off = 3;
34+
const int tydesc_field_take_glue_off = 3;
3535
const int tydesc_field_drop_glue_off = 4;
3636
const int tydesc_field_free_glue_off = 5;
3737
const int tydesc_field_sever_glue_off = 6;
@@ -40,22 +40,14 @@ const int tydesc_field_obj_drop_glue_off = 8;
4040
const int tydesc_field_is_stateful = 9;
4141

4242

43-
/* Both obj and fn are two-word "bindings": One word points to some static
44-
* dispatch information (vtbl, thunk, callee), and the other points to some
45-
* box of bound data (object-body or closure).
46-
*/
47-
48-
const int binding_field_dispatch = 0;
49-
const int binding_field_bound_data = 1;
50-
51-
const int obj_field_vtbl = binding_field_dispatch;
52-
const int obj_field_box = binding_field_bound_data;
43+
const int obj_field_vtbl = 0;
44+
const int obj_field_box = 1;
5345

5446
const int obj_body_elt_tydesc = 0;
5547
const int obj_body_elt_fields = 1;
5648

57-
const int fn_field_code = binding_field_dispatch;
58-
const int fn_field_box = binding_field_bound_data;
49+
const int fn_field_code = 0;
50+
const int fn_field_box = 1;
5951

6052
const int worst_case_glue_call_args = 7;
6153

trunk/src/comp/middle/trans.rs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ type tag_info = rec(type_handle th,
5757
mutable vec[tup(ast.def_id,arity)] variants,
5858
mutable uint size);
5959

60-
type ty_info = rec(ValueRef take_glue, ValueRef drop_glue);
61-
6260
state type crate_ctxt = rec(session.session sess,
6361
ModuleRef llmod,
6462
target_data td,
@@ -222,7 +220,7 @@ fn T_tydesc() -> TypeRef {
222220
ret T_struct(vec(pvoid, // first_param
223221
T_int(), // size
224222
T_int(), // align
225-
glue_fn_ty, // copy_glue_off
223+
glue_fn_ty, // take_glue_off
226224
glue_fn_ty, // drop_glue_off
227225
glue_fn_ty, // free_glue_off
228226
glue_fn_ty, // sever_glue_off
@@ -375,7 +373,7 @@ fn type_of_inner(@crate_ctxt cx, @typeck.ty t) -> TypeRef {
375373
let TypeRef vtbl = T_struct(mtys);
376374
let TypeRef pair =
377375
T_struct(vec(T_ptr(vtbl),
378-
T_ptr(T_box(T_opaque()))));
376+
T_ptr(T_box(T_nil()))));
379377
ret pair;
380378
}
381379
case (typeck.ty_var(_)) {
@@ -614,7 +612,7 @@ fn make_tydesc(@crate_ctxt cx, @typeck.ty ty) {
614612
auto tydesc = C_struct(vec(C_null(pvoid),
615613
size_of(llty),
616614
align_of(llty),
617-
take_glue, // copy_glue_off
615+
take_glue, // take_glue_off
618616
drop_glue, // drop_glue_off
619617
C_null(glue_fn_ty), // free_glue_off
620618
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 {
665663
if (typeck.type_is_boxed(t)) {
666664
ret incr_refcnt_of_boxed(cx, v);
667665

668-
} else if (typeck.type_is_binding(t)) {
669-
cx.fcx.ccx.sess.unimpl("binding type in trans.incr_all_refcnts");
670-
671666
} else if (typeck.type_is_structural(t)) {
672667
ret iter_structural_ty(cx, v, t,
673668
bind incr_all_refcnts(_, _, _));
@@ -739,10 +734,6 @@ fn make_drop_glue(@block_ctxt cx, ValueRef v, @typeck.ty t) -> result {
739734
ret iter_structural_ty(cx, v, t,
740735
bind drop_ty(_, _, _));
741736

742-
} else if (typeck.type_is_binding(t)) {
743-
cx.fcx.ccx.sess.unimpl("binding type in " +
744-
"trans.make_drop_glue_inner");
745-
746737
} else if (typeck.type_is_scalar(t) ||
747738
typeck.type_is_nil(t)) {
748739
ret res(cx, C_nil());
@@ -813,13 +804,14 @@ fn type_of_variant(@crate_ctxt cx, &ast.variant v) -> TypeRef {
813804
type val_and_ty_fn =
814805
fn(@block_ctxt cx, ValueRef v, @typeck.ty t) -> result;
815806

816-
// Iterates through the elements of a box, tup, rec or tag.
807+
// Iterates through the elements of a structural type.
817808
fn iter_structural_ty(@block_ctxt cx,
818809
ValueRef v,
819810
@typeck.ty t,
820811
val_and_ty_fn f)
821812
-> result {
822813
let result r = res(cx, C_nil());
814+
823815
alt (t.struct) {
824816
case (typeck.ty_tup(?args)) {
825817
let int i = 0;
@@ -922,6 +914,26 @@ fn iter_structural_ty(@block_ctxt cx,
922914

923915
ret res(next_cx, C_nil());
924916
}
917+
case (typeck.ty_fn(_,_)) {
918+
auto box_cell =
919+
cx.build.GEP(v,
920+
vec(C_int(0),
921+
C_int(abi.fn_field_box)));
922+
auto box_ptr = cx.build.Load(box_cell);
923+
auto tnil = typeck.plain_ty(typeck.ty_nil);
924+
auto tbox = typeck.plain_ty(typeck.ty_box(tnil));
925+
ret f(cx, box_ptr, tbox);
926+
}
927+
case (typeck.ty_obj(_)) {
928+
auto box_cell =
929+
cx.build.GEP(v,
930+
vec(C_int(0),
931+
C_int(abi.obj_field_box)));
932+
auto box_ptr = cx.build.Load(box_cell);
933+
auto tnil = typeck.plain_ty(typeck.ty_nil);
934+
auto tbox = typeck.plain_ty(typeck.ty_box(tnil));
935+
ret f(cx, box_ptr, tbox);
936+
}
925937
case (_) {
926938
cx.fcx.ccx.sess.unimpl("type in iter_structural_ty");
927939
}
@@ -1004,9 +1016,10 @@ fn iter_sequence(@block_ctxt cx,
10041016
fn incr_all_refcnts(@block_ctxt cx,
10051017
ValueRef v,
10061018
@typeck.ty t) -> result {
1019+
10071020
if (!typeck.type_is_scalar(t)) {
10081021
auto llrawptr = cx.build.BitCast(v, T_ptr(T_i8()));
1009-
auto llfnptr = field_of_tydesc(cx, t, abi.tydesc_field_copy_glue_off);
1022+
auto llfnptr = field_of_tydesc(cx, t, abi.tydesc_field_take_glue_off);
10101023
auto llfn = cx.build.Load(llfnptr);
10111024
cx.build.FastCall(llfn, vec(cx.fcx.lltaskptr, llrawptr));
10121025
}
@@ -1028,6 +1041,7 @@ fn drop_slot(@block_ctxt cx,
10281041
fn drop_ty(@block_ctxt cx,
10291042
ValueRef v,
10301043
@typeck.ty t) -> result {
1044+
10311045
if (!typeck.type_is_scalar(t)) {
10321046
auto llrawptr = cx.build.BitCast(v, T_ptr(T_i8()));
10331047
auto llfnptr = field_of_tydesc(cx, t, abi.tydesc_field_drop_glue_off);
@@ -1072,9 +1086,6 @@ fn copy_ty(@block_ctxt cx,
10721086
} else if (typeck.type_is_nil(t)) {
10731087
ret res(cx, C_nil());
10741088

1075-
} else if (typeck.type_is_binding(t)) {
1076-
cx.fcx.ccx.sess.unimpl("binding type in trans.copy_ty");
1077-
10781089
} else if (typeck.type_is_boxed(t)) {
10791090
auto r = incr_all_refcnts(cx, src, t);
10801091
if (! is_init) {
@@ -1452,7 +1463,7 @@ impure fn trans_pat_match(@block_ctxt cx, @ast.pat pat, ValueRef llval,
14521463
case (ast.pat_tag(?id, ?subpats, ?vdef_opt, ?ann)) {
14531464
auto lltagptr = cx.build.GEP(llval, vec(C_int(0), C_int(0)));
14541465
auto lltag = cx.build.Load(lltagptr);
1455-
1466+
14561467
auto vdef = option.get[ast.variant_def](vdef_opt);
14571468
auto variant_id = vdef._1;
14581469
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,
24232434
vec(C_int(0),
24242435
C_int(abi.obj_field_vtbl)));
24252436
bcx.build.Store(vtbl, pair_vtbl);
2426-
bcx.build.Ret(pair);
2437+
bcx.build.Ret(bcx.build.Load(pair));
24272438
}
24282439

24292440
fn trans_tag_variant(@crate_ctxt cx, ast.def_id tag_id,

trunk/src/comp/middle/typeck.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -861,15 +861,8 @@ fn type_is_structural(@ty t) -> bool {
861861
case (ty_tup(_)) { ret true; }
862862
case (ty_rec(_)) { ret true; }
863863
case (ty_tag(_)) { ret true; }
864-
case (_) { ret false; }
865-
}
866-
fail;
867-
}
868-
869-
fn type_is_binding(@ty t) -> bool {
870-
alt (t.struct) {
871-
// FIXME: cover obj when we support it.
872864
case (ty_fn(_,_)) { ret true; }
865+
case (ty_obj(_)) { ret true; }
873866
case (_) { ret false; }
874867
}
875868
fail;
@@ -1007,7 +1000,7 @@ fn count_ty_params(@ty t) -> uint {
10071000
ret t;
10081001
}
10091002
}
1010-
1003+
10111004
let vec[ast.def_id] param_ids_inner = vec();
10121005
let @mutable vec[ast.def_id] param_ids = @mutable param_ids_inner;
10131006
fold_ty(ty_param_counter(param_ids), t);

0 commit comments

Comments
 (0)