Skip to content

Commit a9185ce

Browse files
committed
---
yaml --- r: 3836 b: refs/heads/master c: e1f9bfb h: refs/heads/master v: v3
1 parent c1ce733 commit a9185ce

File tree

6 files changed

+45
-112
lines changed

6 files changed

+45
-112
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: 21b94d57d5319e42f5a30818c88b95c95449864e
2+
refs/heads/master: e1f9bfbac93765f833cd20a599165025f18faebe

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import std::int;
88
import std::uint;
99
import syntax::ast::*;
1010
import syntax::codemap::span;
11+
import syntax::visit;
1112
import util::common;
1213
import util::common::log_block;
1314
import std::map::new_int_hash;
@@ -527,13 +528,7 @@ fn match_args(&fn_ctxt fcx, &pred_desc[] occs, &(@constr_arg_use)[] occ) ->
527528
fn eq(&tup(ident, def_id) p, &tup(ident, def_id) q) -> bool {
528529
ret p._1 == q._1;
529530
}
530-
531-
// FIXME: Remove this vec->ivec conversion.
532-
let (@constr_arg_use)[] cau_ivec = ~[];
533-
for (@constr_arg_use cau in pd.node.args) {
534-
cau_ivec += ~[cau];
535-
}
536-
if (ty::args_eq(eq, cau_ivec, occ)) { ret pd.node.bit_num; }
531+
if (ty::args_eq(eq, pd.node.args, occ)) { ret pd.node.bit_num; }
537532
}
538533
fcx.ccx.tcx.sess.bug("match_args: no match for occurring args");
539534
}
@@ -1038,6 +1033,11 @@ fn op_to_oper_ty(init_op io) -> oper_type {
10381033
case (_) { oper_assign }
10391034
}
10401035
}
1036+
1037+
// default function visitor
1038+
fn do_nothing[T](&_fn f, &ty_param[] tp, &span sp, &fn_ident i,
1039+
node_id iid, &T cx, &visit::vt[T] v) {
1040+
}
10411041
//
10421042
// Local Variables:
10431043
// mode: rust

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

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import ast::crate;
1717
import ast::return;
1818
import ast::noreturn;
1919
import ast::expr;
20-
import syntax::walk;
20+
import syntax::visit;
2121
import syntax::codemap::span;
2222
import middle::ty::type_is_nil;
2323
import middle::ty::ret_ty_of_fn;
@@ -62,7 +62,9 @@ fn check_unused_vars(&fn_ctxt fcx) {
6262
}
6363
}
6464

