Skip to content

Commit d32d0f2

Browse files
committed
insert a field into the closure storing number of ty descs
1 parent f7cce6b commit d32d0f2

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

src/comp/back/abi.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,9 @@ const fn_field_code: int = 0;
7373
const fn_field_box: int = 1;
7474

7575
const closure_elt_tydesc: int = 0;
76-
7776
const closure_elt_bindings: int = 1;
78-
79-
const closure_elt_ty_params: int = 2;
77+
const closure_elt_n_ty_params: int = 2;
78+
const closure_elt_ty_params: int = 3;
8079

8180
const vec_elt_fill: int = 0;
8281

src/comp/middle/trans.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,11 +1336,15 @@ fn make_take_glue(cx: @block_ctxt, v: ValueRef, t: ty::t) {
13361336
bcx
13371337
}
13381338
ty::ty_fn(ast::proto_send., _, _, _, _) {
1339-
take_fn_env(bcx, v, { |bcx, _box_ptr_v|
1340-
bcx // NDM
1339+
take_fn_env(bcx, v, { |bcx, box_ptr_v|
1340+
// Here, box_ptr_v is a unique pointer which
1341+
// must be cloned.
1342+
call_bound_data_glue_for_closure(
1343+
bcx, box_ptr_v, abi::tydesc_field_take_glue);
1344+
bcx
13411345
})
13421346
}
1343-
ty::ty_fn(ast::proto_shared(_), _, _, _, _) {
1347+
ty::ty_native_fn(_, _) | ty::ty_fn(ast::proto_shared(_), _, _, _, _) {
13441348
take_fn_env(bcx, v, { |bcx, box_ptr_v|
13451349
incr_refcnt_of_boxed(bcx, box_ptr_v)
13461350
})
@@ -2633,6 +2637,7 @@ fn build_environment(bcx: @block_ctxt, lltydescs: [ValueRef],
26332637
};
26342638
}
26352639

2640+
let ccx = bcx_ccx(bcx);
26362641
let tcx = bcx_tcx(bcx);
26372642

26382643
// First, synthesize a tuple type containing the types of all the
@@ -2661,12 +2666,11 @@ fn build_environment(bcx: @block_ctxt, lltydescs: [ValueRef],
26612666
// ourselves) into a vector. The whole things ends up looking
26622667
// like:
26632668

2664-
// closure_tys = [tydesc_ty, [bound_ty1, bound_ty2, ...], [tydesc_ty,
2665-
// tydesc_ty, ...]]
2669+
// closure_ty = (tydesc_ty, (bound_ty1, bound_ty2, ...), int, (tydesc_ty,
2670+
// tydesc_ty, ...))
26662671
let closure_tys: [ty::t] =
2667-
[tydesc_ty, bindings_ty, ty::mk_tup(tcx, captured_tys)];
2668-
2669-
// Finally, synthesize a type for that whole vector.
2672+
[tydesc_ty, bindings_ty,
2673+
ty::mk_uint(tcx), ty::mk_tup(tcx, captured_tys)];
26702674
let closure_ty: ty::t = ty::mk_tup(tcx, closure_tys);
26712675

26722676
let temp_cleanups = [];
@@ -2758,13 +2762,17 @@ fn build_environment(bcx: @block_ctxt, lltydescs: [ValueRef],
27582762
// appropriate slot in the closure.
27592763
// Silly check as well
27602764
check type_is_tup_like(bcx, closure_ty);
2761-
let ty_params_slot =
2765+
let {bcx:bcx, val:n_ty_params_slot} =
2766+
GEP_tup_like(bcx, closure_ty, closure,
2767+
[0, abi::closure_elt_n_ty_params]);
2768+
Store(bcx, C_uint(ccx, vec::len(lltydescs)), n_ty_params_slot);
2769+
check type_is_tup_like(bcx, closure_ty);
2770+
let {bcx:bcx, val:ty_params_slot} =
27622771
GEP_tup_like(bcx, closure_ty, closure,
27632772
[0, abi::closure_elt_ty_params]);
2764-
bcx = ty_params_slot.bcx;
27652773
i = 0u;
27662774
for td: ValueRef in lltydescs {
2767-
let ty_param_slot = GEPi(bcx, ty_params_slot.val, [0, i as int]);
2775+
let ty_param_slot = GEPi(bcx, ty_params_slot, [0, i as int]);
27682776
let cloned_td = clone_tydesc(bcx, mode, td);
27692777
Store(bcx, cloned_td, ty_param_slot);
27702778
i += 1u;
@@ -3817,10 +3825,6 @@ fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
38173825
let tcx = bcx_tcx(in_cx);
38183826
let fn_expr_ty = ty::expr_ty(tcx, f);
38193827

3820-
//NDM if check type_is_native_fn_on_c_stack(tcx, fn_expr_ty) {
3821-
//NDM ret trans_c_stack_native_call(in_cx, f, args, dest);
3822-
//NDM }
3823-
38243828
let cx = new_scope_block_ctxt(in_cx, "call");
38253829
Br(in_cx, cx.llbb);
38263830
let f_res = trans_callee(cx, f);

src/comp/middle/trans_common.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,9 @@ fn T_closure_ptr(cx: @crate_ctxt, llbindings_ty: TypeRef,
693693
// NB: keep this in sync with code in trans_bind; we're making
694694
// an LLVM typeref structure that has the same "shape" as the ty::t
695695
// it constructs.
696-
ret T_ptr(T_box(cx, T_struct([T_ptr(cx.tydesc_type), llbindings_ty,
696+
ret T_ptr(T_box(cx, T_struct([T_ptr(cx.tydesc_type),
697+
llbindings_ty,
698+
cx.int_type,
697699
T_captured_tydescs(cx, n_ty_params)])));
698700
}
699701

0 commit comments

Comments
 (0)