Skip to content

Commit 22903a9

Browse files
committed
---
yaml --- r: 4140 b: refs/heads/master c: 9ca0ce9 h: refs/heads/master v: v3
1 parent 4308d24 commit 22903a9

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 166d4f5fe98aa58666322fe6413ca3b7bee832aa
2+
refs/heads/master: 9ca0ce91bf2d33fdb3df63d2c4c1470d7e10f767

trunk/src/comp/middle/tstate/auxiliary.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,15 @@ fn constraints_expr(&ty::ctxt cx, @expr e) -> (@ty::constr)[] {
486486
}
487487
}
488488

489+
fn node_id_to_def_upvar_strict(&fn_ctxt cx, node_id id) -> def {
490+
alt (freevars::def_lookup(cx.ccx.tcx, cx.id, id)) {
491+
case (none) {
492+
log_err "node_id_to_def: node_id " + int::str(id) + " has no def";
493+
fail;
494+
}
495+
case (some(?d)) { ret d; }
496+
}
497+
}
489498
fn node_id_to_def_strict(&ty::ctxt cx, node_id id) -> def {
490499
alt (cx.def_map.find(id)) {
491500
case (none) {

trunk/src/comp/middle/tstate/pre_post_conditions.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,18 @@ fn handle_update(&fn_ctxt fcx, &@expr parent,
299299
}
300300
}
301301

302+
fn handle_var(&fn_ctxt fcx, &pre_and_post rslt, node_id id, ident name) {
303+
auto df = node_id_to_def_upvar_strict(fcx, id);
304+
alt (df) {
305+
case (def_local(?d_id)) {
306+
auto i = bit_num(fcx, ninit(d_id.node, name));
307+
use_var(fcx, d_id.node);
308+
require_and_preserve(i, rslt);
309+
}
310+
case (_) {/* nothing to check */ }
311+
}
312+
}
313+
302314
/* Fills in annotations as a side effect. Does not rebuild the expr */
303315
fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
304316
auto enclosing = fcx.enclosing;
@@ -337,17 +349,7 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
337349
case (expr_path(?p)) {
338350
auto rslt = expr_pp(fcx.ccx, e);
339351
clear_pp(rslt);
340-
auto df = node_id_to_def_strict(fcx.ccx.tcx, e.id);
341-
alt (df) {
342-
case (def_local(?d_id)) {
343-
auto i =
344-
bit_num(fcx,
345-
ninit(d_id.node, path_to_ident(fcx.ccx.tcx, p)));
346-
use_var(fcx, d_id.node);
347-
require_and_preserve(i, rslt);
348-
}
349-
case (_) {/* nothing to check */ }
350-
}
352+
handle_var(fcx, rslt, e.id, path_to_ident(fcx.ccx.tcx, p));
351353
}
352354
case (expr_self_method(?v)) { clear_pp(expr_pp(fcx.ccx, e)); }
353355
case (expr_log(_, ?arg)) {
@@ -367,7 +369,14 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
367369
case (none) { clear_pp(expr_pp(fcx.ccx, e)); }
368370
}
369371
}
370-
case (expr_fn(?f)) { clear_pp(expr_pp(fcx.ccx, e)); }
372+
case (expr_fn(?f)) {
373+
auto rslt = expr_pp(fcx.ccx, e);
374+
clear_pp(rslt);
375+
auto upvars = freevars::get_freevar_uses(fcx.ccx.tcx, e.id);
376+
for (node_id id in *upvars) {
377+
handle_var(fcx, rslt, id, "upvar");
378+
}
379+
}
371380
case (expr_block(?b)) {
372381
find_pre_post_block(fcx, b);
373382
auto p = block_pp(fcx.ccx, b);

trunk/src/comp/middle/tstate/states.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ fn find_pre_post_state_loop(&fn_ctxt fcx, prestate pres, &@local l,
208208
fn gen_if_local(&fn_ctxt fcx, &poststate p, &@expr e) -> bool {
209209
alt (e.node) {
210210
case (expr_path(?pth)) {
211-
alt (node_id_to_def(fcx.ccx, e.id)) {
211+
alt (freevars::def_lookup(fcx.ccx.tcx, fcx.id, e.id)) {
212212
case (some(def_local(?loc))) {
213213
ret set_in_poststate_ident(fcx, loc.node,
214214
path_to_ident(fcx.ccx.tcx, pth), p);

0 commit comments

Comments
 (0)