]> git.lizzy.rs Git - rust.git/commitdiff
insert a field into the closure storing number of ty descs
authorNiko Matsakis <niko@alum.mit.edu>
Wed, 14 Dec 2011 16:16:15 +0000 (08:16 -0800)
committerNiko Matsakis <niko@alum.mit.edu>
Wed, 14 Dec 2011 22:32:27 +0000 (14:32 -0800)
src/comp/back/abi.rs
src/comp/middle/trans.rs
src/comp/middle/trans_common.rs

index bfb46a94d7707e07cd0da3de6970c5aad5b3dabb..28a9d239d574417770c9513e8de1cb47bebc2f2c 100644 (file)
 const fn_field_box: int = 1;
 
 const closure_elt_tydesc: int = 0;
-
 const closure_elt_bindings: int = 1;
-
-const closure_elt_ty_params: int = 2;
+const closure_elt_n_ty_params: int = 2;
+const closure_elt_ty_params: int = 3;
 
 const vec_elt_fill: int = 0;
 
index 170351a1406a067afe36895138f3ed6851c17f40..37d4eff1cdcd09b15a3b755c11ddd5d6701bdcd6 100644 (file)
@@ -1336,11 +1336,15 @@ fn take_fn_env(cx: @block_ctxt,
         bcx
       }
       ty::ty_fn(ast::proto_send., _, _, _, _) {
-        take_fn_env(bcx, v, { |bcx, _box_ptr_v|
-            bcx // NDM
+        take_fn_env(bcx, v, { |bcx, box_ptr_v|
+            // Here, box_ptr_v is a unique pointer which
+            // must be cloned.
+            call_bound_data_glue_for_closure(
+                bcx, box_ptr_v, abi::tydesc_field_take_glue);
+            bcx
         })
       }
-      ty::ty_fn(ast::proto_shared(_), _, _, _, _) {
+      ty::ty_native_fn(_, _) | ty::ty_fn(ast::proto_shared(_), _, _, _, _) {
         take_fn_env(bcx, v, { |bcx, box_ptr_v|
             incr_refcnt_of_boxed(bcx, box_ptr_v)
         })
@@ -2633,6 +2637,7 @@ fn clone_tydesc(bcx: @block_ctxt,
         };
     }
 
+    let ccx = bcx_ccx(bcx);
     let tcx = bcx_tcx(bcx);
 
     // First, synthesize a tuple type containing the types of all the
@@ -2661,12 +2666,11 @@ fn clone_tydesc(bcx: @block_ctxt,
     // ourselves) into a vector.  The whole things ends up looking
     // like:
 
-    // closure_tys = [tydesc_ty, [bound_ty1, bound_ty2, ...], [tydesc_ty,
-    // tydesc_ty, ...]]
+    // closure_ty = (tydesc_ty, (bound_ty1, bound_ty2, ...), int, (tydesc_ty,
+    // tydesc_ty, ...))
     let closure_tys: [ty::t] =
-        [tydesc_ty, bindings_ty, ty::mk_tup(tcx, captured_tys)];
-
-    // Finally, synthesize a type for that whole vector.
+        [tydesc_ty, bindings_ty,
+         ty::mk_uint(tcx), ty::mk_tup(tcx, captured_tys)];
     let closure_ty: ty::t = ty::mk_tup(tcx, closure_tys);
 
     let temp_cleanups = [];
@@ -2758,13 +2762,17 @@ fn clone_tydesc(bcx: @block_ctxt,
     // appropriate slot in the closure.
     // Silly check as well
     check type_is_tup_like(bcx, closure_ty);
-    let ty_params_slot =
+    let {bcx:bcx, val:n_ty_params_slot} =
+        GEP_tup_like(bcx, closure_ty, closure,
+                     [0, abi::closure_elt_n_ty_params]);
+    Store(bcx, C_uint(ccx, vec::len(lltydescs)), n_ty_params_slot);
+    check type_is_tup_like(bcx, closure_ty);
+    let {bcx:bcx, val:ty_params_slot} =
         GEP_tup_like(bcx, closure_ty, closure,
                      [0, abi::closure_elt_ty_params]);
-    bcx = ty_params_slot.bcx;
     i = 0u;
     for td: ValueRef in lltydescs {
-        let ty_param_slot = GEPi(bcx, ty_params_slot.val, [0, i as int]);
+        let ty_param_slot = GEPi(bcx, ty_params_slot, [0, i as int]);
         let cloned_td = clone_tydesc(bcx, mode, td);
         Store(bcx, cloned_td, ty_param_slot);
         i += 1u;
@@ -3817,10 +3825,6 @@ fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
     let tcx = bcx_tcx(in_cx);
     let fn_expr_ty = ty::expr_ty(tcx, f);
 
-//NDM    if check type_is_native_fn_on_c_stack(tcx, fn_expr_ty) {
-//NDM        ret trans_c_stack_native_call(in_cx, f, args, dest);
-//NDM    }
-
     let cx = new_scope_block_ctxt(in_cx, "call");
     Br(in_cx, cx.llbb);
     let f_res = trans_callee(cx, f);
index 2b2d95fc52f85d67060ea41107f7b8ef7171d89f..1bf3bd38931ee89dbc63fba73706ae18debd45a1 100644 (file)
@@ -693,7 +693,9 @@ fn T_closure_ptr(cx: @crate_ctxt, llbindings_ty: TypeRef,
     // NB: keep this in sync with code in trans_bind; we're making
     // an LLVM typeref structure that has the same "shape" as the ty::t
     // it constructs.
-    ret T_ptr(T_box(cx, T_struct([T_ptr(cx.tydesc_type), llbindings_ty,
+    ret T_ptr(T_box(cx, T_struct([T_ptr(cx.tydesc_type),
+                                  llbindings_ty,
+                                  cx.int_type,
                                   T_captured_tydescs(cx, n_ty_params)])));
 }