65-
fn check_states_expr(&fn_ctxt fcx, &@expr e) {
65+
fn check_states_expr(&@expr e, &fn_ctxt fcx, &visit::vt[fn_ctxt] v) {
66+
visit::visit_expr(e, fcx, v);
67+
6668
let precond prec = expr_precond(fcx.ccx, e);
6769
let prestate pres = expr_prestate(fcx.ccx, e);
6870

@@ -90,7 +92,9 @@ fn check_states_expr(&fn_ctxt fcx, &@expr e) {
9092
}
9193
}
9294

93-
fn check_states_stmt(&fn_ctxt fcx, &@stmt s) {
95+
fn check_states_stmt(&@stmt s, &fn_ctxt fcx, &visit::vt[fn_ctxt] v) {
96+
visit::visit_stmt(s, fcx, v);
97+
9498
auto a = stmt_to_ann(fcx.ccx, *s);
9599
let precond prec = ann_precond(a);
96100
let prestate pres = ann_prestate(a);
@@ -126,24 +130,13 @@ fn check_states_against_conditions(&fn_ctxt fcx, &_fn f,
126130
because we want the smallest possible erroneous statement
127131
or expression. */
128132

129-
let @mutable bool keepgoing = @mutable true;
130-
131-
/* TODO probably should use visit instead */
132-
133-
fn quit(@mutable bool keepgoing, &@ast::item i) {
134-
*keepgoing = false;
135-
}
136-
fn kg(@mutable bool keepgoing) -> bool {
137-
ret *keepgoing;
138-
}
133+
auto visitor = visit::default_visitor[fn_ctxt]();
139134

140-
auto v = rec (visit_stmt_post=bind check_states_stmt(fcx, _),
141-
visit_expr_post=bind check_states_expr(fcx, _),
142-
visit_item_pre=bind quit(keepgoing, _),
143-
keep_going=bind kg(keepgoing)
144-
with walk::default_visitor());
145-
146-
walk::walk_fn(v, f, tps, sp, i, id);
135+
visitor = @rec(visit_stmt=check_states_stmt,
136+
visit_expr=check_states_expr,
137+
visit_fn=do_nothing
138+
with *visitor);
139+
visit::visit_fn(f, tps, sp, i, id, fcx, visit::mk_vt(visitor));
147140

148141
/* Check that the return value is initialized */
149142
auto post = aux::block_poststate(fcx.ccx, f.body);
@@ -189,10 +182,12 @@ fn check_fn_states(&fn_ctxt fcx, &_fn f, &ast::ty_param[] tps,
189182
check_states_against_conditions(fcx, f, tps, id, sp, i);
190183
}
191184

192-
fn fn_states(&crate_ctxt ccx, &_fn f, &ast::ty_param[] tps,
193-
&span sp, &fn_ident i, node_id id) {
185+
fn fn_states(&_fn f, &ast::ty_param[] tps,
186+
&span sp, &fn_ident i, node_id id, &crate_ctxt ccx,
187+
&visit::vt[crate_ctxt] v) {
188+
visit::visit_fn(f, tps, sp, i, id, ccx, v);
194189
/* Look up the var-to-bit-num map for this function */
195-
190+
196191
assert (ccx.fm.contains_key(id));
197192
auto f_info = ccx.fm.get(id);
198193
auto name = option::from_maybe("anon", i);
@@ -210,19 +205,14 @@ fn check_crate(ty::ctxt cx, @crate crate) {
210205
annotate_crate(ccx, *crate);
211206
/* Compute the pre and postcondition for every subexpression */
212207

213-
auto do_pre_post = walk::default_visitor();
214-
do_pre_post =
215-
rec(visit_fn_post=bind fn_pre_post(ccx, _, _, _, _, _)
216-
with do_pre_post);
217-
walk::walk_crate(do_pre_post, *crate);
208+
auto vtor = visit::default_visitor[crate_ctxt]();
209+
vtor = @rec(visit_fn=fn_pre_post with *vtor);
210+
visit::visit_crate(*crate, ccx, visit::mk_vt(vtor));
211+
218212
/* Check the pre- and postcondition against the pre- and poststate
219213
for every expression */
220-
221-
auto do_states = walk::default_visitor();
222-
do_states =
223-
rec(visit_fn_post=bind fn_states(ccx, _, _, _, _, _)
224-
with do_states);
225-
walk::walk_crate(do_states, *crate);
214+
vtor = @rec(visit_fn=fn_states with *vtor);
215+
visit::visit_crate(*crate, ccx, visit::mk_vt(vtor));
226216
}
227217
//
228218
// Local Variables:

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,7 @@ import syntax::visit;
99
import walk::walk_crate;
1010
import walk::walk_fn;
1111
import walk::ast_visitor;
12-
import aux::cinit;
13-
import aux::ninit;
14-
import aux::npred;
15-
import aux::cpred;
16-
import aux::constraint;
17-
import aux::fn_info;
18-
import aux::crate_ctxt;
19-
import aux::num_constraints;
20-
import aux::constr_map;
21-
import aux::expr_to_constr;
22-
import aux::constraints_expr;
23-
import aux::node_id_to_def_strict;
12+
import aux::*;
2413
import std::map::new_int_hash;
2514
import util::common::new_def_hash;
2615
import syntax::codemap::span;
@@ -63,10 +52,6 @@ fn collect_pred(&@expr e, &ctxt cx, &visit::vt[ctxt] v) {
6352
// visit subexpressions
6453
visit::visit_expr(e, cx, v);
6554
}
66-
67-
fn do_nothing(&_fn f, &ty_param[] tp, &span sp, &fn_ident i,
68-
node_id iid, &ctxt cx, &visit::vt[ctxt] v) {
69-
}
7055

7156
fn find_locals(&ty::ctxt tcx, &_fn f, &ty_param[] tps, &span sp, &fn_ident i,
7257
node_id id) -> ctxt {

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import bitvectors::relax_precond_block;
3232
import bitvectors::gen;
3333
import tritv::tritv_clone;
3434
import syntax::ast::*;
35+
import syntax::visit;
3536
import std::map::new_int_hash;
3637
import util::common::new_def_hash;
3738
import util::common::log_expr;
@@ -719,8 +720,10 @@ fn find_pre_post_fn(&fn_ctxt fcx, &_fn f) {
719720
}
720721
}
721722

722-
fn fn_pre_post(crate_ctxt ccx, &_fn f, &ty_param[] tps,
723-
&span sp, &fn_ident i, node_id id) {
723+
fn fn_pre_post(&_fn f, &ty_param[] tps,
724+
&span sp, &fn_ident i, node_id id, &crate_ctxt ccx,
725+
&visit::vt[crate_ctxt] v) {
726+
visit::visit_fn(f, tps, sp, i, id, ccx, v);
724727
assert (ccx.fm.contains_key(id));
725728
auto fcx = rec(enclosing=ccx.fm.get(id), id=id,
726729
name=fn_ident_to_string(id, i), ccx=ccx);

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

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -24,52 +24,6 @@ import tstate::ann::ts_ann;
2424
import tstate::ann::set_prestate;
2525
import tstate::ann::set_poststate;
2626
import aux::*;
27-
/*
28-
import aux::crate_ctxt;
29-
import aux::fn_ctxt;
30-
import aux::num_constraints;
31-
import aux::expr_pp;
32-
import aux::stmt_pp;
33-
import aux::block_pp;
34-
import aux::set_pre_and_post;
35-
import aux::expr_prestate;
36-
import aux::expr_precond;
37-
import aux::expr_postcond;
38-
import aux::stmt_poststate;
39-
import aux::expr_poststate;
40-
import aux::block_prestate;
41-
import aux::block_poststate;
42-
import aux::block_precond;
43-
import aux::block_postcond;
44-
import aux::fn_info;
45-
import aux::log_pp;
46-
import aux::log_pp_err;
47-
import aux::extend_prestate_ann;
48-
import aux::extend_poststate_ann;
49-
import aux::set_prestate_ann;
50-
import aux::set_poststate_ann;
51-
import aux::pure_exp;
52-
import aux::log_tritv;
53-
import aux::log_tritv_err;
54-
import aux::stmt_to_ann;
55-
import aux::log_states;
56-
import aux::log_states_err;
57-
import aux::block_states;
58-
import aux::controlflow_expr;
59-
import aux::node_id_to_def;
60-
import aux::expr_to_constr;
61-
import aux::ninit;
62-
import aux::npred;
63-
import aux::path_to_ident;
64-
import aux::if_ty;
65-
import aux::if_check;
66-
import aux::plain_if;
67-
import aux::forget_in_poststate;
68-
import aux::forget_in_poststate_still_init;
69-
import aux::copy_in_poststate;
70-
import aux::copy_in_poststate_two;
71-
import aux::local_node_id_to_def;
72-
*/
7327
import tritv::tritv_clone;
7428
import tritv::tritv_set;
7529
import tritv::ttrue;
@@ -229,7 +183,13 @@ fn find_pre_post_state_loop(&fn_ctxt fcx, prestate pres, &@local l,
229183

230184
auto changed = set_prestate_ann(fcx.ccx, id, loop_pres) |
231185
find_pre_post_state_expr(fcx, pres, index);
232-
find_pre_post_state_block(fcx, expr_poststate(fcx.ccx, index), body);
186+
187+
// Make sure the index var is considered initialized
188+
// in the body
189+
auto index_post = tritv_clone(expr_poststate(fcx.ccx, index));
190+
set_in_poststate_ident(fcx, l.node.id, l.node.ident, index_post);
191+
192+
changed |= find_pre_post_state_block(fcx, index_post, body);
233193

234194
if (has_nonlocal_exits(body)) {
235195
// See [Break-unsound]
@@ -238,11 +198,6 @@ fn find_pre_post_state_loop(&fn_ctxt fcx, prestate pres, &@local l,
238198
else {
239199
auto res_p = intersect_states(expr_poststate(fcx.ccx, index),
240200
block_poststate(fcx.ccx, body));
241-
/*
242-
auto res_p =
243-
intersect_postconds([expr_poststate(fcx.ccx, index),
244-
block_poststate(fcx.ccx, body)]); */
245-
246201
ret changed | set_poststate_ann(fcx.ccx, id, res_p);
247202
}
248203
}

0 commit comments

Comments
 (0)