@@ -3951,7 +3951,7 @@ fn trans_for_each(cx: &@block_ctxt, local: &@ast::local, seq: &@ast::expr,
3951
3951
ty:: mk_nil ( lcx. ccx . tcx ) , 0 u) ;
3952
3952
let lliterbody: ValueRef =
3953
3953
decl_internal_fastcall_fn ( lcx. ccx . llmod , s, iter_body_llty) ;
3954
- let fcx = new_fn_ctxt ( lcx, cx. sp , lliterbody) ;
3954
+ let fcx = new_fn_ctxt_w_id ( lcx, cx. sp , lliterbody, body . node . id ) ;
3955
3955
3956
3956
// Generate code to load the environment out of the
3957
3957
// environment pointer.
@@ -3961,7 +3961,7 @@ fn trans_for_each(cx: &@block_ctxt, local: &@ast::local, seq: &@ast::expr,
3961
3961
// Add bindings for the loop variable alias.
3962
3962
bcx = trans_alt:: bind_irrefutable_pat
3963
3963
( bcx, local. node . pat , llvm:: LLVMGetParam ( fcx. llfn , 3 u) ,
3964
- bcx. fcx . llupvars , false ) ;
3964
+ bcx. fcx . lllocals , false ) ;
3965
3965
let lltop = bcx. llbb ;
3966
3966
let r = trans_block ( bcx, body, return ) ;
3967
3967
finish_fn ( fcx, lltop) ;
@@ -3971,7 +3971,6 @@ fn trans_for_each(cx: &@block_ctxt, local: &@ast::local, seq: &@ast::expr,
3971
3971
r. bcx . build . RetVoid ( ) ;
3972
3972
}
3973
3973
3974
-
3975
3974
// Step 3: Call iter passing [lliterbody, llenv], plus other args.
3976
3975
alt seq. node {
3977
3976
ast:: expr_call ( f, args) {
@@ -4101,36 +4100,22 @@ fn lookup_discriminant(lcx: &@local_ctxt, tid: &ast::def_id,
4101
4100
fn trans_var ( cx : & @block_ctxt , sp : & span , id : ast:: node_id ) ->
4102
4101
lval_result {
4103
4102
let ccx = bcx_ccx ( cx) ;
4104
- // If we had a good way to get at the node_id for the function we
4105
- // are in, we could do a freevars::def_lookup and avoid having to
4106
- // check the llupvars case in all of the other cases...
4107
- alt bcx_tcx( cx) . def_map . find ( id) {
4103
+ alt freevars:: def_lookup ( bcx_tcx ( cx) , cx. fcx . id , id) {
4104
+ some ( ast:: def_upvar ( did, _) ) {
4105
+ assert ( cx. fcx . llupvars . contains_key ( did. node ) ) ;
4106
+ ret lval_mem( cx, cx. fcx . llupvars . get ( did. node ) ) ;
4107
+ }
4108
4108
some ( ast:: def_arg ( did) ) {
4109
- alt cx. fcx . llargs . find ( did. node ) {
4110
- none. {
4111
- assert ( cx. fcx . llupvars . contains_key ( did. node ) ) ;
4112
- ret lval_mem( cx, cx. fcx . llupvars . get ( did. node ) ) ;
4113
- }
4114
- some ( llval) { ret lval_mem ( cx, llval) ; }
4115
- }
4109
+ assert ( cx. fcx . llargs . contains_key ( did. node ) ) ;
4110
+ ret lval_mem( cx, cx. fcx . llargs . get ( did. node ) ) ;
4116
4111
}
4117
4112
some ( ast:: def_local ( did) ) {
4118
- alt cx. fcx . lllocals . find ( did. node ) {
4119
- none. {
4120
- assert ( cx. fcx . llupvars . contains_key ( did. node ) ) ;
4121
- ret lval_mem( cx, cx. fcx . llupvars . get ( did. node ) ) ;
4122
- }
4123
- some ( llval) { ret lval_mem ( cx, llval) ; }
4124
- }
4113
+ assert ( cx. fcx . lllocals . contains_key ( did. node ) ) ;
4114
+ ret lval_mem( cx, cx. fcx . lllocals . get ( did. node ) ) ;
4125
4115
}
4126
4116
some ( ast:: def_binding ( did) ) {
4127
- alt cx. fcx . lllocals . find ( did. node ) {
4128
- none. {
4129
- assert ( cx. fcx . llupvars . contains_key ( did. node ) ) ;
4130
- ret lval_mem( cx, cx. fcx . llupvars . get ( did. node ) ) ;
4131
- }
4132
- some ( llval) { ret lval_mem ( cx, llval) ; }
4133
- }
4117
+ assert ( cx. fcx . lllocals . contains_key ( did. node ) ) ;
4118
+ ret lval_mem( cx, cx. fcx . lllocals . get ( did. node ) ) ;
4134
4119
}
4135
4120
some ( ast:: def_obj_field ( did) ) {
4136
4121
assert ( cx. fcx . llobjfields . contains_key ( did. node ) ) ;
@@ -6227,7 +6212,8 @@ fn mk_standard_basic_blocks(llfn: ValueRef) ->
6227
6212
// - create_llargs_for_fn_args.
6228
6213
// - new_fn_ctxt
6229
6214
// - trans_args
6230
- fn new_fn_ctxt ( cx : @local_ctxt , sp : & span , llfndecl : ValueRef ) -> @fn_ctxt {
6215
+ fn new_fn_ctxt_w_id ( cx : @local_ctxt , sp : & span , llfndecl : ValueRef ,
6216
+ id : ast:: node_id ) -> @fn_ctxt {
6231
6217
let llretptr: ValueRef = llvm:: LLVMGetParam ( llfndecl, 0 u) ;
6232
6218
let lltaskptr: ValueRef = llvm:: LLVMGetParam ( llfndecl, 1 u) ;
6233
6219
let llenv: ValueRef = llvm:: LLVMGetParam ( llfndecl, 2 u) ;
@@ -6256,10 +6242,14 @@ fn new_fn_ctxt(cx: @local_ctxt, sp: &span, llfndecl: ValueRef) -> @fn_ctxt {
6256
6242
llupvars : llupvars,
6257
6243
mutable lltydescs : ~[ ] ,
6258
6244
derived_tydescs : derived_tydescs,
6245
+ id : id,
6259
6246
sp : sp,
6260
6247
lcx : cx} ;
6261
6248
}
6262
6249
6250
+ fn new_fn_ctxt ( cx : @local_ctxt , sp : & span , llfndecl : ValueRef ) -> @fn_ctxt {
6251
+ be new_fn_ctxt_w_id ( cx, sp, llfndecl, -1 ) ;
6252
+ }
6263
6253
6264
6254
// NB: must keep 4 fns in sync:
6265
6255
//
@@ -6460,7 +6450,7 @@ fn trans_closure(bcx_maybe: &option::t[@block_ctxt],
6460
6450
set_uwtable ( llfndecl) ;
6461
6451
6462
6452
// Set up arguments to the function.
6463
- let fcx = new_fn_ctxt ( cx, sp, llfndecl) ;
6453
+ let fcx = new_fn_ctxt_w_id ( cx, sp, llfndecl, id ) ;
6464
6454
create_llargs_for_fn_args ( fcx, f. proto , ty_self,
6465
6455
ty:: ret_ty_of_fn ( cx. ccx . tcx , id) , f. decl . inputs ,
6466
6456
ty_params) ;
0 commit comments