@@ -4073,10 +4073,13 @@ fn trans_for(&@block_ctxt cx, &@ast::local local, &@ast::expr seq,
4073
4073
4074
4074
// Iterator translation
4075
4075
4076
- // Searches through a block for all references to locals or upvars in this
4077
- // frame and returns the list of definition IDs thus found.
4078
- fn collect_upvars( & @block_ctxt cx, & ast:: block bloc,
4079
- ast:: node_id initial_decl) -> ast:: node_id[ ] {
4076
+ // Searches through part of the AST for all references to locals or
4077
+ // upvars in this frame and returns the list of definition IDs thus found.
4078
+ // Since we want to be able to collect upvars in some arbitrary piece
4079
+ // of the AST, we take a walker function that we invoke with a visitor
4080
+ // in order to start the search.
4081
+ fn collect_upvars( & @block_ctxt cx, & fn ( & walk:: ast_visitor) walker,
4082
+ ast:: node_id[ ] initial_decls) -> ast:: node_id[ ] {
4080
4083
type env =
4081
4084
@rec( mutable ast:: node_id[ ] refs,
4082
4085
hashmap[ ast:: node_id, ( ) ] decls,
@@ -4112,7 +4115,8 @@ fn collect_upvars(&@block_ctxt cx, &ast::block bloc,
4112
4115
}
4113
4116
}
4114
4117
let hashmap[ ast:: node_id, ( ) ] decls = new_int_hash[ ( ) ] ( ) ;
4115
- decls. insert( initial_decl, ( ) ) ;
4118
+ for ( ast:: node_id decl in initial_decls) { decls. insert( decl, ( ) ) ; }
4119
+
4116
4120
let env e =
4117
4121
@rec( mutable refs=~[ ] ,
4118
4122
decls=decls,
@@ -4123,7 +4127,7 @@ fn collect_upvars(&@block_ctxt cx, &ast::block bloc,
4123
4127
visit_expr_pre=bind walk_expr( e, _) ,
4124
4128
visit_pat_pre=bind walk_pat( e, _)
4125
4129
with walk:: default_visitor( ) ) ;
4126
- walk :: walk_block ( * visitor, bloc ) ;
4130
+ walker ( * visitor) ;
4127
4131
// Calculate (refs - decls). This is the set of captured upvars.
4128
4132
4129
4133
let ast:: node_id[ ] result = ~[ ] ;
@@ -4310,7 +4314,8 @@ fn trans_for_each(&@block_ctxt cx, &@ast::local local, &@ast::expr seq,
4310
4314
// FIXME: possibly support alias-mode here?
4311
4315
auto decl_ty = node_id_type( lcx. ccx, local. node. id) ;
4312
4316
auto decl_id = local. node. id;
4313
- auto upvars = collect_upvars( cx, body, decl_id) ;
4317
+ auto upvars = collect_upvars( cx, bind walk:: walk_block( _, body) ,
4318
+ ~[ decl_id] ) ;
4314
4319
4315
4320
auto environment_data = build_environment( cx, upvars) ;
4316
4321
auto llenvptr = environment_data. _0;
0 commit comments