Skip to content

Commit 6bda5e6

Browse files
catamorphismgraydon
authored andcommitted
---
yaml --- r: 2647 b: refs/heads/master c: b74d0d7 h: refs/heads/master i: 2645: ac4e613 2643: 371f867 2639: 40c60a2 v: v3
1 parent e0133e6 commit 6bda5e6

File tree

3 files changed

+13
-44
lines changed

3 files changed

+13
-44
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: d60e08c18e25dd2699a67b59b6d29126f53a28c2
2+
refs/heads/master: b74d0d7c3d48f8d8e8944389b9094cab7693e512

trunk/src/comp/driver/rustc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ fn compile_input(session::session sess,
104104
auto type_cache = typeck_result._1;
105105

106106
if (sess.get_opts().run_typestate) {
107-
crate = time(time_passes, "typestate checking",
108-
bind middle::tstate::ck::check_crate(node_type_table,
109-
ty_cx, crate));
107+
time(time_passes, "typestate checking",
108+
bind middle::tstate::ck::check_crate(node_type_table,
109+
ty_cx, crate));
110110
}
111111

112112
auto llmod = time[llvm::ModuleRef](time_passes, "translation",

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

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ import front::ast::ty_param;
1313
import front::ast::crate;
1414

1515
import front::ast::expr;
16-
import middle::fold::respan;
17-
import middle::fold::new_identity_fold;
18-
import middle::fold::fold_crate;
1916
import middle::ty::type_is_nil;
2017
import middle::ty::ret_ty_of_fn;
2118
import util::common::span;
@@ -153,43 +150,16 @@ fn check_fn_states(&fn_ctxt fcx, &_fn f, &ann a) -> () {
153150
check_states_against_conditions(fcx, f, a);
154151
}
155152

156-
fn check_item_fn_state(&crate_ctxt ccx, &span sp, &ident i,
157-
&_fn f, &vec[ty_param] ty_params,
158-
&def_id id, &ann a) -> @item {
159-
153+
fn fn_states(&crate_ctxt ccx, &_fn f, &ident i, &def_id id, &ann a) -> () {
160154
/* Look up the var-to-bit-num map for this function */
161155
assert (ccx.fm.contains_key(id));
162156
auto f_info = ccx.fm.get(id);
163157

164158
auto fcx = rec(enclosing=f_info, id=id, name=i, ccx=ccx);
165159
check_fn_states(fcx, f, a);
166-
167-
/* Rebuild the same function */
168-
ret @respan(sp, item_fn(i, f, ty_params, id, a));
169-
}
170-
171-
fn check_method_states(&crate_ctxt ccx, @method m) -> () {
172-
assert (ccx.fm.contains_key(m.node.id));
173-
auto fcx = rec(enclosing=ccx.fm.get(m.node.id),
174-
id=m.node.id, name=m.node.ident, ccx=ccx);
175-
check_fn_states(fcx, m.node.meth, m.node.ann);
176-
}
177-
178-
fn check_obj_state(&crate_ctxt ccx, &vec[obj_field] fields,
179-
&vec[@method] methods,
180-
&option::t[@method] dtor) -> _obj {
181-
fn one(crate_ctxt ccx, &@method m) -> () {
182-
ret check_method_states(ccx, m);
183-
}
184-
auto f = bind one(ccx,_);
185-
vec::map[@method, ()](f, methods);
186-
option::map[@method, ()](f, dtor);
187-
ret rec(fields=fields, methods=methods, dtor=dtor);
188160
}
189161

190-
/* FIXME use walk instead of fold where possible */
191-
192-
fn check_crate(ty::node_type_table nt, ty::ctxt cx, @crate crate) -> @crate {
162+
fn check_crate(ty::node_type_table nt, ty::ctxt cx, @crate crate) -> () {
193163
let crate_ctxt ccx = new_crate_ctxt(nt, cx);
194164

195165
/* Build the global map from function id to var-to-bit-num-map */
@@ -200,17 +170,16 @@ fn check_crate(ty::node_type_table nt, ty::ctxt cx, @crate crate) -> @crate {
200170

201171
/* Compute the pre and postcondition for every subexpression */
202172
auto do_pre_post = walk::default_visitor();
203-
do_pre_post = rec(visit_fn_pre = bind fn_pre_post(ccx, _, _, _)
173+
do_pre_post = rec(visit_fn_pre = bind fn_pre_post(ccx,_,_,_,_)
204174
with do_pre_post);
205175
walk::walk_crate(do_pre_post, *crate);
206176

207-
auto fld1 = new_identity_fold[crate_ctxt]();
208-
209-
fld1 = @rec(fold_item_fn = bind check_item_fn_state(_,_,_,_,_,_,_),
210-
fold_obj = bind check_obj_state(_,_,_,_)
211-
with *fld1);
212-
213-
ret fold_crate[crate_ctxt](ccx, fld1, crate);
177+
/* Check the pre- and postcondition against the pre- and poststate
178+
for every expression */
179+
auto do_states = walk::default_visitor();
180+
do_states = rec(visit_fn_pre = bind fn_states(ccx,_,_,_,_)
181+
with do_states);
182+
walk::walk_crate(do_states, *crate);
214183
}
215184

216185
//

0 commit comments

Comments
 (0)