@@ -4350,7 +4350,7 @@ fn trans_cast(cx: &@block_ctxt, e: &@ast::expr, id: ast::node_id) -> result {
4350
4350
fn trans_bind_thunk ( cx : & @local_ctxt , sp : & span , incoming_fty : & ty:: t ,
4351
4351
outgoing_fty : & ty:: t , args : & ( option:: t[ @ast:: expr ] ) [ ] ,
4352
4352
closure_ty : & ty:: t , bound_tys : & ty:: t [ ] ,
4353
- ty_param_count : uint ) -> ValueRef {
4353
+ ty_param_count : uint ) -> { val : ValueRef , ty : TypeRef } {
4354
4354
4355
4355
// Here we're not necessarily constructing a thunk in the sense of
4356
4356
// "function with no arguments". The result of compiling 'bind f(foo,
@@ -4520,7 +4520,7 @@ fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: &ty::t,
4520
4520
bcx. build . FastCall ( lltargetfn, llargs) ;
4521
4521
bcx. build . RetVoid ( ) ;
4522
4522
finish_fn ( fcx, lltop) ;
4523
- ret llthunk;
4523
+ ret { val : llthunk, ty : llthunk_ty } ;
4524
4524
}
4525
4525
4526
4526
fn trans_bind ( cx : & @block_ctxt , f : & @ast:: expr ,
@@ -4552,15 +4552,13 @@ fn trans_bind_1(cx: &@block_ctxt, f: &@ast::expr, f_res: &lval_result,
4552
4552
lltydescs = ginfo. tydescs ;
4553
4553
}
4554
4554
}
4555
- let ty_param_count = std:: ivec:: len[ ValueRef ] ( lltydescs) ;
4556
- if std:: ivec:: len[ @ast:: expr] ( bound) == 0 u && ty_param_count == 0 u {
4557
4555
4556
+ let ty_param_count = std:: ivec:: len ( lltydescs) ;
4557
+ if std:: ivec:: len ( bound) == 0 u && ty_param_count == 0 u {
4558
4558
// Trivial 'binding': just return the static pair-ptr.
4559
4559
ret f_res. res ;
4560
4560
}
4561
4561
let bcx = f_res. res . bcx ;
4562
- let pair_t = node_type ( bcx_ccx ( cx) , cx. sp , id) ;
4563
- let pair_v = alloca ( bcx, pair_t) ;
4564
4562
4565
4563
// Translate the bound expressions.
4566
4564
let bound_tys: ty:: t [ ] = ~[ ] ;
@@ -4675,23 +4673,15 @@ fn trans_bind_1(cx: &@block_ctxt, f: &@ast::expr, f_res: &lval_result,
4675
4673
}
4676
4674
}
4677
4675
4678
- // Make thunk and store thunk-ptr in outer pair's code slot.
4679
- let pair_code =
4680
- bcx. build . GEP ( pair_v, ~[ C_int ( 0 ) , C_int ( abi:: fn_field_code) ] ) ;
4676
+ // Make thunk
4681
4677
// The type of the entire bind expression.
4682
- let pair_ty: ty:: t = node_id_type ( bcx_ccx ( cx) , id) ;
4678
+ let pair_ty = node_id_type ( bcx_ccx ( cx) , id) ;
4679
+ let llthunk =
4680
+ trans_bind_thunk ( cx. fcx . lcx , cx. sp , pair_ty, outgoing_fty,
4681
+ args, closure_ty, bound_tys, ty_param_count) ;
4683
4682
4684
- let llthunk: ValueRef =
4685
- trans_bind_thunk ( cx. fcx . lcx , cx. sp , pair_ty, outgoing_fty, args,
4686
- closure_ty, bound_tys, ty_param_count) ;
4687
- bcx. build . Store ( llthunk, pair_code) ;
4688
-
4689
- // Store box ptr in outer pair's box slot.
4690
- let ccx = * bcx_ccx ( bcx) ;
4691
- let pair_box =
4692
- bcx. build . GEP ( pair_v, ~[ C_int ( 0 ) , C_int ( abi:: fn_field_box) ] ) ;
4693
- bcx. build . Store ( bcx. build . PointerCast ( box, T_opaque_closure_ptr ( ccx) ) ,
4694
- pair_box) ;
4683
+ // Construct the function pair
4684
+ let pair_v = create_real_fn_pair ( bcx, llthunk. ty , llthunk. val , box) ;
4695
4685
add_clean_temp ( cx, pair_v, pair_ty) ;
4696
4686
ret rslt( bcx, pair_v) ;
4697
4687
}
0 commit comments