@@ -3671,8 +3671,8 @@ fn build_environment_heap(bcx: @block_ctxt, lltydescs: ValueRef[],
3671
3671
// ourselves) into a vector. The whole things ends up looking
3672
3672
// like:
3673
3673
3674
- // closure_tys = [tydesc_ty, outgoing_fty, [bound_ty1, bound_ty2,
3675
- // ...], [tydesc_ty, tydesc_ty, ...]]
3674
+ // closure_tys = [tydesc_ty, [bound_ty1, bound_ty2, ...], [tydesc_ty ,
3675
+ // tydesc_ty, ...]]
3676
3676
let closure_tys: ty:: t [ ] =
3677
3677
~[ tydesc_ty, bindings_ty, ty:: mk_imm_tup ( bcx_tcx ( bcx) , captured_tys) ] ;
3678
3678
@@ -3697,22 +3697,27 @@ fn build_environment_heap(bcx: @block_ctxt, lltydescs: ValueRef[],
3697
3697
// Copy expr values into boxed bindings.
3698
3698
let i = 0 u;
3699
3699
let bindings =
3700
- bcx. build . GEP ( closure, ~[ C_int ( 0 ) , C_int ( abi:: closure_elt_bindings) ] ) ;
3700
+ GEP_tup_like ( bcx, closure_ty, closure,
3701
+ ~[ 0 , abi:: closure_elt_bindings] ) ;
3702
+ bcx = bindings. bcx ;
3701
3703
for lv: lval_result in bound_vals {
3702
- let bound = bcx. build . GEP ( bindings, ~[ C_int ( 0 ) , C_int ( i as int ) ] ) ;
3703
- bcx = move_val_if_temp ( bcx, INIT , bound, lv, bound_tys. ( i) ) . bcx ;
3704
+ let bound = GEP_tup_like ( bcx, bindings_ty, bindings. val ,
3705
+ ~[ 0 , i as int ] ) ;
3706
+ bcx = move_val_if_temp ( bound. bcx , INIT ,
3707
+ bound. val , lv, bound_tys. ( i) ) . bcx ;
3704
3708
i += 1 u;
3705
3709
}
3706
3710
3707
3711
// If necessary, copy tydescs describing type parameters into the
3708
3712
// appropriate slot in the closure.
3709
3713
let ty_params_slot =
3710
- bcx. build . GEP ( closure,
3711
- ~[ C_int ( 0 ) , C_int ( abi:: closure_elt_ty_params) ] ) ;
3714
+ GEP_tup_like ( bcx, closure_ty, closure,
3715
+ ~[ 0 , abi:: closure_elt_ty_params] ) ;
3716
+ bcx = ty_params_slot. bcx ;
3712
3717
i = 0 u;
3713
3718
for td: ValueRef in lltydescs {
3714
3719
let ty_param_slot =
3715
- bcx. build . GEP ( ty_params_slot, ~[ C_int ( 0 ) , C_int ( i as int ) ] ) ;
3720
+ bcx. build . GEP ( ty_params_slot. val , ~[ C_int ( 0 ) , C_int ( i as int ) ] ) ;
3716
3721
bcx. build . Store ( td, ty_param_slot) ;
3717
3722
i += 1 u;
3718
3723
}
@@ -3802,34 +3807,33 @@ fn load_environment_heap(enclosing_cx: &@block_ctxt, fcx: &@fn_ctxt,
3802
3807
envty : & ty:: t , upvars : & @ast:: node_id [ ] ) {
3803
3808
let bcx = new_raw_block_ctxt ( fcx, fcx. llcopyargs ) ;
3804
3809
3805
- let llenvptr =
3806
- bcx. build . GEP ( fcx. llenv , ~[ C_int ( 0 ) , C_int ( abi:: box_rc_field_body) ] ) ;
3807
- let llenvptrty = T_ptr ( type_of ( bcx_ccx ( bcx) , bcx. sp , envty) ) ; ;
3808
- llenvptr = bcx. build . PointerCast ( llenvptr, llenvptrty) ;
3810
+ let ty = ty:: mk_imm_box ( bcx_tcx ( bcx) , envty) ;
3811
+ let llty = type_of ( bcx_ccx ( bcx) , bcx. sp , ty) ;
3812
+ let llclosure = bcx. build . PointerCast ( fcx. llenv , llty) ;
3813
+
3814
+ let path = ~[ 0 , abi:: box_rc_field_body] ;
3809
3815
3810
3816
// Populate the upvars from the environment.
3811
- let llbindingsptr =
3812
- bcx. build . GEP ( llenvptr,
3813
- ~[ C_int ( 0 ) , C_int ( abi:: closure_elt_bindings) ] ) ;
3817
+ let bindings_path = path + ~[ abi:: closure_elt_bindings] ;
3814
3818
let i = 0 u;
3815
3819
for upvar_id: ast:: node_id in * upvars {
3816
3820
let llupvarptr =
3817
- bcx. build . GEP ( llbindingsptr, ~[ C_int ( 0 ) , C_int ( i as int ) ] ) ;
3821
+ GEP_tup_like ( bcx, ty, llclosure, bindings_path + ~[ i as int ] ) ;
3822
+ bcx = llupvarptr. bcx ;
3818
3823
let def_id = ast:: def_id_of_def ( bcx_tcx ( bcx) . def_map . get ( upvar_id) ) ;
3819
- fcx. llupvars . insert ( def_id. node , llupvarptr) ;
3824
+ fcx. llupvars . insert ( def_id. node , llupvarptr. val ) ;
3820
3825
i += 1 u;
3821
3826
}
3822
3827
3823
3828
// Populate the type parameters from the environment.
3824
- let lltydescsptr =
3825
- bcx. build . GEP ( llenvptr,
3826
- ~[ C_int ( 0 ) , C_int ( abi:: closure_elt_ty_params) ] ) ;
3827
3829
let tydesc_count = std:: ivec:: len ( enclosing_cx. fcx . lltydescs ) ;
3830
+ let tydesc_path = path + ~[ abi:: closure_elt_ty_params] ;
3828
3831
i = 0 u;
3829
3832
while i < tydesc_count {
3830
3833
let lltydescptr =
3831
- bcx. build . GEP ( lltydescsptr, ~[ C_int ( 0 ) , C_int ( i as int ) ] ) ;
3832
- fcx. lltydescs += ~[ bcx. build . Load ( lltydescptr) ] ;
3834
+ GEP_tup_like ( bcx, ty, llclosure, tydesc_path + ~[ i as int ] ) ;
3835
+ bcx = lltydescptr. bcx ;
3836
+ fcx. lltydescs += ~[ bcx. build . Load ( lltydescptr. val ) ] ;
3833
3837
i += 1 u;
3834
3838
}
3835
3839
}
@@ -4442,7 +4446,7 @@ fn trans_cast(cx: &@block_ctxt, e: &@ast::expr, id: ast::node_id) -> result {
4442
4446
4443
4447
fn trans_bind_thunk ( cx : & @local_ctxt , sp : & span , incoming_fty : & ty:: t ,
4444
4448
outgoing_fty : & ty:: t , args : & ( option:: t[ @ast:: expr ] ) [ ] ,
4445
- closure_ty : & ty:: t , bound_tys : & ty:: t [ ] ,
4449
+ env_ty : & ty:: t , bound_tys : & ty:: t [ ] ,
4446
4450
ty_param_count : uint ) -> { val : ValueRef , ty: TypeRef } {
4447
4451
4448
4452
// Here we're not necessarily constructing a thunk in the sense of
@@ -4491,8 +4495,8 @@ fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: &ty::t,
4491
4495
4492
4496
// The llenv pointer needs to be the correct size. That size is
4493
4497
// 'closure_ty', which was determined by trans_bind.
4494
- let llclosure_ptr_ty =
4495
- type_of ( cx. ccx , sp, ty :: mk_imm_box ( cx . ccx . tcx , closure_ty) ) ;
4498
+ let closure_ty = ty :: mk_imm_box ( cx . ccx . tcx , env_ty ) ;
4499
+ let llclosure_ptr_ty = type_of ( cx. ccx , sp, closure_ty) ;
4496
4500
let llclosure =
4497
4501
copy_args_bcx. build . PointerCast ( fcx. llenv , llclosure_ptr_ty) ;
4498
4502
0 commit comments