Skip to content

Commit abab046

Browse files
committed
rustc: Move middle::tstate::auxiliary and middle::tstate::bitvectors over to interior vectors
1 parent 6d1517c commit abab046

File tree

5 files changed

+131
-123
lines changed

5 files changed

+131
-123
lines changed

src/comp/middle/tstate/auxiliary.rs

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import std::ivec;
12
import std::str;
23
import std::vec;
34
import std::vec::len;
@@ -48,7 +49,7 @@ fn def_id_to_str(def_id d) -> str {
4849
ret int::str(d._0) + "," + int::str(d._1);
4950
}
5051

51-
fn comma_str(vec[@constr_arg_use] args) -> str {
52+
fn comma_str(&(@constr_arg_use)[] args) -> str {
5253
auto rslt = "";
5354
auto comma = false;
5455
for (@constr_arg_use a in args) {
@@ -107,17 +108,17 @@ fn first_difference_string(&fn_ctxt fcx, &tritv::t expected, &tritv::t actual)
107108

108109
fn log_tritv_err(fn_ctxt fcx, tritv::t v) { log_err tritv_to_str(fcx, v); }
109110

110-
fn tos(vec[uint] v) -> str {
111+
fn tos(&uint[] v) -> str {
111112
auto rslt = "";
112113
for (uint i in v) { if (i == 0u) { rslt += "0"; }
113114
else if (i == 1u) { rslt += "1"; }
114115
else { rslt += "?"; } }
115116
ret rslt;
116117
}
117118

118-
fn log_cond(vec[uint] v) { log tos(v); }
119+
fn log_cond(&uint[] v) { log tos(v); }
119120

120-
fn log_cond_err(vec[uint] v) { log_err tos(v); }
121+
fn log_cond_err(&uint[] v) { log_err tos(v); }
121122

122123
fn log_pp(&pre_and_post pp) {
123124
auto p1 = tritv::to_vec(pp.precondition);
@@ -157,10 +158,10 @@ fn log_states_err(&pre_and_post_state pp) {
157158

158159
fn print_ident(&ident i) { log " " + i + " "; }
159160
160-
fn print_idents(vec[ident] idents) {
161-
if (len[ident](idents) == 0u) {
162-
ret;
163-
} else { log "an ident: " + pop[ident](idents); print_idents(idents); }
161+
fn print_idents(&mutable ident[] idents) {
162+
if (ivec::len[ident](idents) == 0u) { ret; }
163+
log "an ident: " + ivec::pop[ident](idents);
164+
print_idents(idents);
164165
}
165166
166167
@@ -194,18 +195,21 @@ to represent predicate *arguments* however. This type
194195
195196
Both types store an ident and span, for error-logging purposes.
196197
*/
197-
type pred_desc_ = rec(vec[@constr_arg_use] args, uint bit_num);
198+
type pred_desc_ = rec((@constr_arg_use)[] args, uint bit_num);
198199
199200
type pred_desc = spanned[pred_desc_];
200201
201202
type constr_arg_use = constr_arg_general[tup(ident, def_id)];
202203
203204
tag constraint {
204205
cinit(uint, span, ident);
205-
cpred(path, @mutable vec[pred_desc]);
206+
cpred(path, @mutable pred_desc[]);
206207
}
207208
208-
tag constr__ { ninit(ident); npred(path, vec[@constr_arg_use]); }
209+
tag constr__ {
210+
ninit(ident);
211+
npred(path, (@constr_arg_use)[]);
212+
}
209213
210214
type constr_ = rec(node_id id, constr__ c);
211215
@@ -223,11 +227,11 @@ type fn_info = rec(constr_map constrs,
223227
used*/
224228
// Doesn't seem to work without the @ --
225229
// bug?
226-
@mutable vec[node_id] used_vars);
230+
@mutable node_id[] used_vars);
227231
228232
229233
/* mapping from node ID to typestate annotation */
230-
type node_ann_table = @mutable vec[mutable ts_ann];
234+
type node_ann_table = @mutable ts_ann[mutable];
231235
232236
233237
/* mapping from function name to fn_info map */
@@ -243,15 +247,15 @@ fn get_fn_info(&crate_ctxt ccx, node_id id) -> fn_info {
243247
}
244248
245249
fn add_node(&crate_ctxt ccx, node_id i, &ts_ann a) {
246-
auto sz = len(*ccx.node_anns);
250+
auto sz = ivec::len(*ccx.node_anns);
247251
if (sz <= i as uint) {
248-
grow(*ccx.node_anns, (i as uint) - sz + 1u, empty_ann(0u));
252+
ivec::grow_mut(*ccx.node_anns, (i as uint) - sz + 1u, empty_ann(0u));
249253
}
250254
ccx.node_anns.(i) = a;
251255
}
252256
253257
fn get_ts_ann(&crate_ctxt ccx, node_id i) -> option::t[ts_ann] {
254-
if (i as uint < len(*ccx.node_anns)) {
258+
if (i as uint < ivec::len(*ccx.node_anns)) {
255259
ret some[ts_ann](ccx.node_anns.(i));
256260
} else { ret none[ts_ann]; }
257261
}
@@ -439,7 +443,7 @@ fn pure_exp(&crate_ctxt ccx, node_id id, &prestate p) -> bool {
439443
fn num_constraints(fn_info m) -> uint { ret m.num_constraints; }
440444

441445
fn new_crate_ctxt(ty::ctxt cx) -> crate_ctxt {
442-
let vec[mutable ts_ann] na = vec::empty_mut();
446+
let ts_ann[mutable] na = ~[mutable];
443447
ret rec(tcx=cx, node_anns=@mutable na, fm=@new_int_hash[fn_info]());
444448
}
445449

@@ -474,19 +478,18 @@ fn node_id_to_def(&crate_ctxt ccx, node_id id) -> option::t[def] {
474478
ret ccx.tcx.def_map.find(id);
475479
}
476480

477-
fn norm_a_constraint(node_id id, &constraint c) -> vec[norm_constraint] {
481+
fn norm_a_constraint(node_id id, &constraint c) -> norm_constraint[] {
478482
alt (c) {
479483
case (cinit(?n, ?sp, ?i)) {
480-
ret [rec(bit_num=n, c=respan(sp, rec(id=id, c=ninit(i))))];
484+
ret ~[rec(bit_num=n, c=respan(sp, rec(id=id, c=ninit(i))))];
481485
}
482486
case (cpred(?p, ?descs)) {
483-
let vec[norm_constraint] rslt = [];
487+
let norm_constraint[] rslt = ~[];
484488
for (pred_desc pd in *descs) {
485-
vec::push(rslt,
486-
rec(bit_num=pd.node.bit_num,
489+
rslt += ~[rec(bit_num=pd.node.bit_num,
487490
c=respan(pd.span,
488491
rec(id=id,
489-
c=npred(p, pd.node.args)))));
492+
c=npred(p, pd.node.args))))];
490493
}
491494
ret rslt;
492495
}
@@ -496,15 +499,15 @@ fn norm_a_constraint(node_id id, &constraint c) -> vec[norm_constraint] {
496499

497500
// Tried to write this as an iterator, but I got a
498501
// non-exhaustive match in trans.
499-
fn constraints(&fn_ctxt fcx) -> vec[norm_constraint] {
500-
let vec[norm_constraint] rslt = [];
502+
fn constraints(&fn_ctxt fcx) -> norm_constraint[] {
503+
let norm_constraint[] rslt = ~[];
501504
for each (@tup(node_id, constraint) p in fcx.enclosing.constrs.items()) {
502505
rslt += norm_a_constraint(p._0, p._1);
503506
}
504507
ret rslt;
505508
}
506509

507-
fn match_args(&fn_ctxt fcx, vec[pred_desc] occs, &(@constr_arg_use)[] occ) ->
510+
fn match_args(&fn_ctxt fcx, &pred_desc[] occs, &(@constr_arg_use)[] occ) ->
508511
uint {
509512
log "match_args: looking at " +
510513
constr_args_to_str(std::util::fst[ident, def_id], occ);
@@ -564,10 +567,10 @@ fn expr_to_constr_arg(ty::ctxt tcx, &@expr e) -> @constr_arg_use {
564567
}
565568
}
566569

567-
fn exprs_to_constr_args(ty::ctxt tcx, vec[@expr] args) ->
568-
vec[@constr_arg_use] {
570+
fn exprs_to_constr_args(ty::ctxt tcx, &(@expr)[] args)
571+
-> (@constr_arg_use)[] {
569572
auto f = bind expr_to_constr_arg(tcx, _);
570-
ret vec::map(f, args);
573+
ret ivec::map(f, args);
571574
}
572575

573576
fn expr_to_constr(ty::ctxt tcx, &@expr e) -> constr {
@@ -578,10 +581,14 @@ fn expr_to_constr(ty::ctxt tcx, &@expr e) -> constr {
578581
expr_call(?operator, ?args)) {
579582
alt (operator.node) {
580583
case (expr_path(?p)) {
584+
// FIXME: Remove this vec->ivec conversion.
585+
auto args_ivec = ~[];
586+
for (@expr e in args) { args_ivec += ~[e]; }
587+
581588
ret respan(e.span,
582589
rec(id=node_id_for_constr(tcx, operator.id),
583-
c=npred(p,
584-
exprs_to_constr_args(tcx, args))));
590+
c=npred(p, exprs_to_constr_args(tcx,
591+
args_ivec))));
585592
}
586593
case (_) {
587594
tcx.sess.span_fatal(operator.span,
@@ -609,20 +616,20 @@ fn pred_desc_to_str(&pred_desc p) -> str {
609616
constr_args_to_str(std::util::fst[ident, def_id], cau_ivec) + ">";
610617
}
611618

612-
fn substitute_constr_args(&ty::ctxt cx, &vec[@expr] actuals,
619+
fn substitute_constr_args(&ty::ctxt cx, &(@expr)[] actuals,
613620
&@ty::constr_def c) -> constr__ {
614-
let vec[@constr_arg_use] rslt = [];
621+
let (@constr_arg_use)[] rslt = ~[];
615622
for (@constr_arg a in c.node.args) {
616-
rslt += [substitute_arg(cx, actuals, a)];
623+
rslt += ~[substitute_arg(cx, actuals, a)];
617624
}
618625
ret npred(c.node.path, rslt);
619626
}
620627

621-
type subst = vec[tup(arg, @expr)];
628+
type subst = tup(arg, @expr)[];
622629

623-
fn substitute_arg(&ty::ctxt cx, &vec[@expr] actuals, @constr_arg a) ->
630+
fn substitute_arg(&ty::ctxt cx, &(@expr)[] actuals, @constr_arg a) ->
624631
@constr_arg_use {
625-
auto num_actuals = vec::len(actuals);
632+
auto num_actuals = ivec::len(actuals);
626633
alt (a.node) {
627634
case (carg_ident(?i)) {
628635
if (i < num_actuals) {
@@ -778,26 +785,28 @@ fn non_init_constraint_mentions(&fn_ctxt fcx, &norm_constraint c,
778785
}
779786

780787

781-
fn args_mention(&vec[@constr_arg_use] args, &def_id v) -> bool {
788+
fn args_mention(&(@constr_arg_use)[] args, &def_id v) -> bool {
782789
fn mentions(&def_id v, &@constr_arg_use a) -> bool {
783790
alt (a.node) {
784791
case (carg_ident(?p1)) { p1._1 == v }
785792
case (_) { false }
786793
}
787794
}
788-
ret util::common::any[@constr_arg_use](bind mentions(v,_), args);
795+
ret ivec::any[@constr_arg_use](bind mentions(v,_), args);
789796
}
790797

791798
fn use_var(&fn_ctxt fcx, &node_id v) {
792-
vec::push(*fcx.enclosing.used_vars, v);
799+
*fcx.enclosing.used_vars += ~[v];
793800
}
794801

795-
fn vec_contains(&@mutable vec[node_id] v, &node_id i) -> bool {
802+
// FIXME: This should be a function in std::ivec::.
803+
fn vec_contains(&@mutable (node_id[]) v, &node_id i) -> bool {
796804
for (node_id d in *v) {
797805
if (d == i) { ret true; }
798806
}
799807
ret false;
800808
}
809+
801810
//
802811
// Local Variables:
803812
// mode: rust

src/comp/middle/tstate/bitvectors.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11

22
import syntax::ast::*;
33
import syntax::walk;
4+
import std::ivec;
45
import std::option::*;
56
import std::vec;
6-
import std::vec::len;
7-
import std::vec::slice;
87
import aux::constr_arg_use;
98
import aux::local_node_id_to_def;
109
import aux::fn_ctxt;
@@ -70,7 +69,8 @@ fn bit_num(&fn_ctxt fcx, &constr_ c) -> uint {
7069
for (@constr_arg_use cau in args) {
7170
cau_ivec += ~[cau];
7271
}
73-
ret match_args(fcx, *descs, cau_ivec);
72+
auto d = *descs;
73+
ret match_args(fcx, d, cau_ivec);
7474
}
7575
case (_) {
7676
fcx.ccx.tcx.sess.bug("bit_num: asked for pred constraint,"
@@ -106,11 +106,11 @@ fn seq_tritv(&postcond p, &postcond q) {
106106
}
107107
}
108108

109-
fn seq_postconds(&fn_ctxt fcx, &vec[postcond] ps) -> postcond {
110-
auto sz = vec::len(ps);
109+
fn seq_postconds(&fn_ctxt fcx, &postcond[] ps) -> postcond {
110+
auto sz = ivec::len(ps);
111111
if (sz >= 1u) {
112112
auto prev = tritv_clone(ps.(0));
113-
for (postcond p in slice(ps, 1u, sz)) {
113+
for (postcond p in ivec::slice(ps, 1u, sz)) {
114114
seq_tritv(prev, p);
115115
}
116116
ret prev;
@@ -124,14 +124,14 @@ fn seq_postconds(&fn_ctxt fcx, &vec[postcond] ps) -> postcond {
124124
// return the precondition for evaluating each expr in order.
125125
// So, if e0's post is {x} and e1's pre is {x, y, z}, the entire
126126
// precondition shouldn't include x.
127-
fn seq_preconds(&fn_ctxt fcx, &vec[pre_and_post] pps) -> precond {
128-
let uint sz = len(pps);
127+
fn seq_preconds(&fn_ctxt fcx, &pre_and_post[] pps) -> precond {
128+
let uint sz = ivec::len(pps);
129129
let uint num_vars = num_constraints(fcx.enclosing);
130130

131-
fn seq_preconds_go(&fn_ctxt fcx, &vec[pre_and_post] pps,
131+
fn seq_preconds_go(&fn_ctxt fcx, &pre_and_post[] pps,
132132
&pre_and_post first)
133133
-> precond {
134-
let uint sz = len(pps);
134+
let uint sz = ivec::len(pps);
135135
if (sz >= 1u) {
136136
auto second = pps.(0);
137137
assert (pps_len(second) == num_constraints(fcx.enclosing));
@@ -141,7 +141,7 @@ fn seq_preconds(&fn_ctxt fcx, &vec[pre_and_post] pps) -> precond {
141141
union(next_first, second_pre);
142142
auto next_first_post = clone(first.postcondition);
143143
seq_tritv(next_first_post, second.postcondition);
144-
ret seq_preconds_go(fcx, slice(pps, 1u, sz),
144+
ret seq_preconds_go(fcx, ivec::slice(pps, 1u, sz),
145145
@rec(precondition=next_first,
146146
postcondition=next_first_post));
147147
}
@@ -153,7 +153,7 @@ fn seq_preconds(&fn_ctxt fcx, &vec[pre_and_post] pps) -> precond {
153153
if (sz >= 1u) {
154154
auto first = pps.(0);
155155
assert (pps_len(first) == num_vars);
156-
ret seq_preconds_go(fcx, slice(pps, 1u, sz), first);
156+
ret seq_preconds_go(fcx, ivec::slice(pps, 1u, sz), first);
157157
} else { ret true_precond(num_vars); }
158158
}
159159

src/comp/middle/tstate/collect_locals.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,15 @@ fn collect_pred(&@expr e, &ctxt cx, &visit::vt[ctxt] v) {
4646
// If it's a call, generate appropriate instances of the
4747
// call's constraints.
4848
case (expr_call(?operator, ?operands)) {
49+
// FIXME: Remove this vec->ivec conversion.
50+
auto operands_ivec = ~[];
51+
for (@expr opd in operands) { operands_ivec += ~[opd]; }
52+
4953
for (@ty::constr_def c in constraints_expr(cx.tcx, operator)) {
5054
let aux::constr ct = respan(c.span,
5155
rec(id=c.node.id._1,
5256
c=aux::substitute_constr_args(cx.tcx,
53-
operands, c)));
57+
operands_ivec, c)));
5458
vec::push(*cx.cs, ct);
5559
}
5660
}
@@ -93,18 +97,17 @@ fn add_constraint(&ty::ctxt tcx, aux::constr c, uint next, constr_map tbl) ->
9397
" as a variable and a pred");
9498
}
9599
case (cpred(_, ?pds)) {
96-
vec::push(*pds,
97-
respan(c.span,
98-
rec(args=args, bit_num=next)));
100+
*pds += ~[respan(c.span,
101+
rec(args=args, bit_num=next))];
99102
}
100103
}
101104
}
102105
case (none) {
103106
tbl.insert(c.node.id,
104107
cpred(p,
105-
@mutable [respan(c.span,
106-
rec(args=args,
107-
bit_num=next))]));
108+
@mutable ~[respan(c.span,
109+
rec(args=args,
110+
bit_num=next))]));
108111
}
109112
}
110113
}
@@ -134,7 +137,7 @@ fn mk_fn_info(&crate_ctxt ccx, &_fn f, &vec[ty_param] tp,
134137
auto name = fn_ident_to_string(id, f_name);
135138
add_constraint(cx.tcx, respan(f_sp, rec(id=id, c=ninit(name))), next,
136139
res_map);
137-
let @mutable vec[node_id] v = @mutable [];
140+
let @mutable node_id[] v = @mutable ~[];
138141
auto rslt =
139142
rec(constrs=res_map,
140143
num_constraints=vec::len(*cx.cs) + 1u,

0 commit comments

Comments
 (0)