Skip to content

Commit 5fb518a

Browse files
committed
Fix assignments to immutable fields throughout the code
1 parent 180db08 commit 5fb518a

File tree

10 files changed

+55
-54
lines changed

10 files changed

+55
-54
lines changed

src/comp/middle/metadata.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -672,21 +672,21 @@ fn hash_path(&str s) -> uint {
672672

673673
fn create_index[T](&vec[tup(T, uint)] index, fn(&T) -> uint hash_fn)
674674
-> vec[vec[tup(T, uint)]] {
675-
let vec[vec[tup(T, uint)]] buckets = [];
675+
let vec[mutable vec[tup(T, uint)]] buckets = vec::empty_mut();
676676
for each (uint i in uint::range(0u, 256u)) {
677-
let vec[tup(T, uint)] bucket = [];
678-
buckets += [bucket];
677+
buckets += [mutable []];
679678
}
680679

681680
for (tup(T, uint) elt in index) {
682681
auto h = hash_fn(elt._0);
683682
buckets.(h % 256u) += [elt];
684683
}
685684

686-
ret buckets;
685+
ret vec::freeze(buckets);
687686
}
688687

689-
fn encode_index[T](&ebml::writer ebml_w, &vec[vec[tup(T, uint)]] buckets,
688+
fn encode_index[T](&ebml::writer ebml_w,
689+
&vec[vec[tup(T, uint)]] buckets,
690690
fn(&io::writer, &T) write_fn) {
691691
auto writer = io::new_writer_(ebml_w.writer);
692692

src/comp/middle/resolve.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ tag mod_index_entry {
8080
type mod_index = hashmap[ident,list[mod_index_entry]];
8181

8282
type indexed_mod = rec(option::t[ast::_mod] m,
83-
mod_index index, vec[def] glob_imports,
83+
mod_index index,
84+
mutable vec[def] glob_imports,
8485
hashmap[str,import_state] glob_imported_names);
8586
/* native modules can't contain tags, and we don't store their ASTs because we
8687
only need to look at them to determine exports, which they can't control.*/
@@ -141,7 +142,7 @@ fn map_crate(&@env e, &@ast::crate c) {
141142
// Register the top-level mod
142143
e.mod_map.insert(-1, @rec(m=some(c.node.module),
143144
index=index_mod(c.node.module),
144-
glob_imports=vec::empty[def](),
145+
mutable glob_imports=vec::empty[def](),
145146
glob_imported_names
146147
=new_str_hash[import_state]()));
147148

@@ -160,7 +161,7 @@ fn map_crate(&@env e, &@ast::crate c) {
160161
case (ast::item_mod(_, ?md, ?defid)) {
161162
e.mod_map.insert(defid._1,
162163
@rec(m=some(md), index=index_mod(md),
163-
glob_imports=vec::empty[def](),
164+
mutable glob_imports=vec::empty[def](),
164165
glob_imported_names
165166
=new_str_hash[import_state]()));
166167
e.ast_map.insert(defid, i);
@@ -169,7 +170,7 @@ fn map_crate(&@env e, &@ast::crate c) {
169170
e.mod_map.insert(defid._1,
170171
@rec(m=none[ast::_mod],
171172
index=index_nmod(nmd),
172-
glob_imports=vec::empty[def](),
173+
mutable glob_imports=vec::empty[def](),
173174
glob_imported_names
174175
=new_str_hash[import_state]()));
175176
e.ast_map.insert(defid, i);
@@ -850,7 +851,7 @@ fn lookup_glob_in_mod(&env e, @indexed_mod info, &span sp,
850851

851852
auto matches = vec::filter_map[def, def]
852853
(bind l_i_m_r(e, _, sp, id, ns, dr),
853-
info.glob_imports);
854+
{info.glob_imports});
854855
if (vec::len(matches) == 0u) {
855856
ret none[def];
856857
} else if (vec::len(matches) == 1u){

src/comp/middle/trans.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -5995,12 +5995,12 @@ fn trans_rec(&@block_ctxt cx, &vec[ast::field] fields,
59955995
}
59965996

59975997
fn trans_expr(&@block_ctxt cx, &@ast::expr e) -> result {
5998-
be trans_expr_out(cx, e, return);
5998+
ret trans_expr_out(cx, e, return);
59995999
}
60006000

60016001
fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output)
60026002
-> result {
6003-
*cx = rec(sp=e.span with *cx);
6003+
// FIXME Fill in cx.sp
60046004
alt (e.node) {
60056005
case (ast::expr_lit(?lit, ?ann)) {
60066006
ret res(cx, trans_lit(cx.fcx.lcx.ccx, *lit, ann));
@@ -6059,7 +6059,6 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output)
60596059
}
60606060

60616061
case (ast::expr_block(?blk, ?ann)) {
6062-
*cx = rec(sp=blk.span with *cx);
60636062
auto sub_cx = new_scope_block_ctxt(cx, "block-expr body");
60646063
auto next_cx = new_sub_block_ctxt(cx, "next");
60656064
auto sub = with_out_method(bind trans_block(sub_cx, blk, _),
@@ -6072,7 +6071,7 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output)
60726071
case (ast::expr_move(?dst, ?src, _)) {
60736072
auto lhs_res = trans_lval(cx, dst);
60746073
assert (lhs_res.is_mem);
6075-
*(lhs_res.res.bcx) = rec(sp=src.span with *(lhs_res.res.bcx));
6074+
// FIXME Fill in lhs_res.res.bcx.sp
60766075
auto rhs_res = trans_lval(lhs_res.res.bcx, src);
60776076
auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, src);
60786077
// FIXME: calculate copy init-ness in typestate.
@@ -6084,7 +6083,7 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output)
60846083
case (ast::expr_assign(?dst, ?src, _)) {
60856084
auto lhs_res = trans_lval(cx, dst);
60866085
assert (lhs_res.is_mem);
6087-
*(lhs_res.res.bcx) = rec(sp=src.span with *(lhs_res.res.bcx));
6086+
// FIXME Fill in lhs_res.res.bcx.sp
60886087
auto rhs_res = trans_expr(lhs_res.res.bcx, src);
60896088
auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, src);
60906089
// FIXME: calculate copy init-ness in typestate.
@@ -6097,7 +6096,7 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output)
60976096
auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, src);
60986097
auto lhs_res = trans_lval(cx, dst);
60996098
assert (lhs_res.is_mem);
6100-
*(lhs_res.res.bcx) = rec(sp=src.span with *(lhs_res.res.bcx));
6099+
// FIXME Fill in lhs_res.res.bcx.sp
61016100
auto rhs_res = trans_expr(lhs_res.res.bcx, src);
61026101
if (ty::type_is_sequence(cx.fcx.lcx.ccx.tcx, t)) {
61036102
alt (op) {
@@ -7182,7 +7181,7 @@ fn zero_alloca(&@block_ctxt cx, ValueRef llptr, ty::t t) -> result {
71827181
}
71837182

71847183
fn trans_stmt(&@block_ctxt cx, &ast::stmt s) -> result {
7185-
*cx = rec(sp=s.span with *cx);
7184+
// FIXME Fill in cx.sp
71867185
auto bcx = cx;
71877186
alt (s.node) {
71887187
case (ast::stmt_expr(?e,_)) {
@@ -7352,7 +7351,7 @@ fn alloc_local(&@block_ctxt cx, &@ast::local_ local) -> result {
73527351
fn trans_block(&@block_ctxt cx, &ast::block b, &out_method output) -> result {
73537352
auto bcx = cx;
73547353
for each (@ast::local_ local in block_locals(b)) {
7355-
*bcx = rec(sp=local_rhs_span(local, cx.sp) with *bcx);
7354+
// FIXME Update bcx.sp
73567355
bcx = alloc_local(bcx, local).bcx;
73577356
}
73587357
auto r = res(bcx, C_nil());

src/comp/middle/tstate/auxiliary.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ type constr_map = @std::map::hashmap[def_id, constraint];
255255
type fn_info = rec(constr_map constrs, uint num_constraints, controlflow cf);
256256

257257
/* mapping from node ID to typestate annotation */
258-
type node_ann_table = @mutable vec[ts_ann];
258+
type node_ann_table = @mutable vec[mutable ts_ann];
259259

260260
/* mapping from function name to fn_info map */
261261
type fn_info_map = @std::map::hashmap[def_id, fn_info];
@@ -485,7 +485,7 @@ fn num_constraints(fn_info m) -> uint {
485485
}
486486

487487
fn new_crate_ctxt(ty::ctxt cx) -> crate_ctxt {
488-
let vec[ts_ann] na = [];
488+
let vec[mutable ts_ann] na = vec::empty_mut();
489489
ret rec(tcx=cx, node_anns=@mutable na, fm=@new_def_hash[fn_info]());
490490
}
491491

src/comp/middle/tstate/ck.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,17 @@ fn check_states_stmt(&fn_ctxt fcx, &stmt s) -> () {
114114
fn check_states_against_conditions(&fn_ctxt fcx, &_fn f, &ann a) -> () {
115115
auto enclosing = fcx.enclosing;
116116
auto nv = num_constraints(enclosing);
117-
auto post = @empty_poststate(nv);
117+
auto post = @mutable empty_poststate(nv);
118118

119-
fn do_one_(fn_ctxt fcx, &@stmt s, @poststate post) -> () {
119+
fn do_one_(fn_ctxt fcx, &@stmt s, @mutable poststate post) -> () {
120120
check_states_stmt(fcx, *s);
121121
*post = stmt_poststate(fcx.ccx, *s);
122122
}
123123

124124
auto do_one = bind do_one_(fcx, _, post);
125125

126126
vec::map[@stmt, ()](do_one, f.body.node.stmts);
127-
fn do_inner_(fn_ctxt fcx, &@expr e, @poststate post) -> () {
127+
fn do_inner_(fn_ctxt fcx, &@expr e, @mutable poststate post) -> () {
128128
check_states_expr(fcx, e);
129129
*post = expr_poststate(fcx.ccx, e);
130130
}
@@ -135,7 +135,7 @@ fn check_states_against_conditions(&fn_ctxt fcx, &_fn f, &ann a) -> () {
135135
/* Finally, check that the return value is initialized */
136136
let aux::constr_ ret_c = rec(id=fcx.id, c=aux::ninit(fcx.name));
137137
if (f.proto == ast::proto_fn
138-
&& ! promises(fcx, *post, ret_c)
138+
&& ! promises(fcx, {*post}, ret_c)
139139
&& ! type_is_nil(fcx.ccx.tcx,
140140
ret_ty_of_fn(fcx.ccx.tcx, a))
141141
&& cf == return) {
@@ -149,7 +149,7 @@ fn check_states_against_conditions(&fn_ctxt fcx, &_fn f, &ann a) -> () {
149149
// check that this really always fails
150150
// the fcx.id bit means "returns" for a returning fn,
151151
// "diverges" for a non-returning fn
152-
if (! promises(fcx, *post, ret_c)) {
152+
if (! promises(fcx, {*post}, ret_c)) {
153153
fcx.ccx.tcx.sess.span_err(f.body.span,
154154
"In non-returning function " + fcx.name +
155155
", some control paths may return to the caller");

src/comp/pretty/pp.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn tok_str(token t) -> str {
7878
}
7979
}
8080

81-
fn buf_str(vec[token] toks, vec[int] szs,
81+
fn buf_str(vec[mutable token] toks, vec[mutable int] szs,
8282
uint left, uint right, uint lim) -> str {
8383
auto n = vec::len(toks);
8484
assert n == vec::len(szs);
@@ -112,9 +112,9 @@ fn mk_printer(io::writer out, uint linewidth) -> printer {
112112

113113
log #fmt("mk_printer %u", linewidth);
114114

115-
let vec[token] token = vec::init_elt[token](EOF, n);
116-
let vec[int] size = vec::init_elt[int](0, n);
117-
let vec[uint] scan_stack = vec::init_elt[uint](0u, n);
115+
let vec[mutable token] token = vec::init_elt_mut(EOF, n);
116+
let vec[mutable int] size = vec::init_elt_mut(0, n);
117+
let vec[mutable uint] scan_stack = vec::init_elt_mut(0u, n);
118118
let vec[print_stack_elt] print_stack = [];
119119

120120
ret printer(out,
@@ -220,8 +220,8 @@ obj printer(io::writer out,
220220

221221
mutable uint left, // index of left side of input stream
222222
mutable uint right, // index of right side of input stream
223-
mutable vec[token] token, // ring-buffer stream goes through
224-
mutable vec[int] size, // ring-buffer of calculated sizes
223+
mutable vec[mutable token] token,// ring-buffr stream goes through
224+
mutable vec[mutable int] size, // ring-buffer of calculated sizes
225225
mutable int left_total, // running size of stream "...left"
226226
mutable int right_total, // running size of stream "...right"
227227

@@ -231,7 +231,7 @@ obj printer(io::writer out,
231231
// on top of it. Stuff is flushed off the bottom as it becomes
232232
// irrelevant due to the primary ring-buffer advancing.
233233

234-
mutable vec[uint] scan_stack,
234+
mutable vec[mutable uint] scan_stack,
235235
mutable bool scan_stack_empty, // top==bottom disambiguator
236236
mutable uint top, // index of top of scan_stack
237237
mutable uint bottom, // index of bottom of scan_stack

src/lib/deque.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,27 @@ fn create[T]() -> t[T] {
2727
* Grow is only called on full elts, so nelts is also len(elts), unlike
2828
* elsewhere.
2929
*/
30-
fn grow[T](uint nelts, uint lo, vec[cell[T]] elts) -> vec[cell[T]] {
31-
assert (nelts == vec::len[cell[T]](elts));
30+
fn grow[T](uint nelts, uint lo, vec[mutable cell[T]] elts)
31+
-> vec[mutable cell[T]] {
32+
assert (nelts == vec::len(elts));
3233

3334
// FIXME: Making the vector argument an alias is a workaround for
3435
// issue #375
3536
fn fill[T](uint i, uint nelts, uint lo,
36-
&vec[cell[T]] old) -> cell[T] {
37+
&vec[mutable cell[T]] old) -> cell[T] {
3738
ret if (i < nelts) {
3839
old.((lo + i) % nelts)
3940
} else {
40-
option::none[T]
41+
option::none
4142
};
4243
}
4344

4445
let uint nalloc = uint::next_power_of_two(nelts + 1u);
4546
let vec::init_op[cell[T]] copy_op = bind fill[T](_, nelts, lo, elts);
46-
ret vec::init_fn[cell[T]](copy_op, nalloc);
47+
ret vec::init_fn_mut[cell[T]](copy_op, nalloc);
4748
}
4849

49-
fn get[T](vec[cell[T]] elts, uint i) -> T {
50+
fn get[T](vec[mutable cell[T]] elts, uint i) -> T {
5051
ret alt (elts.(i)) {
5152
case (option::some(?t)) { t }
5253
case (_) { fail }
@@ -56,7 +57,7 @@ fn create[T]() -> t[T] {
5657
obj deque[T](mutable uint nelts,
5758
mutable uint lo,
5859
mutable uint hi,
59-
mutable vec[cell[T]] elts)
60+
mutable vec[mutable cell[T]] elts)
6061
{
6162
fn size() -> uint { ret nelts; }
6263

@@ -130,8 +131,8 @@ fn create[T]() -> t[T] {
130131
}
131132

132133
}
133-
let vec[cell[T]] v = vec::init_elt[cell[T]](option::none[T],
134-
initial_capacity);
134+
let vec[mutable cell[T]] v = vec::init_elt_mut(option::none,
135+
initial_capacity);
135136

136137
ret deque[T](0u, 0u, 0u, v);
137138
}

src/lib/vec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,14 @@ fn freeze[T](vec[mutable T] v) -> vec[T] {
385385
}
386386

387387
// Swaps two elements in a vector
388-
fn swap[T](&vec[T] v, uint a, uint b) {
388+
fn swap[T](&vec[mutable T] v, uint a, uint b) {
389389
let T t = v.(a);
390390
v.(a) = v.(b);
391391
v.(b) = t;
392392
}
393393

394394
// In place vector reversal
395-
fn reverse[T](&vec[T] v) -> () {
395+
fn reverse[T](&vec[mutable T] v) -> () {
396396
let uint i = 0u;
397397
auto ln = len[T](v);
398398

src/test/bench/shootout/fannkuchredux.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ fn fannkuch(int n) -> int {
1212
}
1313
auto perm1init_ = perm1init; // Rustboot workaround
1414

15-
auto perm = vec::init_elt(0, n as uint);
16-
auto perm1 = vec::init_fn(perm1init_, n as uint);
17-
auto count = vec::init_elt(0, n as uint);
15+
auto perm = vec::init_elt_mut(0, n as uint);
16+
auto perm1 = vec::init_fn_mut(perm1init_, n as uint);
17+
auto count = vec::init_elt_mut(0, n as uint);
1818

1919
auto f = 0;
2020
auto i = 0;

src/test/run-pass/vec-reverse.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@ use std;
22
import std::vec;
33

44
fn main() {
5-
let vec[int] v = [10, 20];
5+
let vec[mutable int] v = [mutable 10, 20];
66

77
assert v.(0) == 10;
88
assert v.(1) == 20;
99

10-
vec::reverse[int](v);
10+
vec::reverse(v);
1111

1212
assert v.(0) == 20;
1313
assert v.(1) == 10;
1414

15-
auto v2 = vec::reversed[int](v);
15+
auto v2 = vec::reversed[int]([10, 20]);
1616

17-
assert v2.(0) == 10;
18-
assert v2.(1) == 20;
17+
assert v2.(0) == 20;
18+
assert v2.(1) == 10;
1919

2020
v.(0) = 30;
2121

22-
assert v2.(0) == 10;
22+
assert v2.(0) == 20;
2323

2424
// Make sure they work with 0-length vectors too.
25-
let vec[int] v3 = [];
26-
auto v4 = vec::reversed[int](v3);
25+
auto v4 = vec::reversed[int]([]);
2726

27+
let vec[mutable int] v3 = vec::empty_mut();
2828
vec::reverse[int](v3);
2929
}

0 commit comments

Comments
 (0)