librustc: De-[mut] librustc (remove all mutable arrays). rs=demuting

This commit is contained in:
Patrick Walton 2013-02-25 17:03:31 -08:00
parent 24893e8d02
commit 96bdc34930
2 changed files with 22 additions and 25 deletions

View File

@ -667,8 +667,8 @@ struct Liveness {
tcx: ty::ctxt,
ir: @mut IrMaps,
s: Specials,
successors: ~[mut LiveNode],
users: ~[mut Users],
successors: @mut ~[LiveNode],
users: @mut ~[Users],
// The list of node IDs for the nested loop scopes
// we're in.
loop_scope: DVec<node_id>,
@ -684,14 +684,9 @@ fn Liveness(ir: @mut IrMaps, specials: Specials) -> Liveness {
ir: ir,
tcx: ir.tcx,
s: specials,
successors:
vec::cast_to_mut(
vec::from_elem(ir.num_live_nodes,
invalid_node())),
users:
vec::cast_to_mut(
vec::from_elem(ir.num_live_nodes * ir.num_vars,
invalid_users())),
successors: @mut vec::from_elem(ir.num_live_nodes, invalid_node()),
users: @mut vec::from_elem(ir.num_live_nodes * ir.num_vars,
invalid_users()),
loop_scope: DVec(),
break_ln: HashMap(),
cont_ln: HashMap()
@ -916,12 +911,13 @@ impl Liveness {
let mut changed = false;
do self.indices2(ln, succ_ln) |idx, succ_idx| {
changed |= copy_if_invalid(copy self.users[succ_idx].reader,
&mut self.users[idx].reader);
changed |= copy_if_invalid(copy self.users[succ_idx].writer,
&mut self.users[idx].writer);
if self.users[succ_idx].used && !self.users[idx].used {
self.users[idx].used = true;
let users = &mut *self.users;
changed |= copy_if_invalid(copy users[succ_idx].reader,
&mut users[idx].reader);
changed |= copy_if_invalid(copy users[succ_idx].writer,
&mut users[idx].writer);
if users[succ_idx].used && !users[idx].used {
users[idx].used = true;
changed = true;
}
}
@ -956,7 +952,8 @@ impl Liveness {
// Either read, write, or both depending on the acc bitset
fn acc(&self, ln: LiveNode, var: Variable, acc: uint) {
let idx = self.idx(ln, var);
let user = &mut self.users[idx];
let users = &mut *self.users;
let user = &mut users[idx];
if (acc & ACC_WRITE) != 0 {
user.reader = invalid_node();
@ -970,7 +967,7 @@ impl Liveness {
}
if (acc & ACC_USE) != 0 {
self.users[idx].used = true;
user.used = true;
}
debug!("%s accesses[%x] %s: %s",

View File

@ -51,7 +51,7 @@ pub const use_tydesc: uint = 2u; /* Takes the tydesc, or compares */
pub struct Context {
ccx: @CrateContext,
uses: ~[mut type_uses]
uses: @mut ~[type_uses]
}
pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
@ -72,7 +72,7 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
let cx = Context {
ccx: ccx,
uses: vec::cast_to_mut(vec::from_elem(n_tps, 0u))
uses: @mut vec::from_elem(n_tps, 0u)
};
match ty::get(ty::lookup_item_type(cx.ccx.tcx, fn_id).ty).sty {
ty::ty_bare_fn(ty::BareFnTy {sig: ref sig, _}) |
@ -90,7 +90,7 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
}
if fn_id_loc.crate != local_crate {
let uses = vec::cast_from_mut(copy cx.uses);
let uses = copy *cx.uses;
ccx.type_use_cache.insert(fn_id, copy uses);
return uses;
}
@ -175,16 +175,16 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
ccx.tcx.sess.parse_sess.interner)));
}
}
let uses = vec::cast_from_mut(copy cx.uses);
// XXX: Bad copy, use @vec instead?
// XXX: Bad copies, use @vec instead?
let uses = copy *cx.uses;
ccx.type_use_cache.insert(fn_id, copy uses);
uses
}
pub fn type_needs(cx: Context, use_: uint, ty: ty::t) {
// Optimization -- don't descend type if all params already have this use
for vec::each_mut(cx.uses) |u| {
if *u & use_ != use_ {
for uint::range(0, cx.uses.len()) |i| {
if cx.uses[i] & use_ != use_ {
type_needs_inner(cx, use_, ty, @Nil);
return;
}