@@ -3677,30 +3677,6 @@ fn trans_for(cx: &@block_ctxt, local: &@ast::local, seq: &@ast::expr,
3677
3677
3678
3678
// Iterator translation
3679
3679
3680
- // Finds the ValueRef associated with a variable in a function
3681
- // context. It checks locals, upvars, and args.
3682
- fn find_variable ( cx : & @block_ctxt , nid : ast:: node_id ) -> lval_result {
3683
- let fcx = cx. fcx ;
3684
- let llval = alt fcx. lllocals . find ( nid) {
3685
- none. {
3686
- alt fcx . llupvars . find ( nid) {
3687
- none. {
3688
- alt fcx . llargs . find ( nid) {
3689
- some ( llval) { llval }
3690
- _ {
3691
- fcx. lcx . ccx . sess . bug ( "unbound var in build_environment "
3692
- + int:: str ( nid) )
3693
- }
3694
- }
3695
- }
3696
- some ( llval) { llval }
3697
- }
3698
- }
3699
- some ( llval) { llval }
3700
- } ;
3701
- ret lval_mem( cx, llval) ;
3702
- }
3703
-
3704
3680
// build_environment_heap and build_environment are very similar. It
3705
3681
// would be nice to unify them.
3706
3682
@@ -3781,21 +3757,21 @@ fn build_environment_heap(bcx: @block_ctxt, lltydescs: ValueRef[],
3781
3757
// Given a block context and a list of upvars, construct a closure that
3782
3758
// contains pointers to all of the upvars and all of the tydescs in
3783
3759
// scope. Return the ValueRef and TypeRef corresponding to the closure.
3784
- fn build_environment ( cx : & @block_ctxt , upvars : & freevar_set ) ->
3760
+ fn build_environment ( cx : & @block_ctxt , upvars : & @ast :: node_id [ ] ) ->
3785
3761
{ ptr : ValueRef , ptrty : TypeRef } {
3786
3762
let has_iterbody = !option:: is_none ( cx. fcx . lliterbody ) ;
3787
3763
let llbindingsptr;
3788
3764
3789
- if upvars . size ( ) > 0 u || has_iterbody {
3765
+ if std :: ivec :: len ( * upvars ) > 0 u || has_iterbody {
3790
3766
// Gather up the upvars.
3791
3767
let llbindings: ValueRef [ ] = ~[ ] ;
3792
3768
let llbindingtys: TypeRef [ ] = ~[ ] ;
3793
3769
if has_iterbody {
3794
3770
llbindings += ~[ option:: get ( cx. fcx . lliterbody ) ] ;
3795
3771
llbindingtys += ~[ val_ty ( llbindings. ( 0 ) ) ] ;
3796
3772
}
3797
- for each nid: ast:: node_id in upvars. keys ( ) {
3798
- let llbinding = find_variable ( cx, nid) . res . val ;
3773
+ for nid: ast:: node_id in * upvars {
3774
+ let llbinding = trans_var ( cx, cx . sp , nid) . res . val ;
3799
3775
llbindings += ~[ llbinding] ;
3800
3776
llbindingtys += ~[ val_ty ( llbinding) ] ;
3801
3777
}
@@ -3847,7 +3823,7 @@ fn build_environment(cx: &@block_ctxt, upvars: &freevar_set) ->
3847
3823
// and a list of upvars, generate code to load and populate the environment
3848
3824
// with the upvars and type descriptors.
3849
3825
fn load_environment ( cx : & @block_ctxt , fcx : & @fn_ctxt , llenvptrty : TypeRef ,
3850
- upvars : & freevar_set ) {
3826
+ upvars : & @ast :: node_id [ ] ) {
3851
3827
let copy_args_bcx = new_raw_block_ctxt ( fcx, fcx. llcopyargs ) ;
3852
3828
3853
3829
// Populate the upvars from the environment.
@@ -3869,12 +3845,13 @@ fn load_environment(cx: &@block_ctxt, fcx: &@fn_ctxt, llenvptrty: TypeRef,
3869
3845
let lliterbody = copy_args_bcx. build . Load ( lliterbodyptr) ;
3870
3846
fcx. lliterbody = some ( lliterbody) ;
3871
3847
}
3872
- for each upvar_id: ast:: node_id in upvars. keys ( ) {
3848
+ for upvar_id: ast:: node_id in * upvars {
3873
3849
let llupvarptrptr =
3874
3850
copy_args_bcx. build . GEP ( llremotebindingsptr,
3875
3851
~[ C_int ( 0 ) , C_int ( i as int ) ] ) ;
3876
3852
let llupvarptr = copy_args_bcx. build . Load ( llupvarptrptr) ;
3877
- fcx. llupvars . insert ( upvar_id, llupvarptr) ;
3853
+ let def_id = ast:: def_id_of_def ( bcx_tcx ( cx) . def_map . get ( upvar_id) ) ;
3854
+ fcx. llupvars . insert ( def_id. node , llupvarptr) ;
3878
3855
i += 1 u;
3879
3856
}
3880
3857
@@ -4092,9 +4069,12 @@ fn lookup_discriminant(lcx: &@local_ctxt, tid: &ast::def_id,
4092
4069
}
4093
4070
}
4094
4071
4095
- fn trans_path ( cx : & @block_ctxt , p : & ast :: path , id : ast:: node_id ) ->
4072
+ fn trans_var ( cx : & @block_ctxt , sp : & span , id : ast:: node_id ) ->
4096
4073
lval_result {
4097
4074
let ccx = bcx_ccx ( cx) ;
4075
+ // If we had a good way to get at the node_id for the function we
4076
+ // are in, we could do a freevars::def_lookup and avoid having to
4077
+ // check the llupvars case in all of the other cases...
4098
4078
alt bcx_tcx( cx) . def_map . find ( id) {
4099
4079
some ( ast:: def_arg ( did) ) {
4100
4080
alt cx. fcx . llargs . find ( did. node ) {
@@ -4144,7 +4124,7 @@ fn trans_path(cx: &@block_ctxt, p: &ast::path, id: ast::node_id) ->
4144
4124
let tag_ty = node_id_type ( ccx, id) ;
4145
4125
let alloc_result = alloc_ty ( cx, tag_ty) ;
4146
4126
let lltagblob = alloc_result. val ;
4147
- let lltagty = type_of_tag ( ccx, p . span , tid, tag_ty) ;
4127
+ let lltagty = type_of_tag ( ccx, sp , tid, tag_ty) ;
4148
4128
let bcx = alloc_result. bcx ;
4149
4129
let lltagptr = bcx. build . PointerCast ( lltagblob, T_ptr ( lltagty) ) ;
4150
4130
if std:: ivec:: len ( ty:: tag_variants ( ccx. tcx , tid) ) != 1 u {
@@ -4180,6 +4160,11 @@ fn trans_path(cx: &@block_ctxt, p: &ast::path, id: ast::node_id) ->
4180
4160
}
4181
4161
}
4182
4162
4163
+ fn trans_path ( cx : & @block_ctxt , p : & ast:: path , id : ast:: node_id ) ->
4164
+ lval_result {
4165
+ ret trans_var ( cx, p. span , id) ;
4166
+ }
4167
+
4183
4168
fn trans_field ( cx : & @block_ctxt , sp : & span , v : ValueRef , t0 : & ty:: t ,
4184
4169
field : & ast:: ident , id : ast:: node_id ) -> lval_result {
4185
4170
let r = autoderef ( cx, v, t0) ;
0 commit comments