@@ -4488,15 +4488,20 @@ fn collect_upvars(&@block_ctxt cx, &ast::block bloc,
4488
4488
// contains pointers to all of the upvars and all of the tydescs in
4489
4489
// scope. Return the ValueRef and TypeRef corresponding to the closure.
4490
4490
fn build_environment( & @block_ctxt cx, & ast:: node_id[ ] upvars) ->
4491
- tup( ValueRef , TypeRef )
4492
- {
4491
+ tup( ValueRef , TypeRef ) {
4493
4492
auto upvar_count = std:: ivec:: len( upvars) ;
4493
+ auto has_iterbody = !option:: is_none( cx. fcx. lliterbody) ;
4494
+ if ( has_iterbody) { upvar_count += 1 u; }
4494
4495
auto llbindingsptr;
4495
4496
4496
4497
if ( upvar_count > 0 u) {
4497
4498
// Gather up the upvars.
4498
4499
let ValueRef [ ] llbindings = ~[ ] ;
4499
4500
let TypeRef [ ] llbindingtys = ~[ ] ;
4501
+ if ( has_iterbody) {
4502
+ llbindings += ~[ option:: get( cx. fcx. lliterbody) ] ;
4503
+ llbindingtys += ~[ val_ty( llbindings. ( 0 ) ) ] ;
4504
+ }
4500
4505
for ( ast:: node_id nid in upvars) {
4501
4506
auto llbinding;
4502
4507
alt ( cx. fcx. lllocals. find( nid) ) {
@@ -4566,9 +4571,7 @@ fn build_environment(&@block_ctxt cx, &ast::node_id[] upvars) ->
4566
4571
// and a list of upvars, generate code to load and populate the environment
4567
4572
// with the upvars and type descriptors.
4568
4573
fn load_environment( & @block_ctxt cx, & @fn_ctxt fcx,
4569
- TypeRef llenvptrty, & ast:: node_id[ ] upvars)
4570
- {
4571
- auto upvar_count = std:: ivec:: len( upvars) ;
4574
+ TypeRef llenvptrty, & ast:: node_id[ ] upvars) {
4572
4575
auto copy_args_bcx = new_raw_block_ctxt( fcx, fcx. llcopyargs) ;
4573
4576
4574
4577
// Populate the upvars from the environment.
@@ -4581,7 +4584,17 @@ fn load_environment(&@block_ctxt cx, &@fn_ctxt fcx,
4581
4584
auto llremotebindingsptr =
4582
4585
copy_args_bcx. build. Load ( llremotebindingsptrptr) ;
4583
4586
auto i = 0 u;
4584
- while ( i < upvar_count) {
4587
+ auto end = std:: ivec:: len( upvars) ;
4588
+ if ( !option:: is_none( cx. fcx. lliterbody) ) {
4589
+ end += 1 u;
4590
+ i += 1 u;
4591
+ auto lliterbodyptr =
4592
+ copy_args_bcx. build. GEP ( llremotebindingsptr,
4593
+ ~[ C_int ( 0 ) , C_int ( 0 ) ] ) ;
4594
+ auto lliterbody = copy_args_bcx. build. Load ( lliterbodyptr) ;
4595
+ fcx. lliterbody = some( lliterbody) ;
4596
+ }
4597
+ while ( i < end) {
4585
4598
auto upvar_id = upvars. ( i) ;
4586
4599
auto llupvarptrptr =
4587
4600
copy_args_bcx. build. GEP ( llremotebindingsptr,
0 commit comments