Skip to content

Commit 64b5ae2

Browse files
committed
Start annotating FIXMEs in typestate; also some minor refactoring
1 parent 6b2cfe7 commit 64b5ae2

File tree

2 files changed

+19
-51
lines changed

2 files changed

+19
-51
lines changed

src/rustc/middle/tstate/ann.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type poststate = t;
3434
type pre_and_post = {precondition: precond, postcondition: postcond};
3535

3636

37-
/* FIXME: once it's implemented: */
37+
/* FIXME: once it's implemented: (Issue #34) */
3838

3939
// : ((*.precondition).nbits == (*.postcondition).nbits);
4040
type pre_and_post_state = {prestate: prestate, poststate: poststate};
@@ -196,7 +196,6 @@ fn extend_poststate(p: poststate, newv: poststate) -> bool {
196196
}
197197

198198
// Sets the given bit in p to "don't care"
199-
// FIXME: is this correct?
200199
fn relax_prestate(i: uint, p: prestate) -> bool {
201200
let was_set = tritv_get(p, i);
202201
tritv_set(i, p, dont_care);
@@ -234,7 +233,6 @@ fn clone(p: prestate) -> prestate { ret tritv_clone(p); }
234233
// returns true if a implies b
235234
// that is, returns true except if for some bits c and d,
236235
// c = 1 and d = either 0 or "don't know"
237-
// FIXME: is this correct?
238236
fn implies(a: t, b: t) -> bool {
239237
let tmp = tritv_clone(b);
240238
tritv_difference(tmp, a);
@@ -244,6 +242,10 @@ fn implies(a: t, b: t) -> bool {
244242
fn trit_str(t: trit) -> str {
245243
alt t { dont_care { "?" } ttrue { "1" } tfalse { "0" } }
246244
}
245+
246+
// FIXME: Would be nice to have unit tests for some of these operations, as
247+
// a step towards formalizing them more rigorously. #2538
248+
247249
//
248250
// Local Variables:
249251
// mode: rust

src/rustc/middle/tstate/auxiliary.rs

Lines changed: 14 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ may be the operator in a "check" expression in the source. */
196196
type constraint = {
197197
path: @path,
198198
// FIXME: really only want it to be mut during collect_locals.
199-
// freeze it after that.
199+
// freeze it after that. (#2539)
200200
descs: @dvec<pred_args>
201201
};
202202

@@ -496,7 +496,7 @@ fn constraints(fcx: fn_ctxt) -> [norm_constraint] {
496496

497497
// FIXME
498498
// Would rather take an immutable vec as an argument,
499-
// should freeze it at some earlier point.
499+
// should freeze it at some earlier point. (#2539)
500500
fn match_args(fcx: fn_ctxt, occs: @dvec<pred_args>,
501501
occ: [@constr_arg_use]) -> uint {
502502
#debug("match_args: looking at %s",
@@ -715,28 +715,23 @@ fn replace(subst: subst, d: pred_args) -> [constr_arg_general_<inst>] {
715715
}
716716
}
717717
_ {
718-
// #error("##");
719718
rslt += [c.node];
720719
}
721720
}
722721
}
723722

724-
/*
725-
for (constr_arg_general_<tup(ident, def_id)> p in rslt) {
726-
alt (p) {
727-
case (carg_ident(?p)) {
728-
log(error, p._0);
729-
}
730-
case (_) {}
731-
}
732-
}
733-
*/
734-
735723
ret rslt;
736724
}
737725

738726
enum if_ty { if_check, plain_if, }
739727

728+
fn for_constraints_mentioning(fcx: fn_ctxt, id: node_id,
729+
f: fn(norm_constraint)) {
730+
for constraints(fcx).each {|c|
731+
if constraint_mentions(fcx, c, id) { f(c); }
732+
};
733+
}
734+
740735
fn local_node_id_to_def_id_strict(fcx: fn_ctxt, sp: span, i: node_id) ->
741736
def_id {
742737
alt local_node_id_to_def(fcx, i) {
@@ -787,7 +782,6 @@ fn copy_in_postcond(fcx: fn_ctxt, parent_exp: node_id, dest: inst, src: inst,
787782
copy_in_poststate_two(fcx, post, post, dest, src, ty);
788783
}
789784

790-
// FIXME refactor
791785
fn copy_in_poststate(fcx: fn_ctxt, post: poststate, dest: inst, src: inst,
792786
ty: oper_type) {
793787
copy_in_poststate_two(fcx, post, post, dest, src, ty);
@@ -823,42 +817,31 @@ fn copy_in_poststate_two(fcx: fn_ctxt, src_post: poststate,
823817
};
824818
}
825819

826-
/* FIXME should refactor this better */
827820
fn forget_in_postcond(fcx: fn_ctxt, parent_exp: node_id, dead_v: node_id) {
828821
// In the postcondition given by parent_exp, clear the bits
829822
// for any constraints mentioning dead_v
830823
let d = local_node_id_to_local_def_id(fcx, dead_v);
831-
alt d {
832-
some(d_id) {
833-
for constraints(fcx).each {|c|
834-
if constraint_mentions(fcx, c, d_id) {
824+
option::iter(d) {|d_id|
825+
for_constraints_mentioning(fcx, d_id) {|c|
835826
#debug("clearing constraint %u %s",
836827
c.bit_num,
837828
constraint_to_str(fcx.ccx.tcx, c.c));
838829
clear_in_postcond(c.bit_num,
839830
node_id_to_ts_ann(fcx.ccx,
840831
parent_exp).conditions);
841-
}
842832
}
843-
}
844-
_ { }
845-
}
833+
};
846834
}
847835

848836
fn forget_in_poststate(fcx: fn_ctxt, p: poststate, dead_v: node_id) -> bool {
849837
// In the poststate given by parent_exp, clear the bits
850838
// for any constraints mentioning dead_v
851839
let d = local_node_id_to_local_def_id(fcx, dead_v);
852840
let mut changed = false;
853-
alt d {
854-
some(d_id) {
855-
for constraints(fcx).each {|c|
856-
if constraint_mentions(fcx, c, d_id) {
841+
option::iter(d) {|d_id|
842+
for_constraints_mentioning(fcx, d_id) {|c|
857843
changed |= clear_in_poststate_(c.bit_num, p);
858-
}
859844
}
860-
}
861-
_ { }
862845
}
863846
ret changed;
864847
}
@@ -876,23 +859,6 @@ fn constraint_mentions(_fcx: fn_ctxt, c: norm_constraint, v: node_id) ->
876859
fn args_mention<T>(args: [@constr_arg_use],
877860
q: fn([T], node_id) -> bool,
878861
s: [T]) -> bool {
879-
/*
880-
FIXME
881-
The following version causes an assertion in trans to fail
882-
(something about type_is_tup_like)
883-
fn mentions<T>(&[T] s, &fn(&[T], def_id) -> bool q,
884-
&@constr_arg_use a) -> bool {
885-
alt (a.node) {
886-
case (carg_ident(?p1)) {
887-
auto res = q(s, p1._1);
888-
log(error, (res));
889-
res
890-
}
891-
case (_) { false }
892-
}
893-
}
894-
ret vec::any(bind mentions(s,q,_), args);
895-
*/
896862

897863
for args.each {|a|
898864
alt a.node { carg_ident(p1) { if q(s, p1.node) { ret true; } } _ { } }

0 commit comments

Comments
 (0)