@@ -261,7 +261,7 @@ fn allocate_cbox(bcx: @block_ctxt,
261
261
262
262
type closure_result = {
263
263
llbox : ValueRef , // llvalue of ptr to closure
264
- cboxptr_ty : ty:: t , // type of ptr to closure
264
+ cbox_ty : ty:: t , // type of the closure data
265
265
bcx : @block_ctxt // final bcx
266
266
} ;
267
267
@@ -332,12 +332,12 @@ fn store_environment(
332
332
// whatever.
333
333
let cboxptr_ty = ty:: mk_ptr ( tcx, { ty: cbox_ty, mut: ast:: imm} ) ;
334
334
let llbox = cast_if_we_can ( bcx, llbox, cboxptr_ty) ;
335
- check type_is_tup_like ( bcx, cboxptr_ty ) ;
335
+ check type_is_tup_like ( bcx, cbox_ty ) ;
336
336
337
337
// If necessary, copy tydescs describing type parameters into the
338
338
// appropriate slot in the closure.
339
339
let { bcx: bcx , val : ty_params_slot } =
340
- GEP_tup_like_1 ( bcx, cboxptr_ty , llbox, [ 0 , abi:: cbox_elt_ty_params] ) ;
340
+ GEP_tup_like ( bcx, cbox_ty , llbox, [ 0 , abi:: cbox_elt_ty_params] ) ;
341
341
let off = 0 ;
342
342
for tp in lltyparams {
343
343
let cloned_td = maybe_clone_tydesc ( bcx, ck, tp. desc ) ;
@@ -354,15 +354,16 @@ fn store_environment(
354
354
355
355
// Copy expr values into boxed bindings.
356
356
// Silly check
357
- let { bcx: bcx , val : bindings_slot } =
358
- GEP_tup_like_1 ( bcx, cboxptr_ty, llbox, [ 0 , abi:: cbox_elt_bindings] ) ;
359
357
vec:: iteri ( bound_values) { |i, bv|
360
358
if ( !ccx. sess . opts . no_asm_comments ) {
361
359
add_comment ( bcx, #fmt ( "Copy %s into closure" ,
362
360
ev_to_str ( ccx, bv) ) ) ;
363
361
}
364
362
365
- let bound_data = GEPi ( bcx, bindings_slot, [ 0 , i as int ] ) ;
363
+ let bound_data = GEP_tup_like_1 ( bcx, cbox_ty, llbox,
364
+ [ 0 , abi:: cbox_elt_bindings, i as int ] ) ;
365
+ bcx = bound_data. bcx ;
366
+ let bound_data = bound_data. val ;
366
367
alt bv {
367
368
env_expr( e) {
368
369
bcx = trans:: trans_expr_save_in ( bcx, e, bound_data) ;
@@ -397,7 +398,7 @@ fn store_environment(
397
398
}
398
399
for cleanup in temp_cleanups { revoke_clean ( bcx, cleanup) ; }
399
400
400
- ret { llbox : llbox, cboxptr_ty : cboxptr_ty , bcx : bcx} ;
401
+ ret { llbox : llbox, cbox_ty : cbox_ty , bcx : bcx} ;
401
402
}
402
403
403
404
// Given a context and a list of upvars, build a closure. This just
@@ -441,13 +442,15 @@ fn build_closure(bcx0: @block_ctxt,
441
442
// with the upvars and type descriptors.
442
443
fn load_environment ( enclosing_cx : @block_ctxt ,
443
444
fcx : @fn_ctxt ,
444
- cboxptr_ty : ty:: t ,
445
+ cbox_ty : ty:: t ,
445
446
cap_vars : [ capture:: capture_var ] ,
446
447
ck : ty:: closure_kind ) {
447
448
let bcx = new_raw_block_ctxt ( fcx, fcx. llloadenv ) ;
448
449
let ccx = bcx_ccx ( bcx) ;
450
+ let tcx = bcx_tcx ( bcx) ;
449
451
450
452
let sp = bcx. sp ;
453
+ let cboxptr_ty = ty:: mk_ptr ( tcx, { ty: cbox_ty, mut: ast:: imm} ) ;
451
454
check ( type_has_static_size ( ccx, cboxptr_ty) ) ;
452
455
let llty = type_of ( ccx, sp, cboxptr_ty) ;
453
456
let llclosure = PointerCast ( bcx, fcx. llenv , llty) ;
@@ -479,9 +482,9 @@ fn load_environment(enclosing_cx: @block_ctxt,
479
482
alt cap_var. mode {
480
483
capture:: cap_drop. { /* ignore */ }
481
484
_ {
482
- check type_is_tup_like( bcx, cboxptr_ty ) ;
485
+ check type_is_tup_like( bcx, cbox_ty ) ;
483
486
let upvarptr = GEP_tup_like (
484
- bcx, cboxptr_ty , llclosure, path + [ i as int ] ) ;
487
+ bcx, cbox_ty , llclosure, path + [ i as int ] ) ;
485
488
bcx = upvarptr. bcx ;
486
489
let llupvarptr = upvarptr. val ;
487
490
alt ck {
@@ -516,9 +519,9 @@ fn trans_expr_fn(bcx: @block_ctxt,
516
519
let trans_closure_env = fn @( ck: ty:: closure_kind) -> ValueRef {
517
520
let cap_vars = capture:: compute_capture_vars (
518
521
ccx. tcx , id, proto, cap_clause) ;
519
- let { llbox, cboxptr_ty , bcx} = build_closure ( bcx, cap_vars, ck) ;
522
+ let { llbox, cbox_ty , bcx} = build_closure ( bcx, cap_vars, ck) ;
520
523
trans_closure ( sub_cx, sp, decl, body, llfn, no_self, [ ] , id, { |fcx|
521
- load_environment ( bcx, fcx, cboxptr_ty , cap_vars, ck) ;
524
+ load_environment ( bcx, fcx, cbox_ty , cap_vars, ck) ;
522
525
} ) ;
523
526
llbox
524
527
} ;
@@ -616,15 +619,15 @@ fn trans_bind_1(cx: @block_ctxt, outgoing_fty: ty::t,
616
619
} ;
617
620
618
621
// Actually construct the closure
619
- let { llbox, cboxptr_ty , bcx} = store_environment (
622
+ let { llbox, cbox_ty , bcx} = store_environment (
620
623
bcx, vec:: map ( lltydescs, { |d| { desc: d, dicts: none} } ) ,
621
624
env_vals + vec:: map ( bound, { |x| env_expr ( x) } ) ,
622
625
ty:: ck_box) ;
623
626
624
627
// Make thunk
625
628
let llthunk =
626
629
trans_bind_thunk ( cx. fcx . lcx , cx. sp , pair_ty, outgoing_fty_real, args,
627
- cboxptr_ty , * param_bounds, target_res) ;
630
+ cbox_ty , * param_bounds, target_res) ;
628
631
629
632
// Fill the function pair
630
633
fill_fn_pair ( bcx, get_dest_addr ( dest) , llthunk. val , llbox) ;
@@ -782,7 +785,7 @@ fn trans_bind_thunk(cx: @local_ctxt,
782
785
incoming_fty: ty:: t,
783
786
outgoing_fty: ty:: t,
784
787
args: [ option:: t<@ast:: expr>] ,
785
- cboxptr_ty : ty:: t,
788
+ cbox_ty : ty:: t,
786
789
param_bounds: [ ty:: param_bounds] ,
787
790
target_fn: option:: t<ValueRef >)
788
791
-> { val: ValueRef , ty: TypeRef } {
@@ -794,6 +797,7 @@ fn trans_bind_thunk(cx: @local_ctxt,
794
797
*/
795
798
// but since we don't, we have to do the checks at the beginning.
796
799
let ccx = cx. ccx ;
800
+ let tcx = ccx_tcx ( ccx) ;
797
801
check type_has_static_size ( ccx, incoming_fty) ;
798
802
799
803
// Here we're not necessarily constructing a thunk in the sense of
@@ -838,7 +842,8 @@ fn trans_bind_thunk(cx: @local_ctxt,
838
842
// to the original function. So, let's create one of those:
839
843
840
844
// The llenv pointer needs to be the correct size. That size is
841
- // 'cboxptr_ty', which was determined by trans_bind.
845
+ // 'cbox_ty', which was determined by trans_bind.
846
+ let cboxptr_ty = ty:: mk_ptr ( tcx, { ty: cbox_ty, mut: ast:: imm} ) ;
842
847
check type_has_static_size ( ccx, cboxptr_ty) ;
843
848
let llclosure_ptr_ty = type_of ( ccx, sp, cboxptr_ty) ;
844
849
let llclosure = PointerCast ( l_bcx, fcx. llenv , llclosure_ptr_ty) ;
@@ -854,9 +859,9 @@ fn trans_bind_thunk(cx: @local_ctxt,
854
859
}
855
860
none. {
856
861
// Silly check
857
- check type_is_tup_like ( bcx, cboxptr_ty ) ;
862
+ check type_is_tup_like ( bcx, cbox_ty ) ;
858
863
let { bcx: cx , val : pair } =
859
- GEP_tup_like ( bcx, cboxptr_ty , llclosure,
864
+ GEP_tup_like ( bcx, cbox_ty , llclosure,
860
865
[ 0 , abi:: cbox_elt_bindings, 0 ] ) ;
861
866
let lltargetenv =
862
867
Load ( cx, GEPi ( cx, pair, [ 0 , abi:: fn_field_box] ) ) ;
@@ -891,9 +896,9 @@ fn trans_bind_thunk(cx: @local_ctxt,
891
896
let llargs: [ ValueRef ] = [ llretptr, lltargetenv] ;
892
897
893
898
// Copy in the type parameters.
894
- check type_is_tup_like ( l_bcx, cboxptr_ty ) ;
899
+ check type_is_tup_like ( l_bcx, cbox_ty ) ;
895
900
let { bcx: l_bcx , val: param_record } =
896
- GEP_tup_like ( l_bcx, cboxptr_ty , llclosure,
901
+ GEP_tup_like ( l_bcx, cbox_ty , llclosure,
897
902
[ 0 , abi:: cbox_elt_ty_params] ) ;
898
903
let off = 0 ;
899
904
for param in param_bounds {
@@ -932,9 +937,9 @@ fn trans_bind_thunk(cx: @local_ctxt,
932
937
// closure.
933
938
some( e) {
934
939
// Silly check
935
- check type_is_tup_like( bcx, cboxptr_ty ) ;
940
+ check type_is_tup_like( bcx, cbox_ty ) ;
936
941
let bound_arg =
937
- GEP_tup_like ( bcx, cboxptr_ty , llclosure,
942
+ GEP_tup_like ( bcx, cbox_ty , llclosure,
938
943
[ 0 , abi : : cbox_elt_bindings, b] ) ;
939
944
bcx = bound_arg. bcx;
940
945
let val = bound_arg. val;
0 commit comments